bintin Posted February 1, 2013 Author Share Posted February 1, 2013 Hello,I've been looking through the code and I can't find anything wrong with it, I also tried some apparent "solutions" but I still get the same error.The error I get is a run time error (9) subscript out of range and it highlights "If NPC(npcNum).QuestNum = i Then"I use Project Vertigo and this started when I added Alatar's Quest system (which doesn't work as NPC's don't want to give me the quest.) Link to comment Share on other sites More sharing options...
Matt Posted February 1, 2013 Share Posted February 1, 2013 Post the entire sub please. Link to comment Share on other sites More sharing options...
bintin Posted February 1, 2013 Author Share Posted February 1, 2013 Indeed I shall>! Public Sub DrawPlayerName(ByVal Index As Long)>! Dim TextX As Long>! Dim TextY As Long>! Dim color As Long>! Dim Name As String>! ' If debug mode, handle error then exit out>! If Options.Debug = 1 Then On Error GoTo errorhandler>! ' Check access level>! If GetPlayerPK(Index) = NO Then>! Select Case GetPlayerAccess(Index)>! Case 0>! color = RGB(255, 96, 0)>! Case 1>! color = QBColor(DarkGrey)>! Case 2>! color = QBColor(Cyan)>! Case 3>! color = QBColor(BrightGreen)>! Case 4>! color = QBColor(Yellow)>! End Select>! Else>! color = QBColor(BrightRed)>! End If>! Name = Trim$(Player(Index).Name)>! ' calc pos>! TextX = ConvertMapX(GetPlayerX(Index) * PIC_X) + Player(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(Name)))>! If GetPlayerSprite(Index) < 1 Or GetPlayerSprite(Index) > NumCharacters Then>! TextY = ConvertMapY(GetPlayerY(Index) * PIC_Y) + Player(Index).YOffset - 16>! Else>! ' Determine location for text>! TextY = ConvertMapY(GetPlayerY(Index) * PIC_Y) + Player(Index).YOffset - (DDSD_Character(GetPlayerSprite(Index)).lHeight / 6) + 16>! End If>! ' Draw name>! Call DrawText(TexthDC, TextX, TextY, Name, color)>! Dim i As Long>! Dim npcNum As Long>! For i = 1 To MAX_QUESTS>! 'check if the npc is the next task to any quest: [?] symbol>! If Quest(i).Name <> "" Then>! If Player(MyIndex).PlayerQuest(i).Status = QUEST_STARTED Then>! If Quest(i).Task(Player(MyIndex).PlayerQuest(i).ActualTask).NPC = npcNum Then>! Name = "[?]">! TextX = ConvertMapX(MapNpc(Index).x * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(Name)))>! If NPC(npcNum).Sprite < 1 Or NPC(npcNum).Sprite > NumCharacters Then>! TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 16>! Else>! TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(NPC(npcNum).Sprite).lHeight / 4)>! End If>! Call DrawText(TexthDC, TextX, TextY, Name, QBColor(Yellow))>! Exit For>! End If>! End If>! 'check if the npc is the starter to any quest: [!] symbol>! 'can accept the quest as a new one?>! If Player(MyIndex).PlayerQuest(i).Status = QUEST_NOT_STARTED Or Player(MyIndex).PlayerQuest(i).Status = QUEST_COMPLETED_BUT Then>! 'the npc gives this quest?>! If NPC(npcNum).QuestNum = i Then>! Name = "[!]">! TextX = ConvertMapX(MapNpc(Index).x * PIC_X) + MapNpc(Index).XOffset + (PIC_X \ 2) - getWidth(TexthDC, (Trim$(Name)))>! If NPC(npcNum).Sprite < 1 Or NPC(npcNum).Sprite > NumCharacters Then>! TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - 16>! Else>! TextY = ConvertMapY(MapNpc(Index).Y * PIC_Y) + MapNpc(Index).YOffset - (DDSD_Character(NPC(npcNum).Sprite).lHeight / 4)>! End If>! Call DrawText(TexthDC, TextX, TextY, Name, QBColor(Yellow))>! Exit For>! End If>! End If>! End If>! Next>! ' Error handler>! Exit Sub>! errorhandler:>! HandleError "DrawPlayerName", "modText", Err.Number, Err.Description, Err.Source, Err.HelpContext>! Err.Clear>! Exit Sub>! End Sub Link to comment Share on other sites More sharing options...
Matt Posted February 1, 2013 Share Posted February 1, 2013 Please post your NPC rec, and constant MAX_QUESTS. I'm pretty sure I know what's wrong. Link to comment Share on other sites More sharing options...
bintin Posted February 1, 2013 Author Share Posted February 1, 2013 Couldn't find what you meant so I uploaded the files:http://www.freemmorpgmaker.com/files/imagehost/pics/e5a4dbce024051b12eb1d473aa45f04c.rar Link to comment Share on other sites More sharing options...
Exception Posted February 1, 2013 Share Posted February 1, 2013 You're using npcNum, without actually assigning it a value, hence the subscript errors. You're attempting to use a structure that doesn't exist. (In this case, NPC #0\. ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png))Also, why are you iterating through each quest, in the player name drawing procedure? Not mentioning that it's going to render with -each player on the map-, rather than loop through a large amount of quests, loop through your map NPCs when your map loads, and grab whether it has a quest, then (Known as caching. It's better to get what's needed beforehand, not constantly!), and use said stored variables to draw.Although, if that's from a tutorial, shouldn't that code be in DrawNPCName, not DrawPlayerName? I think a npcNum argument exists there, hence the need for it. ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)Pseudo-code:Public CacheQuestNpcsVar(1 To Max_Map_Npcs) As BytePublic Sub CacheQuestNpcs()Dim i As LongFor i = 1 To Max_Map_NpcsIf Npc(i).QuestNum > 0 Then' Check for players quest details here, to grab [!]/[?].'For [!], make CacheQuestNpcsVar(i) = 1.'For [?], make CacheQuestNpcsVar(i) = 2.Else' Here, the NPC has no quest. We can clear it.CacheQuestNpcsVar(i) = 0End IfNextEnd SubThen, in it's OWN SUBPublic Sub DrawQuestNpcsFor i = 1 To Max_Map_NpcsSelect Case CacheQuestNpcsVar(i)Case 1' Draw [!] here!case 2' Draw [?] here!End SelectNextEnd SubEDIT: Sorry 'bout the nesting. No idea what happened there. Link to comment Share on other sites More sharing options...
bintin Posted February 1, 2013 Author Share Posted February 1, 2013 Perfect thank you ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now