![]() |
[Guide] AI
This documentation not for sell and re-sharing. Save my name for each quote on another resource.
For newbie, for myself, for people who want know more. Note. If you want something add, fix and etc - say. We can do good documentation for AI language. Note 2. How to create new class on AI "C+ decompile language" (no retail language) can read there. Note 3. If you want understund AI code better, you must have C4Decompiler (by Sauron) or retail NCSoft decompiler and can make a text simpler for the understanding. AI Header AI Class AI Parameters AI Handler AI Common commands |
AI header
AI.obj file always have this header.
Retail build523 Quote:
Note: But L2Npc.exe show red error about bad version. Work parameters: Quote:
|
AI Class
Entire AI.obj file - this is the collection of classes.
Each class have structure: Code:
class 1 default_npc : (null)class 1 default_npc : (null)
class_end Define end of class. Required always. One class can have more parents classes. Example, class 1 thermal_nepenthes : warrior_ag_casting_enchant_rangephysical_poison class 1 warrior_ag_casting_enchant_rangephysical_poison : warrior_casting_enchant_rangephysical_poison class 1 warrior_casting_enchant_rangephysical_poison : warrior_casting_enchant_physical_poison class 1 warrior_casting_enchant_physical_poison : warrior class 1 warrior : warrior_parameter class 1 warrior_parameter : monster_parameter class 1 monster_parameter : default_npc class 1 default_npc : (null) |
parameter_define_begin
(content) parameter_define_end Each class can use custom constant's. You can define types - string, int, float, waypointstype, waypointdelaystype. Example, Quote:
Same constants define and in npcdata.txt Code:
npc_ai={[silvia];{[fnHi]=[silvia001.htm]};...2) If npcdata have not this definition, AI class will be use value from parameter_define area. 3) If npcdata have param, but AI class (full tree structure for this class) have not this param in parameter_define area, then npcserver show error in console: Code:
06/18/2007 14:07:xx.xx2, Npc[silvia] doesn't have parameter[fnHi]. failed to setCode:
06/18/2007 14:07:xx.xx2, Npc[silvia] doesn't have parameter[fnhi]. failed to set(content) where property_define_begin - start word for properties property_define_end - end word for properties This area can have two definitions - teleport list (telposlist) for gatekeeper and merchant buy/sell (buyselllist) for shops Example: Code:
telposlist_begin RaidBossList20_29telposlist_begin - start word for teleport list definitions RaidBossList20_29 - name of teleport list telposlist_end - end word for teleport list definitions each property can have more then one teleport list, but teleportname must be unique in this property. Example, Code:
telposlist_begin RaidBossList20_29{"Madness Beast (lv20)"; -54096; 84288; -3512; 0; 0 } "Madness Beast (lv20)" - name of place. What you see in GK dialoge. -54096; 84288; -3512; - X, Y, Z coordinates where you will be after selected this place 3000 - price for teleport. Can be only positive (or 0, for free teleport). 5 - parent castle name for this teleport location. If goes on the siege of castle with number 5 (Aden), then you will not be able to teleport, until siege goes on. Note. If your teleport coordinates wrong, l2server show red error Code:
container NULL pos[X, Y, Z]..."Code:
buyselllist_begin - start word for shop list definitions SellList5 - name of buy/sell list buyselllist_end - end word for shop list definitions each property can have more then one shop list, but shoplist name must be unique in this property. Example, Code:
buyselllist_begin SellList53960 - item id. name=[Mercenary Posting Ticket (Sword/Stationary)] 20 - Castle Town Tax Rate (in %). Example, full price for item in shop = default_price (in itemdata) + default_price * Castle Tax Rate% + default_price * Castle Town Tax Rate%. 0.000000 - unknown 0 - unknown |
AI Handler
Each handler have structure:
Code:
handler 3 0 // TALKEDhandler - start word for handler 3 - handler id (full list sometime later) 0 - amount handler code lines (later) TALKED - name of handler (this only commentarie) variable_begin - start word for variable list variable_end - end word for variable list handler_end - end word for handler Example handler 10 0 // MY_DYING handler_end handler 11 0 // TIMER_FIRED handler_end variable_begin must be defined always. Guide to list of paramerer later. Amount lines in handler Example: Code:
handler 3 6 // TALKEDValue for amount lines in handler define "How much memory required by server for working with this handler." If you have small value - your server can be crashed because memory not enought for working this npc. Or, if you have big value - your server can be use a lot memory and cause leak memory after sometimes. |
Looks nice as always, thanks
|
AI Common commands
Handler
call_super exit_handler Variable definition type fetch_f fetch_i4 fetch_d fetch_i Stack using push_const push_string add_string push_parameter push_property push_reg_sp Arithmetical commands assign4 assign add sub div mul negate mod Bit operation bit_or bit_and xor not Functions func_call Logical equal greater greater_equal not_equal less_equal less and or Stack using shift_sp Hyperlinks jump branch_false branch_true Labels Lxxx Sxxx note. where * - increased number |
Note. Guide for using all push_
Code:
push_constCode:
push_const 1000Code:
push_string S0Code:
push_parameter fnHiCode:
push_property SellList0Code:
add_string 1025Code:
S973. "crop_client_info" |
How use commands:
push_event, push_const, add, fetch_i, push_string, func_call, shift_sp, Sxxx Example Code:
handler 4 13 // TALK_SELECTED1) handler 4 13 // TALK_SELECTED Some examples: Handler 'TALK_SELECTED' uses when player select link 'Quest'. Handler 'TALKED' uses if your npc can show dialoge for you (not attacked). Uses for checking PK player for open required dialog or etc. Handler 'CREATED' uses for npc who create Privates around self. Example, Pytan spawned. Server check handler 'CREATED' in 'pytan' ai class and start it. Next reading Private list and spawned privates from this handler. Example 2, this handler uses for start walking npc to required point, for start timer and etc. 2) Variables Code:
variable_begin3) Code 3.1) Code:
push_event // myselfNote. server save not integer 704, but real memory offcet for this event Code:
push_event // talkerCode:
S0. "noquest.htm"push_string command read string data from label S0 to memory. Function Code:
func_call 184680516 // func[ShowPage]Function 'ShowPage' have id in npcserver as 184680516. Note. Retail pack (free share C4server retail pack) have bug value for fetch, event, func. Function 'ShowPage' required 2 input parameter and 1 output. This function in decompiled mode: Code:
myself->ShowPage(talker, fnHi);Note. This decompiled format use C4Decompiler (by Sauron). Another developer can use another, like this: Code:
ShowPage(talker.myself, fnHi);Code:
shift_sp -2Clear -1 stack because we used 1 output 'myself->' param. handler_end Required handler end definition. Check amount lines - 13. |
Simple using Function.
Func_call, push_const, mul Code:
push_event // myself
|
Quote:
add xor mod bit_or bit_and not -------- Class 1 Class 2 Type 1 for NPCs, Type 2 for Npc Maker (defines spawning rules) -------- Are you sure that labels are not counted in handlers lenght? Cos from original AI I can tell that they are counted. |
Example for using branch_false, not_equal (decompiled code If, else)
Note. 'PARTY_ATTACKED' uses if monster see what one from him party has been attacked Code:
class 1 party_private : party_private_paramThere you have known structure for using function and new command 'branch_false' and working 'add' for multiple events. Note: Code:
addCode:
push_event // myself
Code:
handler PARTY_ATTACKED (attacker, private, damage, f0)Another example for brench_false without second param. Code:
class 1 castle_merchant : citizenCode:
if (myself->IsMyLord(talker))Code:
if (myself->IsMyLord(talker) == True) |
Quote:
add = + xor = xor mod = / ... Quote:
|
Use 'assign'
Code:
class 1 undead_priest : warrior_pa_slow_type2always_list (1) and gg->AllocCodeInfoList() (2) uses in - operation is value assignment 'gg->AllocCodeInfoList()' for variable 'always_list' Code:
always_list = gg->AllocCodeInfoList();Short and easy example: Code:
L2269Code:
i0 = i0 + 1000322; |
This is awesome, i was taking my first look at ai last night and this is just what i needed to get me started, thanks.
|
Quote:
|
Quote:
Code:
case 'mul':Quote:
|
Quote:
1) maybe you can more changes in decompiler? :) "New unoffical release" :rolleyes: 2) Oh.. yes... I wrong. Wrong only in thread. Yes. Need count all and Lxxx labels too. I can confirm it - my tool, im always counting with Labels. But another developers have different openition. You can find thread about "C4 compiler" service. I'll fix everywhere in this thread all my errors. |
This thread is amazing, great work HF im impressed, I hope you build on this further.
|
So many work in one place. Big kudos!
|
Quote:
Or maybe you are interested in version for C1? I made one by changing Sauron's C4 version. |
Quote:
|
Great thread indeed. Pretty awesome job HF. :)
Quote:
Those're revisions. SizeofPointer is the pointer which makes the ai.obj 'xx-bits'.. so.. 8^8 = 64 bit. 20^8 = 160 bits. try it, u'll see msg.. like.. Invalid ai.obj compiled from 160 bit nasc blabla in console if u change the pointer to 20. it's hardcoded in l2npc. SharedFactoryVersion is a version info too l2npc related, also hardocded. NPCHVersion aka npc.h version is header for nasc obviously, so anyways.. true values depends on l2npc itself. it's hardcoded in l2npc. NASCVersion..nasc version ai was compiled from..also hardcoded in l2npc.. NPCEvent header.. also hardcoded.. i dunno about debug.. yet. And also.. the true values for each of these in l2npc..IDA wise.. Code:
SharedFactoryVersion: |
Quote:
Code:
handler 0 0 // NO_DESIRECode:
handler 4 13 // TALK_SELECTEDCode:
handler 3 38 // TALKED |
Quote:
0 - count of items that sell... Ex.: {3960; 20; 1.000000; 5 } - in one hour we may buy only 5 items. /rus 0.000000 - время в часах 0 - количество итемов доступных на продажу. Если там например стоит 5 - то купив эти 5 шт, новые появятся только черех промежуток времени обозначенный выше, например: {3960; 20; 1.000000; 5 } - получается в час можно купить 5 штук этого итема. p.s.: со временем могу конечно ошибаться - замерял "на глаз" :) rus/ |
Мне убится=) Но как первый пост прочитать если он английский перевидете малолетке который жаждет перевода:p
|
[offtop]
Лучше убейся. учи английский. [/offtop] |
Quote:
Quote:
"I dont know what discussion" What discussion? :) Because i has long discussion on russian forum about it. And this why i add checkbox "Count without labels" to my 'L2SM:HandlerLine Checker' module. :) Quote:
Reputation for all! :) P.S. It thread not ended. Sure, i'll continue. All this I wrote in the state, when it was boring. |
SizeofPointer does. AI won't work with it being more than 64 bit. Rest, i have no idea, prolly with different l2npc, it will.
I had this one AI where the nascversion and sharedfactoryversion was different, that's when i tried and found the values. |
[offtop]
HF - как пурга поживает?=) [/offtop] |
I havent go through your entire guide yet but this is what i was looking for. Thanks! <3 much appreciated ^^
|
Some 'vars' I've found which were now included in Sauron's decompiler data. Because they were not used in retail c4 pts AI, but they might be usefull for someone. Names are my own imagination :P
Code:
284|default|exp_**Code:
push_event // talker |
Quote:
one question - ** - it normal, full name for this vars? so strange |
I said I made this names from my head ;) _** was to point that this are new values.
I found them in easy way - by making AI with like 800 executions of function Say() and by reading what it outputs... ;P |
Wow, this is great, thanks a lot :).
|
Awesome guide, I learned a lot.
|
| All times are GMT. The time now is 16:24. |