iSKweek Posted February 16, 2011 Author Share Posted February 16, 2011 Hi there! This is my first tutorial so be kind :PThis quest system is based off of Richy's tutorial found [here.](http://www.touchofdeathforums.com/smf/index.php/topic,68426.0.html) You will need to follow the first part of the tutorial (the quest part) for this to all work.The first thing that needs to be done is to change how he has the Quest scripts set up, I have mine all in a module named 'modQuest'. So create that or just put this where you want (I recommend creating a new module).Paste this code in there and delete the 'Sub QuestScript' from Richy's tutorial.```Option ExplicitDim msg, qtype, finmsg, updatemsg As StringDim questnum, reward, rewardamount As Long'itemquestsDim reqitem, reqitemamount As Long'killquestsDim npcnumber, npckillamount As LongPublic Sub QuestScript(attacker, Script)Select Case Script'Script num = npc numCase 1  'Check Quest Progress  Select Case Player(attacker).NPCQuest(Int(Script)).NPCQuestProgress    Case 0      'set required item, the item number      reqitem = 2      'set req item amount      reqitemamount = 1      'set reward, the item number      reward = 1      'set reward amount      rewardamount = 100      msg = "This is a test quest, go get me a Tentacle Axe and I will give you moneyz."      qtype = "Get Item"      questnum = Script      Call QuestWindow(attacker, msg, qtype, questnum)    Case 1      If HasItem(attacker, reqitem) Then        finmsg = "Thanks for that, have some cash bro"        Call TakeInvItem(attacker, reqitem, reqitemamount)        Call GiveInvItem(attacker, reward, rewardamount)        Call QuestFinish(attacker, finmsg, Script)      Else: updatemsg = "You don't have the item yet."      Call QuestUpdate(attacker, updatemsg)      End If    Case 2      updatemsg = "I don't have anymore quests for you."      Call QuestUpdate(attacker, updatemsg)    'etc etc    End SelectExit SubCase 2'Check Quest Progress  Select Case Player(attacker).NPCQuest(Int(Script)).NPCQuestProgress    'not started    Case 0            'set required npc, the npc number      npcnumber = 3      'set killamount amount      npckillamount = 20      'set reward, the item number      reward = 1      'set reward amount      rewardamount = 100      msg = "This is a test kill quest, kill 20 female dogs and I will give you moar moneyz."      qtype = "Kill x"      questnum = Script      Call QuestWindow(attacker, msg, qtype, questnum)    Case 1      If npckillamount > 0 Then      updatemsg = "You still need to kill another " & npckillamount & "."      Call QuestUpdate(attacker, updatemsg)      Else: finmsg = "Thanks for that, have some cash bro"        Call GiveInvItem(attacker, reward, rewardamount)        Call QuestFinish(attacker, finmsg, Script)      End If    Case 2      updatemsg = "I don't have anymore quests for you."      Call QuestUpdate(attacker, updatemsg)  End SelectExit SubCase 3'npc num 3Exit SubCase ElseCall PlayerMsg(attacker, "There is no quest script for NPC Number " & Int(Script) & ". Check the source..", BrightRed)Exit SubEnd SelectEnd Sub'Quest handlersSub QuestWindow(ByVal index As Long, ByVal msg As String, ByVal qtype As String, ByVal questnum As Long)Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong SQuestWindowBuffer.WriteString msgBuffer.WriteString qtypeBuffer.WriteLong questnumSendDataTo index, Buffer.ToArray()  Set Buffer = NothingEnd SubSub QuestFinish(ByVal index As Long, ByVal finmsg As String, ByVal questnum As Long)Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong SQuestFinishBuffer.WriteString finmsgBuffer.WriteLong questnumSendDataTo index, Buffer.ToArray()Set Buffer = NothingEnd SubSub QuestUpdate(ByVal index As Long, ByVal updatemsg As String)Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong SQuestUpdateBuffer.WriteString updatemsgSendDataTo index, Buffer.ToArray()Set Buffer = NothingEnd SubSub KillQuestCount(ByVal index As Long, ByVal npcnum As Long)If npcnum = npcnumber Then  If npckillamout > 0 Then    npckillamount = npckillamount - 1    Call PlayerMsg(index, npckillamount & " left to kill.", Green)  End IfEnd IfEnd Sub```Each case is the npcNum, which dictates which NPC gives which quest. I am not going to explain the code because most people will just copy and paste it anyway, if you do want help understanding it feel free to ask.This section is all SERVER side.In modEnumerations add```'Quest  CQuestAccept  CQuestFinish```above the ' Make sure CMSG_COUNT is below everything elseand also```'Quest  SQuestWindow  SQuestFinishSQuestUpdate```above the 'Make sure SMSG_COUNT is below everything elseThen in modHandleData add```'Quest  HandleDataSub(CQuestAccept) = GetAddress(AddressOf HandleQuestAccept)  HandleDataSub(CQuestFinish) = GetAddress(AddressOf HandleQuestFinish)```to the bottom of InitMessages and then```'QuestPublic Sub HandleQuestAccept(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddR As Long, ByVal ExtraVar As Long)  Dim questnum As Long  Dim Buffer As clsBuffer  Set Buffer = New clsBuffer  Buffer.WriteBytes Data()  questnum = Buffer.ReadLong  Player(index).NPCQuest(Int(questnum)).NPCQuestProgress = 1End SubPublic Sub HandleQuestFinish(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddR As Long, ByVal ExtraVar As Long)  Dim questnum As Long  Dim Buffer As clsBuffer  Set Buffer = New clsBuffer  Buffer.WriteBytes Data()  questnum = Buffer.ReadLong  Player(index).NPCQuest(Int(questnum)).NPCQuestProgress = 2End Sub```to the very bottom of the module.In modCombat -> PlayerAttackNpc, look for```If Damage >= MapNpc(mapNum).Npc(mapNpcNum).Vital(Vitals.HP) Then```and add```'check if a quest npc, if so minus one from kills needed    Call KillQuestCount(attacker, npcnum)```under it.That is all for the Server.**CLIENT side.**First some form work. Add 3 pictureboxes. One named picQuestWindow, picQuestFinish, the other named picQuestUpdate.picQuestWindowAdd 4 labels, one named lblQuestMsg, one lblQuestNum, the other lblQuestType and one with a caption of "Quest Window".Add 2 command buttons, one cmdQuestOk the other cmdQuestCancel.picQuestFinishAdd 3 labels, one named lblQuestFinishMsg, the other lblQuestType and one with a caption of "Quest Window".Add a command button, cmdQuestFinish.picQuestUpdateLabel named lblQuestUpdate and a cmdButton named cmdQuestUpdateOK.In frmMain add```Private Sub cmdQuestFinish_Click()  Dim questnum As Long  questnum = lblquesnum2.Caption  Call QuestFinish(questnum)  picQuestFinish.Visible = FalseEnd SubPrivate Sub cmdQuestOk_Click()  Dim questnum As Integer  questnum = lblQuestNum.Caption  picQuestWindow.Visible = False  Call AcceptQuest(questnum)End SubPrivate Sub cmdQuestCancel_Click()  picQuestWindow.Visible = FalseEnd SubPrivate Sub cmdQuestUpdateOK_Click()  picQuestUpdate.Visible = FalseEnd Sub```In modClientTCP add```'QuestPublic Sub AcceptQuest(ByVal questnum As Long)  Dim Buffer As clsBuffer  Set Buffer = New clsBuffer  Buffer.WriteLong CQuestAccept  Buffer.WriteLong questnum  SendData Buffer.ToArray  Set Buffer = NothingEnd SubPublic Sub FinishQuest(ByVal questnum As Long)  Dim Buffer As clsBuffer  Set Buffer = New clsBuffer  Buffer.WriteLong CQuestAccept  Buffer.WriteLong questnum  SendData Buffer.ToArray  Set Buffer = NothingEnd SubPublic Sub QuestFinish(ByVal questnum As Long)  Dim Buffer As clsBuffer  Set Buffer = New clsBuffer  Buffer.WriteLong CQuestFinish  Buffer.WriteLong questnum  SendData Buffer.ToArray  Set Buffer = NothingEnd SubPrivate Sub HandleQuestUpdate(ByVal Index As Long, ByRef Data() As Byte, ByVal EditorIndex As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim Buffer As clsBufferDim Msg As StringSet Buffer = New clsBufferBuffer.WriteBytes Data()Msg = Buffer.ReadStringfrmMain.picQuestUpdate.top = frmMain.picScreen.top / 2frmMain.picQuestUpdate.Visible = TruefrmMain.lblQuestUpdate.Caption = "Quest Update: " & MsgEnd Sub```at the bottom of the module.In modEnumerations add```'Quest  CQuestAccept  CQuestFinish```above 'Make sure CMSG_Count blah blah and```'Quest  SQuestWindow  SQuestFinishSQuestUpdate```above 'Make sure SMSG_Count blah blah.In modHandleData add```'Quest  HandleDataSub(SQuestWindow) = GetAddress(AddressOf HandleQuestWindow)  HandleDataSub(SQuestFinish) = GetAddress(AddressOf HandleQuestFinish)HandleDataSub(SQuestUpdate) = GetAddress(AddressOf HandleQuestUpdate)```at the bottom of InitMessages and then```'QuestPrivate Sub HandleQuestWindow(ByVal Index As Long, ByRef Data() As Byte, ByVal EditorIndex As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim Buffer As clsBufferDim Msg As StringDim Qtype As StringDim questnum As LongSet Buffer = New clsBufferBuffer.WriteBytes Data()Msg = Buffer.ReadStringQtype = Buffer.ReadStringquestnum = Buffer.ReadLongfrmMain.picQuestWindow.Visible = TruefrmMain.lblQuestMsg.Caption = "Quest Description: " & MsgfrmMain.lblQuestType.Caption = "Quest Type: " & QtypefrmMain.lblQuestNum.Caption = questnumEnd SubPrivate Sub HandleQuestFinish(ByVal Index As Long, ByRef Data() As Byte, ByVal EditorIndex As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim Buffer As clsBufferDim Msg As StringDim questnum As LongSet Buffer = New clsBufferBuffer.WriteBytes Data()Msg = Buffer.ReadStringquestnum = Buffer.ReadLongfrmMain.picQuestFinish.Visible = TruefrmMain.lblQuestFinishMsg.Caption = "Quest Finish: " & MsgfrmMain.lblquesnum2.Caption = questnumEnd Sub```to the bottom of the module.I think that is everything, it isn't too graphically pleasing but design isn't my strong point :P If there is any problems just let me know, report any bugs and if you have suggestions on how to improve the code please let me know :DThanks, Skweek.Screenshots:>! ![](http://img524.imageshack.us/img524/733/questdesc.jpg)>! ![](http://img191.imageshack.us/img191/5048/questfin.jpg)Exp rewards: http://www.touchofdeathforums.com/smf/index.php/topic,69793.0.html Link to comment Share on other sites More sharing options...
Murdoc Posted February 16, 2011 Share Posted February 16, 2011 Thanks much for this. X-D Link to comment Share on other sites More sharing options...
iSKweek Posted February 16, 2011 Author Share Posted February 16, 2011 No problem :) Link to comment Share on other sites More sharing options...
iSKweek Posted February 16, 2011 Author Share Posted February 16, 2011 Ok, update time. I have added a few features that allow for kill x amount of x quests.**Client:**New picBox named picQuestUpdate. Label named lblQuestUpdate and a cmdButton named cmdQuestUpdateOK.Add```Private Sub cmdQuestUpdateOK_Click()  picQuestUpdate.Visible = FalseEnd Sub```anywhere on frmMain.Add```Private Sub HandleQuestUpdate(ByVal Index As Long, ByRef Data() As Byte, ByVal EditorIndex As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)Dim Buffer As clsBufferDim Msg As StringSet Buffer = New clsBufferBuffer.WriteBytes Data()Msg = Buffer.ReadStringfrmMain.picQuestUpdate.top = frmMain.picScreen.top / 2frmMain.picQuestUpdate.Visible = TruefrmMain.lblQuestUpdate.Caption = "Quest Update: " & MsgEnd Sub```to the bottom of modHandleData and```HandleDataSub(SQuestUpdate) = GetAddress(AddressOf HandleQuestUpdate)```to the bottom of InitMessages.Add```SQuestUpdate```to modEnumerations (server and client)**Server:**Add```Sub QuestUpdate(ByVal index As Long, ByVal updatemsg As String)Dim Buffer As clsBufferSet Buffer = New clsBufferBuffer.WriteLong SQuestUpdateBuffer.WriteString updatemsgSendDataTo index, Buffer.ToArray()Set Buffer = NothingEnd SubSub KillQuestCount(ByVal index As Long, ByVal npcnum As Long)If npcnum = npcnumber Then  If npckillamout > 0 Then    npckillamount = npckillamount - 1    Call PlayerMsg(index, npckillamount & " left to kill.", Green)  End IfEnd If```to the bottom of modQuest.```'killquestsDim npcnumber, npckillamount As Long```at the top of modQuest.Add```'check if a quest npc, if so minus one from kills needed    Call KillQuestCount(attacker, npcnum)```to modCombat. Add it anywhere in the```If Damage >= MapNpc(mapNum).Npc(mapNpcNum).Vital(Vitals.HP) Then```statement. I will update the first post with these changes. Link to comment Share on other sites More sharing options...
Murdoc Posted February 16, 2011 Share Posted February 16, 2011 Right on. This should come in handy for a lot of us. Thanks for sharing. :-) Link to comment Share on other sites More sharing options...
saruish Posted February 16, 2011 Share Posted February 16, 2011 very usefull thanks man :D your allways a big help Link to comment Share on other sites More sharing options...
iSKweek Posted February 17, 2011 Author Share Posted February 17, 2011 Thanks for the compliments :D Link to comment Share on other sites More sharing options...
Kradon Posted February 17, 2011 Share Posted February 17, 2011 i like, is there a way to change the UI of the quest interfaces myself? Link to comment Share on other sites More sharing options...
iSKweek Posted February 17, 2011 Author Share Posted February 17, 2011 Well at the moment it is just a picture box, so if you designed your own UI and saved it in the client folder you could use```frmMain.picQuestWindow.Picture = LoadPicture(App.Path & "\data files\graphics\gui\main\questUI.jpg")```to load it up. It just might need some moving around of labels and such. :) Link to comment Share on other sites More sharing options...
Kradon Posted February 17, 2011 Share Posted February 17, 2011 thanks i'll try that really cool quest system =] Link to comment Share on other sites More sharing options...
iSKweek Posted February 17, 2011 Author Share Posted February 17, 2011 The quest system itself is mostly from richy, I just added some small stuff and the gui. Link to comment Share on other sites More sharing options...
adee65 Posted February 21, 2011 Share Posted February 21, 2011 for the first part is that in the client and/or server? Link to comment Share on other sites More sharing options...
iSKweek Posted February 21, 2011 Author Share Posted February 21, 2011 The first part is server side. Make sure you read richy's tutorial before you start adding this in though. Link to comment Share on other sites More sharing options...
adee65 Posted February 21, 2011 Share Posted February 21, 2011 so First I need to add richys tutorial then yours? Link to comment Share on other sites More sharing options...
iSKweek Posted February 21, 2011 Author Share Posted February 21, 2011 Yes :) Link to comment Share on other sites More sharing options...
EclipseCommunity Posted February 25, 2011 Share Posted February 25, 2011 ….. :sad: It doesn't work. I have NPC 1 set as scripted, haven't changed the code for the quest from this post, I go to attack the NPC and nothing happens. Link to comment Share on other sites More sharing options...
Ezand Posted February 25, 2011 Share Posted February 25, 2011 Looks good! Link to comment Share on other sites More sharing options...
iSKweek Posted February 25, 2011 Author Share Posted February 25, 2011 @Xlithan:> ….. :sad: It doesn't work. I have NPC 1 set as scripted, haven't changed the code for the quest from this post, I go to attack the NPC and nothing happens.Let me just check something, I have a feeling I had to change something.@Ezand:> Looks good!Thanks!EDIT: To Xlithan,Find```' Check if at same coordinates      Select Case GetPlayerDir(attacker)        Case DIR_UP          NpcX = MapNpc(mapNum).Npc(mapNpcNum).x          NpcY = MapNpc(mapNum).Npc(mapNpcNum).y + 1        Case DIR_DOWN          NpcX = MapNpc(mapNum).Npc(mapNpcNum).x          NpcY = MapNpc(mapNum).Npc(mapNpcNum).y - 1        Case DIR_LEFT          NpcX = MapNpc(mapNum).Npc(mapNpcNum).x + 1          NpcY = MapNpc(mapNum).Npc(mapNpcNum).y        Case DIR_RIGHT          NpcX = MapNpc(mapNum).Npc(mapNpcNum).x - 1          NpcY = MapNpc(mapNum).Npc(mapNpcNum).y      End Select```in modCombat (server side)Underneath it there should be an if statement checking the npc type or something. I am not sure what the original code is :PMy section of that code looks like this```If NpcX = GetPlayerX(attacker) Then        If NpcY = GetPlayerY(attacker) Then          If Npc(npcnum).Behaviour = NPC_BEHAVIOUR_SCRIPTED Then            CanPlayerAttackNpc = False            Call QuestScript(attacker, Int(npcnum))            Exit Function          ElseIf Npc(npcnum).Behaviour = NPC_BEHAVIOUR_FRIENDLY Then            CanPlayerAttackNpc = False            Call SendNpcChat(attacker, npcnum)            Exit Function          Else: CanPlayerAttackNpc = True          End If        End If      End If```The main part is the```If Npc(npcnum).Behaviour = NPC_BEHAVIOUR_SCRIPTED Then            CanPlayerAttackNpc = False            Call QuestScript(attacker, Int(npcnum))            Exit Function```Try adding that in and let me know if it works. Link to comment Share on other sites More sharing options...
EclipseCommunity Posted February 25, 2011 Share Posted February 25, 2011 Mine looks like this:```If NpcX = GetPlayerX(attacker) Then        If NpcY = GetPlayerY(attacker) Then          If Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_FRIENDLY And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SHOPKEEPER And Npc(npcNum).Behaviour <> NPC_BEHAVIOUR_SCRIPTED Then            CanPlayerAttackNpc = True            If Npc(npcNum).Behaviour = NPC_BEHAVIOUR_SCRIPTED Then              CanPlayerAttackNpc = False              Call QuestScript(attacker, Int(npcNum))              Exit Function            End If            If Len(Trim$(Npc(npcNum).AttackSay)) > 0 Then              PlayerMsg attacker, Trim$(Npc(npcNum).Name) & ": " & Trim$(Npc(npcNum).AttackSay), White            End If          End If        End If      End If``` Link to comment Share on other sites More sharing options...
ohnoitsbenjii Posted February 25, 2011 Share Posted February 25, 2011 Is it possible to have one NPC give several quests? Link to comment Share on other sites More sharing options...
EclipseCommunity Posted February 25, 2011 Share Posted February 25, 2011 I think im gunna rip this back out of my source and write one from fresh. Just thought this would be quicker since it seemed to offer the exact basic quest system as I programmed in MirageMUD, which I was going to use for my EO game. Link to comment Share on other sites More sharing options...
iSKweek Posted February 25, 2011 Author Share Posted February 25, 2011 @ohnoitsbenjii:> Is it possible to have one NPC give several quests?Just use more checkpoints.like: checkpoint = 0 start of quest 1checkpoint = 1 started quest 1checkpoint = 2 finished quest 1checkpoint = 3 start of quest 2etc etc :) Link to comment Share on other sites More sharing options...
ohnoitsbenjii Posted February 26, 2011 Share Posted February 26, 2011 @iSkweek:> Just use more checkpoints.> > like: checkpoint = 0 start of quest 1> checkpoint = 1 started quest 1> checkpoint = 2 finished quest 1> checkpoint = 3 start of quest 2> > etc etc :)So, a "checkpoint" Is the case inside each case, am i right?also, sorry for so many questions. Where exactly would I put in that code you posted to add a UI to the quest boxes? Link to comment Share on other sites More sharing options...
iSKweek Posted February 26, 2011 Author Share Posted February 26, 2011 By checkpoint = 1, 2, 3 etc I mean```Player(attacker).NPCQuest(Int(Script)).NPCQuestProgress =1, 2 ,3 etc```I don't quite understand what you mean by that last question :S Link to comment Share on other sites More sharing options...
ohnoitsbenjii Posted February 26, 2011 Share Posted February 26, 2011 I'm talking about this code:```frmMain.picQuestWindow.Picture = LoadPicture(App.Path & "\data files\graphics\gui\main\questUI.jpg")```And thank you, got the checkpoint part down. :DD 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