![]() |
|
|
#1 |
|
Архивный участник
Join Date: Oct 2006
Posts: 17
|
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: 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);
}
}
Code:
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 |
|
|
|
|
#2 |
|
Архивный участник
Join Date: Aug 2005
Posts: 1,531
|
what is it?
1) Code:
shift_sp 1 Code:
shift_sp -1 2) Code:
push_event push_const 48 // attacker |
|
|
|
|
#3 |
|
Архивный участник
Join Date: Oct 2006
Posts: 64
|
wish i knew AI dude. i'd be honored to help you out...
![]() best way i can say is to just test it. |
|
|
|
|
#4 |
|
Архивный участник
Join Date: Apr 2005
Posts: 151
|
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 |
|
|
|
|
#5 | |
|
Архивный участник
Join Date: Oct 2006
Posts: 17
|
Quote:
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/f...ead.php?t=2367) , but now , I think this for C1 ai. |
|
|
|
|
|
#6 |
|
Архивный участник
Join Date: Sep 2005
Posts: 1,014
|
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 Code:
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 Code:
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 Code:
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);
}
}
Code:
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
|
|
|
|
|
#7 | |
|
Архивный участник
Join Date: Sep 2005
Posts: 1,014
|
Quote:
|
|
|
|
|
|
#8 | |
|
Архивный участник
Join Date: Oct 2006
Posts: 17
|
Quote:
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 : Code:
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);
}
}
|
|
|
|
|
|
#9 |
|
Архивный участник
Join Date: Sep 2005
Posts: 198
|
yea, to use your own vars you specify them on the parameters section on the class in the AI it looks like this
Code:
parameter_define_begin int myvar 0 parameter_define_end 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 |
|
|
|
|
#10 |
|
Архивный участник
Join Date: Sep 2005
Posts: 1,014
|
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 ...)
|
|
|
|
|
#11 |
|
Архивный участник
Join Date: Sep 2005
Posts: 198
|
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 Code:
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 Code:
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");
}
}
}
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
|
|
|
|
|
#12 |
|
Архивный участник
Join Date: Oct 2006
Posts: 17
|
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: 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 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: Code:
class test : (null)
{
handler:
EventHandler ATTACKED(attacker,damage)
{
if( ( attacker + 1092 ) > 10 )
{
myself->Say("Text 1");
}
else
{
myself->Say("Text 2");
}
}
}
|
|
|
|
|
#13 |
|
Архивный участник
Join Date: Sep 2005
Posts: 1,014
|
( attacker + 1092 ) ??
attacker.level |
|
|
|
|
#14 |
|
Архивный участник
Join Date: Oct 2006
Posts: 17
|
|
|
|
|
|
#15 |
|
Архивный участник
Join Date: Oct 2006
Posts: 17
|
Tell me please , can I use in NASC string variable ?
For example, something, like this: Code:
i0 = ( gg->Rand(10) ); my_string_var="my_own".i0.".htm"; myself->ShowPage(talker,my_string_var); |
|
|
|
|
#16 |
|
Архивный участник
Join Date: Sep 2005
Posts: 1,014
|
Look at this... is an example i found in AI.
Code:
s0 = fnHi + RoomIndex + ".htm"; myself->ShowPage(talker,s0); |
|
|
|
|
#17 |
|
Архивный участник
Join Date: Oct 2006
Posts: 17
|
|
|
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|