View Full Version : AI, func[rand] usage and conditions
hello,
i am looking to understand how func[rand] works and how to use it with conditions, here the algo i want to do:
Select a random integer between 0 and 3 (i dunno if it is correct)
if result <=1 goto L1
if result =2 goto L2
if result >=3 goto L3
and here the syntax i suppose i have to use with AI:
L0
push_parameter 3 // 0 to 3 ? 1 to 3 ?
func_call 55 // func[Rand]
push_const 1 // if result <= 1
less_equal // goto L1
jump L1
push_const 2 // if result = 2
equal // goto L2
jump L2
or
push_const 3 // if result >= 3
equal // goto L3
jump L3
or
//---------------------------------------
L1
(FUNCTIONS)
jump L4 // goto end
L2
(FUNCTIONS)
jump L4 // end end
L3
(FUNCTIONS)
jump L4 // end end
//---------------------------------------
L4
(EXIT HANDLER)
i dunno if it is correct and i would like to know, if it is possible, how to save the result of func[Rand] in a variable to use it in my FUNCTIONS parts for example.
Tx for your help :)
//i0=Rand(4) => i0 E [0,3]
push_event //i0
push_const 192
add
push_reg_sp
fetch_i
shift_sp 1
push_const 4
func_call 55 //Rand
shift_sp -1
assign
shift_sp -1
//i0==1?
push_event
push_const 192
add
fetch_i
push_const 1
equal
branch_false L1 //goto L1 if not_equal
// here a code if i0==1
...
L1
...
can you explain this part please ?
push_event //i0
push_const 192
add
push_reg_sp
fetch_i
and what does "assign" ...
and finally, can i use the following part to call back i0 each time i need to use it in my stack ?
push_event
push_const 192
add
fetch_i
Tx :)
Metalmurphy
03.12.2005, 13:08
Amazing how u said u were gone from good but u keep asking for help here lol...
Amazing how u said u were gone from good but u keep asking for help here lol...
what we are talking about in this topic can help everybody who want to learn and produce something, if you have no more to say just dont post, people here have better things to do than to read your shit.
Metalmurphy
04.12.2005, 02:05
My shit was the truth, and the truth is all the shit u said before. U insult everyone here, remove ur share posts, insult everyone again, say u'll never post here again yet you keep asking for help.
Oh and the fact that this post can help other ppl (wich it can) doesnt explain the fact that u said u never posted here again yet u keep doing so.
stop me if i say something stupid, but why not use nasc, to compile your own ai code with a language that looks like C
strangely, or not so strangely, i agree with metal
=D
stop me if i say something stupid, but why not use nasc, to compile your own ai code with a language that looks like C
<fr>salut, je ne connaissais tout simplement pas cet outil, je viens donc de le tester mais il ne me compile rien du tout, il plante tout bêtement. peut-être aurais-tu un tuto à me proposer ? en cherchant sur ce forum j'ai lu qu'on pouvait trouver des exemples dans la distrib meifu, je vais voir si je peux trouver çà. merci en tout cas.</fr>
It crash only ? strange.
You can found source code example in l2tools.
Then you just have to specify the filename of source code to compile in the command line of nasc, like "nasc ai_mmerged.txt" (will produce a ai.obj in same directory)
<fr>il plante betement ? bizard.
Tu peux trouver le code source de L2 ('prelude' me semble) dans L2Tools.
Pour compiler ensuite, suffit de donner le nom du fichier a compiler dans la ligne de commande de nasc, ex : "nasc ai_mmerged.txt" qui produira un ai.obj dans le meme repertoire</fr>
hello,
i tried nasc but it is not very clear for me for the moment then i tried to do something with the old way:
push_event // i0
push_const 192
add
push_reg_sp
fetch_i
shift_sp 1
push_const 3 // [0-2]
func_call 55 // Rand
shift_sp -1
assign
shift_sp -1
L0
push_event
push_const 192
add
fetch_i
push_const 0 // if rand <= 0
less_equal
branch_false L1
shift_sp 1
(DO ACTION 0 IF rand <= 0)
shift_sp -1
jump L9 // goto end
L1
push_event
push_const 192
add
fetch_i
push_const 0 // if rand = 1
equal
branch_false L2
shift_sp 1
(DO ACTION 1 IF rand = 1)
shift_sp -1
jump L9 // goto end
L2
push_event
push_const 192
add
fetch_i
push_const 2 // if rand >= 2
greater_equal
branch_false L3
shift_sp 1
(DO ACTION 2 IF rand >= 2)
shift_sp -1
jump L9 // goto end
L3
L9 // end
i cant be sure it is correct because this AI display a PUSH CONST error about data TYPE. If you can just take a look at this part and tell me what you think it could help me maybe.
btw do you know, if it is possible, to do something like:
class my_class : my_parent_class
parameter_define_begin
int MyVar 0
parameter_define_end
handler X
push_parameter MyVar // 0
MyVar = Rand[0-9]
push_parameter MyVar // Rand[0-9] result
handler_end
class_end
Regards
?
in AI language, how do u write that
?
tx :D
Kirikups
03.01.2006, 22:21
hello, i try to do something, i want the following class use randomly 1 of his 3 skills when we attack him:
class myclass : parent_class
parameter_define_begin
int SkillPch0 278018 // s_haste2
int SkillPch1 308226 // s_wind_walk2
int SkillPch2 271107 // s_empower3
int NbSkills 2
parameter_define_end
handler 1 // ATTACKED
variable_begin
"attacker"
"damage"
"i0"
"c0"
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end
...
push_event // i0
push_const 192
add
push_reg_sp
fetch_i
shift_sp 1
push_parameter NbSkills // 2 [0-2]
func_call 55 // Rand
shift_sp -1
assign
shift_sp -1
L18600
push_event // i0
push_const 192 //
add //
fetch_i //
push_const 0 // if i0 <= 0
less_equal
branch_false L18601
shift_sp 1
push_parameter SkillPch0
func_call 155 // func[Skill_GetConsumeMP]
shift_sp -1
jump L18603
L18601
push_event // i0
push_const 192 //
add //
fetch_i //
push_const 1 // if i0 = 1
equal
branch_false L18602
shift_sp 1
push_parameter SkillPch1
func_call 155 // func[Skill_GetConsumeMP]
shift_sp -1
jump L18603
L18602
push_event // i0
push_const 192 //
add //
fetch_i //
push_const 2 // if i0 >= 2
greater_equal
branch_false L18603
shift_sp 1
push_parameter SkillPch2
func_call 155 // func[Skill_GetConsumeMP]
shift_sp -1
jump L18603
L18603
...
handler_end
end_class
and it doesnt work every time :? any idea ?
Tx in advance
Don't use NASC because the headers are different and your AI code will come out messed up. We had this discussion in irc a while ago, and found out the hard way. If you want, you can generate your code and then edit out the faulty header to make it work. Just look at Digital's post on the AI code in the stickies section. :P
The best way is to probably do it by hand.
i use nasc and make some good things, like monster derby track, sevensigns, and stuff that doesnt exist on official server too.
ofcourse, we must replace some number id of functions/handlers, ... but i have make a program to do it, but it's very more useful to code with nasc instead of make ai code