View Full Version : ai.obj coding question
Hello
I'm new in ai coding.
For example, I take elpy with class warrior_flee
I want , that after each kick (attack) , elpy say random some phrases...
So, I modified ai code:
class warrior_flee : warrior
{
handler:
EventHandler NO_DESIRE()
{
AddMoveAroundDesire(40, 20);
}
EventHandler ATTACKED(attacker, damage)
{
if ( Rand(2) == 1 )
{
Say("test");
}else{
Say("test1");
}
AddFleeDesire(attacker, 30);
}
}
and ai.obj:
class 1 warrior_flee : warrior
handler 0 9 // NO_DESIRE
variable_begin
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end
push_event
push_const 704 // myself
add
fetch_i
push_const 40
push_const 20
func_call 184680455 // func[AddMoveAroundDesire]
shift_sp -2
shift_sp -1
handler_end
handler 1 38 // ATTACKED
variable_begin
"attacker"
"damage"
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end
push_event
push_const 704 // myself
add
fetch_i
shift_sp 1
push_const 2
func_call 218169344 // func[Rand]
shift_sp -1
push_const 1
equal
branch_false L2480
L2479
shift_sp 1
S325. "test"
push_string S325
func_call 184614973 // func[Say]
shift_sp -1
shift_sp -1
jump L2481
L2480
shift_sp 1
S326. "test1"
push_string S326
func_call 184614973 // func[Say]
shift_sp -1
shift_sp -1
L2481
shift_sp 1
push_event
push_const 48 // attacker
add
fetch_i
push_const 30
func_call 184680461 // func[AddFleeDesire]
shift_sp -2
shift_sp -1
handler_end
class_end
Is it correct ?
what is it? :confused:
1)
shift_sp 1
maybe
shift_sp -1 ?
2)
push_event
push_const 48 // attacker
Use compiler?
L2Requiem
02.05.2007, 11:11
wish i knew AI dude. i'd be honored to help you out... :(
best way i can say is to just test it.
I would like to help you but I need some important Information
your AI code seems to be from C1 AI but with C4 handler/func
so? It should be C1 AI? or C4 AI?
@HF
the shift_sp 1 is correct for C1 because there it was the same like now the push_event/myself
I would like to help you but I need some important Information
your AI code seems to be from C1 AI but with C4 handler/func
so? It should be C1 AI? or C4 AI?
Ok, it should be for C4 ai
I used nasc for c1 , and then , manually changed functions for C4
Is this wrong way ?
I found only one good tutorial here (https://postpacific.loc-online.com/forums/showthread.php?t=2367) , but now , I think this for C1 ai.
The NASC syntax looks like C1... isnt using objects (myself, gg) but in the compiled code is using C4 ids, and in some functions use objects and others not... looks like he was trying to do a mix or whatever...
For those who try to learn... here the correct code..
C1 NASC
class warrior_flee : warrior {
handler:
EventHandler NO_DESIRE() {
AddMoveAroundDesire(40,20);
}
EventHandler ATTACKED(attacker,damage) {
if (Rand(2) == 1) Say("Text1");
else Say("Text2");
AddFleeDesire(attacker,30);
}
}
C1 AI.OBJ
class warrior_flee : warrior
handler 0 // NO_DESIRE
variable_begin
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end
shift_sp 1
push_const 40
push_const 20
func_call 0 // func[AddMoveAroundDesire]
shift_sp -2
shift_sp -1
handler_end
handler 1 // ATTACKED
variable_begin
"attacker"
"damage"
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end
shift_sp 1
push_const 2
func_call 55 // func[Rand]
shift_sp -1
push_const 1
equal
branch_false L1
L0
shift_sp 1
S0. "Text1"
push_string S0
func_call 37 // func[Say]
shift_sp -1
shift_sp -1
jump L2
L1
shift_sp 1
S1. "Text2"
push_string S1
func_call 37 // func[Say]
shift_sp -1
shift_sp -1
L2
shift_sp 1
push_event // attacker
push_const 36
add
fetch_i
push_const 30
func_call 6 // func[AddFleeDesire]
shift_sp -2
shift_sp -1
handler_end
class_end
C4 NASC
class warrior_flee : warrior {
handler:
EventHandler NO_DESIRE() {
myself->AddMoveAroundDesire(40,20);
}
EventHandler ATTACKED(attacker,damage) {
if (gg->Rand(2) == 1) myself->Say("Text1");
else myself->Say("Text2");
myself->AddFleeDesire(attacker,30);
}
}
C4 AI.OBJ
class 1 warrior_flee : warrior
handler 0 9 // NO_DESIRE
variable_begin
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end
push_event // myself
push_const 704
add
fetch_i
push_const 40
push_const 20
func_call 184680455 // func[AddMoveAroundDesire]
shift_sp -2
shift_sp -1
handler_end
handler 1 46 // ATTACKED
variable_begin
"attacker"
"damage"
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end
push_event // gg
push_const 632
add
fetch_i
push_const 2
func_call 218169344 // func[Rand]
shift_sp -1
push_const 1
equal
push_reg_sp
fetch_i
branch_false L1
L0
push_event // myself
push_const 704
add
fetch_i
S0. "Text1"
push_string S0
func_call 184614973 // func[Say]
shift_sp -1
shift_sp -1
jump L2
L1
push_event // myself
push_const 704
add
fetch_i
S1. "Text2"
push_string S1
func_call 184614973 // func[Say]
shift_sp -1
shift_sp -1
L2
push_event // myself
push_const 704
add
fetch_i
push_event // attacker
push_const 48
add
fetch_i
push_const 30
func_call 184680461 // func[AddFleeDesire]
shift_sp -2
shift_sp -1
handler_end
class_end
Ok, it should be for C4 ai
I used nasc for c1 , and then , manually changed functions for C4
Is this wrong way ?
I found only one good tutorial here (https://postpacific.loc-online.com/forums/showthread.php?t=2367) , but now , I think this for C1 ai.
You can use as base the first times but the way i do is looking directly in C4 AI.obj, after compile several codes you start to know how to do without look at other code, and always you can use C4 Decompiler (thx to Sauron) to check if you're in the good way.
The NASC syntax looks like C1... isnt using objects (myself, gg) but in the compiled code is using C4 ids, and in some functions use objects and others not... looks like he was trying to do a mix or whatever...
For those who try to learn... here the correct code..
Thank you very much :)
Tell me please, where I can found information about objects ?
I understand, for example, what mean myself and attacker, but what mean gg ?
Another question.
Can I use my own vars in nasc code ?
For example :
class warrior_flee : warrior {
handler:
EventHandler NO_DESIRE() {
myself->AddMoveAroundDesire(40,20);
}
EventHandler ATTACKED(attacker,damage) {
my var1 = gg->Rand(3);
if (var1 == 1) {
myself->Say("Text1");
}else if (var1 == 2) {
myself->Say("Text2");
}else{
myself->Say("Text3");
}
myself->AddFleeDesire(attacker,30);
}
}
yea, to use your own vars you specify them on the parameters section on the class in the AI it looks like this
parameter_define_begin
int myvar 0
parameter_define_end
the format is
VarType VarName DefaultValue
and with that i will "try" to do your if statements in AI
See my next post for proper code
remember this is just an example to show how to set a variable and then check it with an IF
You cant modify the value of a parameter declared before the handler. If you want to modify a param use some as i0, i1, i2 ... or c1, c2, c3.... depend of the type of data (i = int, c = creature ...)
hmm didnt know that. In that case just remove the parameter section and change myvar to i0 or what ever is not in use and i assume add it to the variable list.
here is what i came up with for an example
class 1 test : (null)
parameter_define_begin
int rand_num 3
parameter_define_end
handler 1 12 // ATTACKED
variable_begin
"attacker"
"damage"
"myself"
"i1"
"_choiceN"
"_code"
"_from_choice"
variable_end
push_event // i1
push_const 264
add
push_reg_sp
fetch_i
push_event // gg
push_const 632
add
push_parameter rand_num
func_call 218169344 // func[Rand]
shift_sp -1
assign4
shift_sp -1
L1
push_event // i1
push_const 264
add
fetch_i
push_const 1
equal
branch_false L3
L2
push_event // myself
push_const 704
add
fetch_i
S16926. "Message 1"
push_string S16926
func_call 184614973 // func[Say]
shift_sp -1
L3
push_event // i1
push_const 264
add
fetch_i
push_const 2
equal
branch_false L5
L4
push_event // myself
push_const 704
add
fetch_i
S16926. "Message 2"
push_string S16926
func_call 184614973 // func[Say]
shift_sp -1
jump L6
L5
push_event // myself
push_const 704
add
fetch_i
S16926. "Message 3"
push_string S16926
func_call 184614973 // func[Say]
shift_sp -1
L6
shift_sp -1
handler_end
class_end
that equates to
class test : (null)
{
parameter:
int rand_num = 3;
handler:
EventHandler ATTACKED(attacker,damage,i1)
{
i1 = gg->Rand(rand_num);
if( i1 == 1 )
{
myself->Say("Message 1");
}
if( i1 == 2 )
{
myself->Say("Message 2");
}
else
{
myself->Say("Message 3");
}
}
}
i decided to leave the parameter option in so i could be changed easily and can be changed in the NPCDATA if wanted
Also thought about another method you could use that NCSoft uses, and that is to change he random number to like 100 and then do a few ifs to see if its <20 or >50 this way you get a slightly more random seeming system
anyway hope this helps, sorry to have kinda hijacked your topic but i learned a few things from this topic that i wasn't expecting :)
Thanks !
This is very good information :)
So , I little changed my task.
If attacker's level > 10 , there will be "text 1" message, and else, "text 2" message.
ai code:
class 1 test : (null)
handler 1 12
variable_begin
"attacker"
"damage"
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end
push_event
push_const 48
add
fetch_i
push_const 1092
add
fetch_i4
push_const 10
greater
branch_false L101
L100
push_event
push_const 704
add
fetch_i
S100. "Text 1"
push_string S100
func_call 184614973
shift_sp -1
jump L102
L101
push_event
push_const 704
add
fetch_i
S101. "Text 2"
push_string S101
func_call 184614973
shift_sp -1
L102
handler_end
class_end
Is it right ?
One another question, what difference between fetch_i4 and fetch_i ?
If I change fetch_i4 at fetch_i , the result of decompiler as the same:
class test : (null)
{
handler:
EventHandler ATTACKED(attacker,damage)
{
if( ( attacker + 1092 ) > 10 )
{
myself->Say("Text 1");
}
else
{
myself->Say("Text 2");
}
}
}
( attacker + 1092 ) ??
attacker.level
( attacker + 1092 ) ??
attacker.level
I got this from decompiler
Tell me please , can I use in NASC string variable ?
For example, something, like this:
i0 = ( gg->Rand(10) );
my_string_var="my_own".i0.".htm";
myself->ShowPage(talker,my_string_var);
Look at this... is an example i found in AI.
s0 = fnHi + RoomIndex + ".htm";
myself->ShowPage(talker,s0);
Look at this... is an example i found in AI.
s0 = fnHi + RoomIndex + ".htm";
myself->ShowPage(talker,s0);
Thank you :)