![]() |
|
|
|
|
#1 |
|
Архивный участник
Join Date: Oct 2005
Posts: 175
|
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
}
}
Regards
|
|
|
|
|
#2 |
|
Архивный участник
Join Date: May 2005
Posts: 99
|
Convert b to int before store in a
ex : myself.i_ai1 = FloatToInt(creature.x); i think will work |
|
|
|
|
#3 |
|
Архивный участник
Join Date: Oct 2005
Posts: 175
|
Success!!!
Tx a lot for your help :P |
|
|
|
|
#4 |
|
Архивный участник
Join Date: Oct 2005
Posts: 175
|
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);
}
}
|
|
|
|
|
#5 |
|
Архивный участник
Join Date: May 2005
Posts: 2,033
|
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
|
|
|
|
|
#6 |
|
Архивный участник
Join Date: Oct 2005
Posts: 175
|
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
|
|
|
|
|
#7 |
|
Архивный участник
Join Date: May 2005
Posts: 2,033
|
cant correct you thats why i asked :P
well thanks... thinks i understood it now^^ |
|
|
|
|
#8 |
|
Архивный участник
Join Date: Oct 2005
Posts: 175
|
btw i tested this code with a summoned mob + setai and it doesnt work :?
|
|
|
|
|