View Single Post
Old 02.05.2007, 10:35   #1
forsage
Архивный участник
 
Join Date: Oct 2006
Posts: 17
Default 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:

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:

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
Is it correct ?
forsage is offline