Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела

Notices

 
 
Thread Tools Search this Thread Display Modes
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  
Old 02.05.2007, 11:10   #2
HF
Архивный участник
 
Join Date: Aug 2005
Posts: 1,531
Default

what is it?

1)
Code:
shift_sp 1
maybe
Code:
shift_sp -1
?

2)
Code:
push_event	
push_const 48  //  attacker
Use compiler?
HF is offline  
Old 02.05.2007, 11:11   #3
L2Requiem
Архивный участник
 
Join Date: Oct 2006
Posts: 64
Default

wish i knew AI dude. i'd be honored to help you out...
best way i can say is to just test it.
L2Requiem is offline  
Old 02.05.2007, 12:39   #4
alysia
Архивный участник
 
Join Date: Apr 2005
Posts: 151
Default

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
alysia is offline  
Old 02.05.2007, 13:42   #5
forsage
Архивный участник
 
Join Date: Oct 2006
Posts: 17
Default

Quote:
Originally Posted by alysia View Post
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/f...ead.php?t=2367) , but now , I think this for C1 ai.
forsage is offline  
Old 02.05.2007, 13:44   #6
FidoW
Архивный участник
 
Join Date: Sep 2005
Posts: 1,014
Default

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);
  }

}
C4 AI.OBJ
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
FidoW is offline  
Old 02.05.2007, 13:53   #7
FidoW
Архивный участник
 
Join Date: Sep 2005
Posts: 1,014
Default

Quote:
Originally Posted by forsage View Post
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/f...ead.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.
FidoW is offline  
Old 02.05.2007, 16:03   #8
forsage
Архивный участник
 
Join Date: Oct 2006
Posts: 17
Default

Quote:
Originally Posted by FidoW View Post
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 :
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);
  }

}
forsage is offline  
Old 02.05.2007, 18:24   #9
GMan
Архивный участник
 
Join Date: Sep 2005
Posts: 198
Default

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
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
GMan is offline  
Old 02.05.2007, 18:40   #10
FidoW
Архивный участник
 
Join Date: Sep 2005
Posts: 1,014
Default

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 ...)
FidoW is offline  
Old 02.05.2007, 19:41   #11
GMan
Архивный участник
 
Join Date: Sep 2005
Posts: 198
Default

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
that equates to

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");
		}
	}

}
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
GMan is offline  
Old 03.05.2007, 07:28   #12
forsage
Архивный участник
 
Join Date: Oct 2006
Posts: 17
Default

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
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:

Code:
class test : (null)
{
handler:
	EventHandler ATTACKED(attacker,damage)
	{
		if( ( attacker + 1092 ) > 10 )
		{
			myself->Say("Text 1");
		}
		else
		{
			myself->Say("Text 2");
		}
	}

}
forsage is offline  
Old 03.05.2007, 12:08   #13
FidoW
Архивный участник
 
Join Date: Sep 2005
Posts: 1,014
Default

( attacker + 1092 ) ??

attacker.level
FidoW is offline  
Old 03.05.2007, 13:12   #14
forsage
Архивный участник
 
Join Date: Oct 2006
Posts: 17
Default

Quote:
Originally Posted by FidoW View Post
( attacker + 1092 ) ??

attacker.level
I got this from decompiler
forsage is offline  
Old 10.05.2007, 16:55   #15
forsage
Архивный участник
 
Join Date: Oct 2006
Posts: 17
Default

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);
forsage is offline  
Old 10.05.2007, 18:48   #16
FidoW
Архивный участник
 
Join Date: Sep 2005
Posts: 1,014
Default

Look at this... is an example i found in AI.

Code:
s0 = fnHi + RoomIndex + ".htm";
myself->ShowPage(talker,s0);
FidoW is offline  
Old 11.05.2007, 01:39   #17
forsage
Архивный участник
 
Join Date: Oct 2006
Posts: 17
Default

Quote:
Originally Posted by FidoW View Post
Look at this... is an example i found in AI.

Code:
s0 = fnHi + RoomIndex + ".htm";
myself->ShowPage(talker,s0);
Thank you
forsage is offline  
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 17:21.