Post Pacific  

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

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 12.02.2006, 22:24   #1
Kirikups
Архивный участник
 
Join Date: Oct 2005
Posts: 175
Default AI - How join SEE_CREATURE() and TIMER_FIRED() ?

Hello all,

i woudl like to link EventHandler SEE_CREATURE(creature) and EventHandler TIMER_FIRED() then i wrote:

Code:
	EventHandler SEE_CREATURE(creature)
	{
		if ((myself.c_ai0 != creature)
		{
			myself.c_ai0 = creature;

			myself.i_ai1 = creature.x;	// i save creature/pc location_x
			myself.i_ai2 = creature.y;	// i save creature/pc location_y
			myself.i_ai3 = creature.z;	// i save creature/pc location_z

			myself.i_ai0 = 0;		// atm NPC dont attack creature/pc

			SetTimerPeriod(5);		// in 5 secs i want to check if PC moved or not
		}
	}

	EventHandler TIMER_FIRED()
	{
		if ((myself.i_ai0 == 0) && (myself.i_ai1 == myself.c_ai0.x) && (myself.i_ai2 == myself.c_ai0.y) && (myself.i_ai3 == myself.c_ai0.z)) {

			Say("Are you sleeping, "+myself.c_ai0.name+" ?");

			AddAttackDesire(myself.c_ai0, @AMT_MOVE_TO_TARGET, 1500);

			myself.i_ai0 = 1;		// action done and must restart for another creature/pc
		}
	}
I want when NPC attack PC if that PC not moved during 5 secs but i have some problems to save creature.x creature.y and creature.z before timer start... a = b, assign incompatible

Regards
Kirikups is offline  
Old 13.02.2006, 14:35   #2
filrip
Архивный участник
 
Join Date: May 2005
Posts: 99
Default

Convert b to int before store in a
ex :
myself.i_ai1 = FloatToInt(creature.x);

i think will work
filrip is offline  
Old 13.02.2006, 15:52   #3
Kirikups
Архивный участник
 
Join Date: Oct 2005
Posts: 175
Default

Success!!!

Tx a lot for your help :P
Kirikups is offline  
Old 13.02.2006, 16:13   #4
Kirikups
Архивный участник
 
Join Date: Oct 2005
Posts: 175
Default

Here my code:

Code:
	EventHandler SEE_CREATURE(creature)
	{
		if ((myself.c_ai0 != creature) && (Rand(100) < 50) && (DistFromMe(creature) < 400) && (DistFromMe(creature) > 50))
		{
			myself.c_ai0 = creature;

			myself.i_ai1 = FloatToInt(creature.x);
			myself.i_ai2 = FloatToInt(creature.y);
			myself.i_ai3 = FloatToInt(creature.z);

			myself.i_ai0 = 0;
			SetTimerPeriod(5);
		}
	}

	EventHandler TIMER_FIRED()
	{
		if ((myself.i_ai0 == 0) && (myself.i_ai1 == FloatToInt(myself.c_ai0.x)) && (myself.i_ai2 == FloatToInt(myself.c_ai0.y)) && (myself.i_ai3 == FloatToInt(myself.c_ai0.z))) {

			Say("Come here, "+myself.c_ai0.name+" !");

			InstantTeleport(myself.c_ai0, FloatToInt(myself.start_x + 50), FloatToInt(myself.start_y + 50), FloatToInt(myself.start_z + 0));
			myself.i_ai0 = 1;

			AddAttackDesire(myself.c_ai0, @AMT_MOVE_TO_TARGET, 1500);
		}
	}
not tested yet, maybe it can interest u
Kirikups is offline  
Old 13.02.2006, 17:09   #5
toolpunk
Архивный участник
 
Join Date: May 2005
Posts: 2,033
Default

seems nice...
as i still want to learn about ai, i'd love to know what myself.i_ai0 and myself.c_ai0 are used for...
also, why is do you check if its NOT a creature if you are going to make it one...
i'm talking about this code:
[...]if ((myself.c_ai0 != creature)[...]
myself.c_ai0 = creature;[...]
thanks in advance
toolpunk is offline  
Old 13.02.2006, 18:57   #6
Kirikups
Архивный участник
 
Join Date: Oct 2005
Posts: 175
Default

i wrote

[...]if ((myself.c_ai0 != creature)[...]
myself.c_ai0 = creature;[...]


because i suppose creature is a pointer to the pc address:

void CNPC::SeeCreature(CSharedCreatureData* spCreature)

i supposed naturally having to save it in myself.c_ai0 to be able to recall that address in the TIMER_FIRED() handler ... i didnt find any TIMER_FIRED(creature) sample in NASC samples files, and it is normal since that handler is not launched by a creature but by SetTimerPeriod function

Correct me if i am wrong
Kirikups is offline  
Old 13.02.2006, 19:21   #7
toolpunk
Архивный участник
 
Join Date: May 2005
Posts: 2,033
Default

cant correct you thats why i asked :P
well thanks... thinks i understood it now^^
toolpunk is offline  
Old 14.02.2006, 13:03   #8
Kirikups
Архивный участник
 
Join Date: Oct 2005
Posts: 175
Default

btw i tested this code with a summoned mob + setai and it doesnt work :?
Kirikups 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 21:12.