![]() |
[SHARE][TUTORIAL]AI.OBJ
(To keep the information in one place I will just continously update this first post - In order for you to know if a significant update took place i will simply make a notifying post in this topic describing the new things that I have added).
Overview ai.obj is used by a stack machine a stack machine is a combination of a specific data structure, a stack and a language that operates on the stack. The Stack Stacks are data structures which maintain the order of last-in, first-out. A good analogy is that of a stack of plates. The first plate you put in the stack is the last one that you get out. If in place of plates we have data objects let's say that we put objects A B C D in the stack in that order then the stack would look after each addition like thus: [php:1:3a88cfacc0] D C C B B B A A A A [/php:1:3a88cfacc0] You can access data objects only from the top of the stack. If you want to access element C then you will have to change where the top of the stack is. You can do that because a stack data structure is combined with an index THE STACK POINTER, which points to the top of the stack + 1. If the stack has no elements then the STACK POINTER is 0. If you add one element is 1 in our example where all 4 elements have been introduced the STACK POINTER has the value 5. So closing this description you have to remember 2 things for a stack data structure, the last-in first out and the stack pointer index. The Language To be able to understand the examples below, i will introduce now the shift_sp command. shift_sp <integer> : moves the stack pointer so many places as described by the integer (it's a signed integer can be positive in that case we are growing the stack, or negative shrinking the stack) The commands of a stack machine affect the top of the stack. They take their values from the stack and they return a value on the stack. If the command needs one value then it removes this value from the stack and returns the result in its place. The top of the stack has remained the same since one value was removed and one value was added. If it needs 2 values then it takes 2 values from the stack and returns the result in its place. The value of the stack pointer is minus one what it was because the command took 2 values and returned one. Every command on the stack affects the stack and the stack pointer. The only exception is the call_func command. The call_func command doesn't affect the stack pointer. It only reads the arguments that needs and returns a value. Specifically it returns a value on the stack position that exists before all its arguments. That is the reason that we see in ai.obj before any func_call code like this: Quote:
the shift_sp -2 after the func_call is to go back 2 stack positions - remember the func call doesn't remove elements from the stack there are still there finally the shift_sp -1 is used to go to the place we reserved with the shift_sp 1 command at the beggining Quote:
push_const <int> : push the value on the stack, increase the stack pointer by one. fetch_i : pop a value from the stack, assume that is an index on the stack data structure (see it like an address), push the value (an integer) that is contained in this address on the stack. Mnemonic Fetch Integer. The stack pointer remains the same since we got one value and returned one value. fetch_d : like fetch_i but it brings back a double. Mnemonic Fetch Double push_reg_sp : it pushes the stack pointer on the stack. Since we didn't use any element from the stack and we returned one the stack pointer increased by one. Why you should do this? For one thing by giving the following code: push_reg_sp fetch_i you make a copy of the value that is on top of the stack. Quite simple and you can see it in many places in ai.obj other commands like mul (multiplication), div(division) etc are self-explanatory. Some (very fast) notes on events: Events are nothing more than structures that contain specific information, in specific places. For example: Quote:
Reserved Words - Statements Code:
(52 reserved words so far)Handler Reference Code:
(37 handlers so far)Code:
To be populated...Code:
Here is a list of all the function calls for reference, the arguments for each function is given in descriptive form, rv stands for the return value of the function (the argument list isn't yet complete or standardised). Remember that the rv (return value) is the lowest element on the stack.Code:
Just an example of the available resources for now... |
i for one say. Really great job there^^
|
great, thanks!
|
Great job! Very usefull, ill give you some cash
|
omg first post and such a good job.thanks
|
woot!
was really helpful to me... i think i got the important part now. thx again. :thumbup: but as far as i could figure it out now you all need this stack pointer, i mean "shift_sp" thingy if you call a function, right? |
next question why cant i use:
"shift_sp -3" instead of "shift_sp -2" "shift_sp -1" |
Quote:
|
all that is what you learn if you program a microprocessador like 6600 in asm ^^ or an intel processor, then you will see the stack pointer ^^. I think is the best languaje for me :P.
|
This Guide is realy helpfull . Tnx for sharing !!! :D :D :D
|
Nice guide, thank you
|
event:
28 myself 32 talker 36 attacker 40 victim 44 private ? 48 ? 52 56 speller ? 60 ? 64 68 creature ? 72 ? 76 ? 80 84 damage ? 88 ? 92 ? 96 100 ask 104 reply 108 skill_id ? 112 ? 116 120 skill_name_id 124 occupation_name_id 128 way_point_index 132 next_way_point_index ? 136 140 weapon_id ? 144 148 x 152 y 156 z ? 160 164 desire 168 event_id 172 question_id 176 timer_id ? 180 ? 184 ? 188 192 i0 196 i1 200 i2 204 i3 208 i4 212 i5 216 i6 272 с0 276 c1 280 c2 324 _code 328 _choice_N 332 _from_choice CSharedCreatureData* talker, myself, attacker, private, creature, sm, master, boss, top_desire_target: 8 x 16 y 24 z 108 is_pc (bool) 112 alive 148 race 152 occupation 160 name 248 sp 344 hp (float) 352 mp (float) 384 target_index 388 target_id 412 karma 644 quest_last_reward_time 664 pledge_id 672 is_pledge_master (bool) 888 level 1000 max_hp 1144 equiped_weapon_class_id 1148 attack_type 1332 last_blow_weapon_class_id 1336 ai 1620 npc_class_id 1624 weight_point 1628 respawn_time 1716 flag 1892 db_value 2308 p_state ? m_state 2316 i_quest0 2320 i_quest1 2324 i_quest2 2336 i_ai0 2340 i_ai1 2344 i_ai2 2360 c_quest0 2364 c_quest1 2368 c_quest2 2380 c_ai0 2384 c_ai1 2388 c_ai2 2400 sm ??? what is it ??? 2404 master 2408 boss 2412 top_desire_target 2428 start_x (defined in npcpos.txt) 2432 start_y (defined in npcpos.txt) 2436 start_z (defined in npcpos.txt) 2500 sit_on_stop plz, add missing parameters |
2316 i_quest0
2320 i_quest1 2324 i_quest2 2336 i_ai0 2340 i_ai1 2344 i_ai2 what do those do? they must have a sense... i found some i_ai codes in ai.obj but couldnt guess their meaning... |
u can use it to save data. but it's not permanent cos once server is restarted info is deleted.
and btw u can use from 0 to 4 and i think c_ai0... is for strs while this one are for int. |
i extracted this info fom sina ai.obj
Code:
fetch_i // karma |
I have added the references section to the original post but only the function calls reference is populated (the resources reference has just some examples and the others will be updated soon).
In the next update I will go through the tutorial describing the event_handlers, the event data structure and the object oriented aspect of the stack machine. |
I suggest two way to set VALUES into DB. Per-PC and per-NPC.
Per PC: There is "Quest" table in "lin2world" database. In this table is writed down quest data per each PC. Every PC have 16 sets of variables q,s,j. q - quest number s - state j - journal SetMemo(CSharedCreatureData *PC,int q) - add new set to "quest" table RemoveMemo(CSharedCreatureData* PC,int q) - clear the set of variables SetMemoState(CSharedCreatureData* PC,int q,int s) - set s for q SetJournal(CSharedCreatureData* PC,int q,int j) - set j for q First set of vars (q=255,s,j) is used by server (i dont know for which purposes). You may use other 15 sets for per-PC data storing (don`t forget about quests :)) Per NPC (more difficult :): There is "npc_boss" table in "lin2world" database. In this table is writed down information about npcs: alive - =0 or =1 hp,mp,pos_x,pos_y,pos_z - HP,MP,POS current values time_low,time_high - ? (death_time and other) i0 - extra variable Look at npcpos.txt. NPC description may include "dbname=[<NPC_db_name>] dbsaving={parameters}" parameters. This parameters is allowed only for npcpos.txt. When server start, it read npcpos.txt and create NPCs. If "dbsaving" parameter is exist, server load alive,hp,mp,pos_x,pos_y,pos_z,time_low,time_high,i 0 values from "npc_boss" table (select * from npc_boss where npc_db_name=@NPC_db_name). What is the i0 variable? This is the db_value variable in CSharedCreatureData structure (offset 1892). How to use: 1) void CNPC::SetDBValue(CSharedCreatureData* c,int Value) - set i0 and myself.sm.db_value value 2) myself.sm.db_value - read this value. If you need to save not per-PC or per-NPC, you may create new NPCs (as many as u need) and use i0 & SetDBValue() method. How get CSharedCreatureData* pointer of any NPC from any NPC in ai-script? I will share later this info . -- sorry 4my english. Learn russian lang! |
wow nice one, i want more !!
|
Minor Update
In the references:
|
very very nice guide!
here's some cash! :D keep up the good work! :) |
Sorry, im trying to understand.. first question: it is like asm tutorial, right?
second: Code:
|
first it will give the character one item with the id 8324 and then it will show him the page "nonexistent_menu_selected_ask_reply.htm" ;)
|
Thanks.. this is the patch for default npc menu selected.. so why should it give item 8324? And is this ID a known item? I dont have it
|
Quote:
|
The above code does exactly what toolpunk described. It seems to be an html exploit trap where the player is given a custom item to mark him.
If handler 32 isn't overriden* in a class that inherits the default npc class then this handler code will be executed. *you override a class handler by defining the handler in the inherited class. Handler 32 is executed every time that an ask-reply combo is given to an npc. |
| All times are GMT. The time now is 21:45. |