In-Depth EVT Coding 2

Newbie Spellweaver
Joined
Jan 2, 2009
Messages
10
Reaction score
0
It is In-Depth EVT Coding 2 because i will explain in details more about "inside thinking" while building an event function while TheRealIceMan's guide is more for the tools to build it.
TheRealIceMan's guide can be found here: http://forum.ragezone.com/f464/guide-in-depth-evt-coding-462376/

Now let's start,
As you know every single program language consists of few parts that need to be put together in order to work properly - "working properly means to work the way it's intended". While EVT coding is simple enough many of you may hit the wall with the "structure of the script".
First thing you should know for yourself is "what should be the result"
Second thing is "what should be the phases".

I will give for example single thing and the phases needed to be coded.
First we need to know - what should be the result of our script.
So we pick something easy like:
We want to start new quest NPC that should give us an ITEM after we collect an certain amount of other item.
Ok this sounds easy, so let's add few more things. We need this NPC to check for:
1. What nation is the player who want to complete the quest
2. What level is the player who want to complete the quest
3. Does the player have all the items needed to complete the quest
4. Does the player already have the quest item in his inventory
5. Does the player have room in his inventory to get the quest item

Ok let's stop here for now. So let's say we give some constants to our checks.

1. What nation is the player who want to complete the quest : Let's say this NPC will complete quests only for Karus users!
2. What level is the player who want to complete the quest : Let's say we won't allow anyone under lvl 20 to complete the quest.
3. Does the player have all the items needed to complete the quest : Let's say he need to have 10 Blood of Wolf (something easy for the demo) in order to complete the quest
4. Does the player already have the quest item in his inventory : Let's say the quest item is Red Treasure Chest.
5. Does the player have room in his inventory to get the quest item : He need at least one free spot in his inventory in order to complete it.

Now all sounds clear enough but we should think about all the thing again. We need to choose what checks we should do first and what checks we should do last etc. For this example i will choose :
1, 2, 3, 4, 5 (the way our checks will be done as 1 is for nation check 2 is for level etc.. )

Now everything may seems easy but it only seems that way. If we need to do only one check at all it is more then easy, but if we need to do all the checks in our selected order our script goes bigger and bigger.

So we know what we have, we shall see what we need.

I will not go in details how to set up NPC. It should be on someone elses guides since this is not the main point here. But since some rows of the NPC are linked to our Event's we need to know em.
Let's say we ignore the Chaotic Generator, and use it's byType number to link our EVENT to 137. For the example purposes i will use byType 137 and starting EVENT num: 22001 (we know it is hard coded in to the
ebenezer. More information about the link between byType number in our K_NPC table and the Event number in our .evt file will come later on when i figure it out or when someone decide to share the info with us.)
OK what we need to know more.
Let's say the NPC for this example stays in Moradon. So we need to put our EVENT's in file 21.evt (number 21 comes from our ZONE_INFO table. And in most of the servers it is ZoneNo:21 for Moradon. But it can be different so check it out before you start. Be sure you put your events in the right EVT file.)

Ok we need to write down the text of the dialog of the NPC. Now, i will not use npcsay file's as it was in older versions of KO. Our dialogs are stored in files from the CLIENT side.
First we open:
Client/Data/Quest_Talk_en.tbl and adding our text : (i will use these numbers in by tbl file since they are empty and available for me) ((I will try to keep em simple in order to understand em better))

4 Hello There, Bring me 10 Blood Of Wolf and i will reward you with a Treasure! <- Main info when we open the dialog box
5 I am sorry this quest is only available for Karus users <- Text that will be shown if El Morad user is trying to complete the quest
6 You are not strong enough to hold such an treasure! Please come again when you reach level 20 or above! <- Text that will be shown if player under lvl 20 is trying to complete the quest
7 Please bring me 10 Blood of Wolf or i can't give you the treasure! <- Text that will be shown if the player don't have enough Blood of Wolf in his inventory
8 You don't have empty slot in your Inventory! <- Ye that doesn't need explanation
9 You are man of your word! For your 10 Blood of Wolf i am giving you a Treasure! <- Text shown by successfully completed quest upon receiving the quest item
10 You already have my Treasure! Common Leave me now! <- Text shown when the user trying to complete the quest but have Red Treasure Box in his inventory.

Ok, now we need to write the text that will be shown in the Quest dialog button. For this we need to edit the Quest_Menu_en.tbl

10 Here are your Blood Wolf's! Give me my Treasure now!

So far so good. Now comes the hard part. The coding.

We will use ID: 370004000 for the Blood of Wolf and ID 379154000 for the Red Treasure Chest (be aware in your ITEM table these ID's may be linked to different items. I use em for demo anyway)

I will explayn everything on the way so let's start.


EVENT 22001 ; [this means we just linked our first event with byType number: 137. From now on our NPC is linked with our start event number]
E SELECT_MSG 150 4 10 501 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
END

Explaining the numbers:
150 is the sSid of our new NPC located in K_NPC table. (some say this number may not be exact and it stays there only for info but i am not so sure about this.)
4 is the Text from Quest_Talk_en.tbl that actually presents the NPC to the player. (Hello There, Bring me 10 Blood Of Wolf and i will reward you with a Treasure! <- Main info when we open the dialog box)
10 is the text from our first Buton in that dialog. We get it from Quest_Menu_en.tbl and it is : [Here are your Blood Wolf's! Give me my Treasure now!]
501 is the EVENT that will start at the moment we press the button.
-1 is well explained in TheRealIceMan's guide. It is used when we don't want to add more quests to this NPC. Instead of empty spaces we use -1 to say that this field will not be used.

Before i start the EVENT 501, i want to say something that you need to understand in order to code successfully from now on. Many of the languages for coding using well known ways to -cross reference the data-
allowing em to do extremely hard checks in only one function. States like - IF WHILE WHEN THEN OR etc. While this is not the case with the EVT coding we need to think of a way to program the events that way so we can do almost the same as we would do with all other languages. So step by step.
Every single check have two different outputs. The easiest sample is : 1 for yes/positive and 2 for no/negative check for failure. This is important to be known!

I will assign [PAF] for positive answer for failure.

The trick is for us to know that every single EVENT gives us at the end positive or negative answer for failure. Knowing this we can now make the events work for us.

EVENT 501
E RUN_EVENT 502
E RUN_EVENT 503
END

As you see we expect to have positive and negative answer for failure and we're prepared. Starting two new events.

Event 502 is started in order to handle the information if we have [PAF].
Event 503 is started while we expect that if we have negative answer we have to proceed to the next event (next check).

EVENT 502 [ ]
A CHECK_NATION 2 [ Here goes our check for the Nation of our player. As you know we expect nation [1] for Karus. Checking for [2] means we expect [PAF]]
E SAY -1 -1 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 [ Received [PAF] (El Morad user activated the button) we can now deny the quest to the player by saying : [5 I am sorry this quest is only available for Karus users ]]
E RETURN [ RETURN is important because this way we say that our function should return to the start and not continue forward. While this is done in Event 501 the next EVENT 503 would not start.]
END []

Ok, we dealt with the nasty El Morad user who wanted to run the event. But soon or later Karus user will try it. This means EVENT 502 will not give RETURN state and our EVENT 503 will have to start.
So what we do now? We proceed to the next Check. Having in mind that we expect also [PAF] from it.

EVENT 503
E RUN_EVENT 504
E RUN_EVENT 505
END

Eh? Things going to be more clear now? Anyway i continue.. For those with fast minds is clearly enough that event 504 will handle the [PAF] from our check. so let's do it:

EVENT 504
A CHECK_LV 1 19 [ Checking for if our player is between lvl 1 and lvl 19. (not 20 or more) and if we have [PAF]]
E SAY -1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 [ Deny the quest with reason: 6 You are not strong enough to hold such an treasure! Please come again when you reach level 20 or above! ]
E RETURN [ Returning to the start. Event 505 will not proceed]
END

Ok but the user is Karus and he have lvl 20 .. We continue with next check (event).

EVENT 505
E RUN_EVENT 506
E RUN_EVENT 507
END

Again event 506 will handle the [PAF].

EVENT 506
A HOWMUCH_ITEM 370004000 0 9 [ Checking that our user have between 0 and 9 Blood of Wolf in his inventory. Item ID: 370004000 ]
E SAY -1 -1 7 -1 -1 -1 -1 -1 -1 -1 -1 -1 [ We have the [PAF] and we deny the quest: 7 Please bring me 10 Blood of Wolf or i can't give you the treasure! ]
E RETURN [ Returning to the start. event 507 will not proceed ]
END

Ok, our user is Karus lvl 20 or above and he have 10 or more Blood of Wolf.

EVENT 507
E RUN_EVENT 508
E RUN_EVENT 509
END


And so on.. first the [PAF] event

EVENT 508
A CHECK_EXIST_ITEM 379154000 1 [ Checking if the user have already [1] item in his inventory. Item ID : 379154000. You can change the number at your choice. But depending of the item some quest items are unique and not stack-able]
E SAY -1 -1 10 -1 -1 -1 -1 -1 -1 -1 -1 -1 [ Denying the quest with : 10 You already have my Treasure! Common Leave me now! ]
E RETURN [ Returning to start. Event 509 wont proceed ]
END


EVENT 509
E RUN_EVENT 510
E RUN_EVENT 511
END

Event 510 will take care if we have [PAF]

EVENT 510
A CHECK_EMPTY_SLOT 0 [ Checking the player if his inventory is full.(have 0 empty slots) In that case we deny the event ]
E SAY -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1 -1 [ Denying the quest with : 8 You don't have empty slot in your Inventory! ]
E RETURN [ Return to start. Event 511 won't proceed ]
END

Ok we can continue this way for long. But luckily we came to the end. Now let's see our situation.
We have all the checks done. And we know that the quest will be denyed if some of the checks return [PAF]. But in case everything is ok and our player knows what he's doing. We came to an event that
should handle the actual finishing of the quest. In our case exchanging the Blood Of Wolfs with the Red Treasure Chest. So let's write the last function that will handle this. EVENT 511 will start in case 510 don't get
[PAF].

EVENT 511
E ROB_ITEM 370004000 10 [ Getting 10 Blood of Wolf from the player. Blood of Wolf item ID: 370004000 ]
E GIVE_ITEM 379154000 1 [ Giving to the player the quest item [1xitem] In our Case the Red Treasure Chest ]
E SAY -1 -1 9 -1 -1 -1 -1 -1 -1 -1 -1 -1 [ Uppon successfully completion of the quest we say final words to the player: 9 You are man of your word! For your 10 Blood of Wolf i am giving you a Treasure! ]
END [ the big end ]


And we're done!

Of course this is just a simple demo of how you should think when you coding an events. You can make it much more sophisticated like adding butons for accepting the event saving it for other time etc. My point was to show you how simple the things are once you understand em right.

Now i am sure for you guys that all this is much more clear in your heads now. And coding Event's will become fun.

Here is the place to say few words about me. I am new in developing KO servers and so. Only spend like 2 weeks over the files. And even if i have decent understanding of many types of coding, i still lack of some
information that you guys probably have and can share it easy. I want to offer my help in the evt coding and not only. All my knowledge i want to share with you if you willing to share yours with me. I have many
and simple questions. (Sometimes the easiest things are much more harder to be found). I added my msn in my personal info. Feel free to contact me for questions and help requests. Also if you feel like sharing more for the developing of KO.

I am sorry for the long post but i hope you enjoyed reading it as much as i enjoyed witting it.

Zhivko

P.S Sorry for my bad english :w00t:
 
nice guide ^_^
but:
Code:
E SELECT_MSG [b]150[/b] 4 10 501 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
END

the *150* isnt linked to anything, it would still work if i made it for example: 98123
 
Back