PDA

View Full Version : a little ai for you


Ninja Kitteh
24.08.2006, 03:22
there we go
full working, non-nasc code. (might not decompile to nasc, since I never use nasc)

class 1 npc_ai : merchant
//
//BEGIN
//
handler 32 99999 // MENU_SELECTED
variable_begin
"talker"
"ask"
"reply"
"i0"
"i1"
"i2"
"i3"
"i4"
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end

push_event // ask
push_const 160
add
fetch_i4
push_const 581
equal
branch_false L99999
push_event // reply
push_const 164
add
fetch_i4
push_const 2
equal
branch_false L99999
//
//COUNT
//
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6360
func_call 184680579 // func[OwnItemCount]
shift_sp -2
push_const 1
greater_equal
branch_true L99995
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6361
func_call 184680579 // func[OwnItemCount]
shift_sp -2
push_const 1
greater_equal
branch_true L99995
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6362
func_call 184680579 // func[OwnItemCount]
shift_sp -2
push_const 0
equal
branch_true L99997
//
//VERIFY, and ASSIGN
//
L99995
shift_sp 2
push_event // i0
push_const 260
add
push_reg_sp
fetch_i
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6360
func_call 184680579 // func[OwnItemCount]
shift_sp -2
assign4
shift_sp -1
push_event // i1
push_const 264
add
push_reg_sp
fetch_i
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6361
func_call 184680579 // func[OwnItemCount]
shift_sp -2
assign4
shift_sp -1
push_event // i2
push_const 268
add
push_reg_sp
fetch_i
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6362
func_call 184680579 // func[OwnItemCount]
shift_sp -2
assign4
shift_sp -1
L99996
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
S99959. "confirm.htm"
push_string S99959
func_call 184680516 // func[ShowPage]
shift_sp -2
//
//DELETE
//
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6360
push_event // i0
push_const 260
add
fetch_i4
func_call 184746114 // func[DeleteItem1]
shift_sp -3
shift_sp -1
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6361
push_event // i1
push_const 264
add
fetch_i4
func_call 184746114 // func[DeleteItem1]
shift_sp -3
shift_sp -1
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 6362
push_event // i2
push_const 268
add
fetch_i4
func_call 184746114 // func[DeleteItem1]
shift_sp -3
shift_sp -1
//
//CONVERT
//
push_event // i3
push_const 272
add
push_reg_sp
fetch_i
push_event // i0
push_const 260
add
fetch_i4
push_const 1
mul
push_event // i1
push_const 264
add
fetch_i4
push_const 2
mul
add
push_event // i2
push_const 268
add
fetch_i4
push_const 3
mul
add
assign4
shift_sp -1
//
//GIVE
//
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
push_const 5575
push_event // i3
push_const 272
add
fetch_i4
func_call 184746111 // func[GiveItem1]
shift_sp -3
shift_sp -1
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
S99969. "thankyou.htm"
push_string S99969
func_call 184680516 // func[ShowPage]
shift_sp -2
jump L99999
L99997
push_event // myself
push_const 704
add
fetch_i
push_event // talker
push_const 40
add
fetch_i
S99979. "noitems.htm"
push_string S99979
func_call 184680516 // func[ShowPage]
shift_sp -2
L99999
call_super
handler_end

class_end

wfx[hp]
24.08.2006, 07:01
some bugs are in it.. sry i forgot to save the final version before i implimented it into the main ai.obj
questions? feel free to ask =D

class 1 hiddenpurpose : merchant
class_end

edit: sry about the title... i tried changing it after i posted
This script is full of bugs:
1) you forged to pass myself, talker to ShowPage() functions.
2) you forged to do "shift_sp -2", "shift_sp -1" after ShowPage().
3) you must change "shift_sp -1" to "fetch_i4" after assign4.
4) all condional jumps must use "branch_false LABEL", "branch_true" allowed only as part of compiling complex expression like "if (expr1 || expr2)".
5) you make "cond.jump" into blocks of another "if (...)"

Please use old (C1) NASC to make skeleton of you handler, after that make some C1-C4 changes :)

Ninja Kitteh
24.08.2006, 11:42
1) you forged to pass myself, talker to ShowPage() functions.
2) you forged to do "shift_sp -2", "shift_sp -1" after ShowPage().
correct

3) you must change "shift_sp -1" to "fetch_i4" after assign4.
nope

4)all condional jumps must use "branch_false LABEL", "branch_true" allowed only as part of compiling complex expression like "if (expr1 || expr2)".
who codes using nasc these days?
this is completely coded in L2 assemble
branch true works perfectly fine

5) you make "cond.jump" into blocks of another "if (...)"
works perfectly =D
imo nasc creates too many lines of junk code
why do you need
L123
L124
L125
L..
L..
L..
L..
call super
handle_end
class_end


digging out final code now
nasc FTL