PDA

View Full Version : AI - How join SEE_CREATURE() and TIMER_FIRED() ?


Kirikups
12.02.2006, 22:24
Hello all,

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

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

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

i think will work

Kirikups
13.02.2006, 15:52
Success!!!

Tx a lot for your help :P

Kirikups
13.02.2006, 16:13
Here my 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 :)

toolpunk
13.02.2006, 17:09
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 :)

Kirikups
13.02.2006, 18:57
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 :)

toolpunk
13.02.2006, 19:21
cant correct you thats why i asked :P
well thanks... thinks i understood it now^^

Kirikups
14.02.2006, 13:03
btw i tested this code with a summoned mob + setai and it doesnt work :?