Hi everyone.
I am working with a smart NPC, this, can move, attack, follow player, etc.
Generally, i test my plugins in CS 1.6 new game option (not a host server, or dedicated), and npc plugin works good, but when i upload and test my npc plugin in a hosted or dedicated server, i have the next problem:
in cs 1.6 game (new game option), when i create the NPC, it follow me with run animation, and when distance between the entity and me, are near (distance: 60.0 example), this attack me.
works ok... but:
if i create the entity in a host or dedicated server (with no other plugins, updated server), the entity follow me, but the model of entity is in the respawn ent origin, and play run sequence, but how i said, the entity follow me, but the model no.
after, when the entity is close to me, the npc attack me and the attack sequence and model works good, (the model appears close to my and play attack sequence, effects, etc).
basically, the problem is that the entity follow me, but the model not (how i check this ? with a BEAMENTPOINT between entity and i, and when i shoot to the entity, this bloods).
check this image:
the boomer model, is in the respawn entity site, but you can see that the entity, is more close to my (i make TE_BEAMENTPOINT [red line] to check the current origin of entity).
now, i stop walk and when the entity is close to my, this attack me, a little screenfade effect, etc.
ending explication of the problem, here is my code (credits to dias for him npc's plugins).
PHP Code:
public fw_think(ent)
{
if(!is_valid_ent(ent))
return HAM_IGNORED
if(pev(ent, pev_iuser4) == 1)
return HAM_IGNORED
static victim
static Float:Origin[3], Float:VicOrigin[3], Float:distance
victim = FindClosesEnemy(ent)
pev(ent, pev_origin, Origin)
pev(victim, pev_origin, VicOrigin)
distance = get_distance_f(Origin, VicOrigin)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(TE_BEAMPOINTS); // 0
engfunc(EngFunc_WriteCoord, Origin[0]); //centerpoint
engfunc(EngFunc_WriteCoord, Origin[1]); //left top corner
engfunc(EngFunc_WriteCoord, Origin[2]); //horizontal height
engfunc(EngFunc_WriteCoord, VicOrigin[0]);//centerpoint
engfunc(EngFunc_WriteCoord, VicOrigin[1]);//left right corner
engfunc(EngFunc_WriteCoord, VicOrigin[2]); //horizontal height
write_short(line); //sprite to use
write_byte (1) // Start frame
write_byte (10) // Frame rate
write_byte (1) // Life
write_byte (5) // Line width
write_byte (0) // Noise
write_byte(255) // red
write_byte(0) // green
write_byte(0) // blue
write_byte(150) // brightness
write_byte(25) // scroll speed in 0.1's
message_end()
//yes, this can be optimized.
if(is_user_alive(victim))
{
if(distance <= 60.0)
{
if(!is_valid_ent(ent))
return FMRES_IGNORED
npc_turntotarget(ent, Origin, victim, VicOrigin)
set_entity_anim(ent, SEQ_ATTACK)
entity_set_float(ent, EV_FL_nextthink, get_gametime() + 1.0)
}
else /*this is the code when entity start follow player and play run sequence (if is in water, swim, but i dont test it)*/
{
if(get_entity_flags(ent) & FL_INWATER)
{
if(pev(ent, pev_sequence) != SEQ_SWIM)
set_entity_anim(ent, SEQ_SWIM)
}
else
{
if(pev(ent, pev_sequence) != SEQ_RUN)
set_entity_anim(ent, SEQ_RUN)
}
npc_turntotarget(ent, Origin, victim, VicOrigin)
hook_ent(ent, victim, 100.0)
entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.1)
}
}
else
{
if(get_entity_flags(ent) & FL_INWATER)
{
if(pev(ent, pev_sequence) != SEQ_TREADWATER)
{
set_entity_anim(ent, SEQ_TREADWATER)
}
}
else
{
if(pev(ent, pev_sequence) != SEQ_IDLE)
{
set_entity_anim(ent, SEQ_IDLE)
}
}
entity_set_float(ent, EV_FL_nextthink, get_gametime() + 1.0)
}
return HAM_HANDLED
}
/* credits to dias*/
public npc_turntotarget(ent, Float:Ent_Origin[3], target, Float:Vic_Origin[3])
{
if(!is_user_connected(target) || !pev_valid(ent))
return;
new Float:newAngle[3]
entity_get_vector(ent, EV_VEC_angles, newAngle)
new Float:x = Vic_Origin[0] - Ent_Origin[0]
new Float:z = Vic_Origin[1] - Ent_Origin[1]
new Float:radians = floatatan(z/x, radian)
newAngle[1] = radians * (180 / 3.14)
if (Vic_Origin[0] < Ent_Origin[0])
newAngle[1] -= 180.0
entity_set_vector(ent, EV_VEC_angles, newAngle)
}
public hook_ent(ent, victim, Float:speed)
{
static Float:fl_Velocity[3]
static Float:VicOrigin[3], Float:EntOrigin[3]
pev(ent, pev_origin, EntOrigin)
pev(victim, pev_origin, VicOrigin)
static Float:distance_f
distance_f = get_distance_f(EntOrigin, VicOrigin)
if (distance_f > 60.0)
{
new Float:fl_Time = distance_f / speed
fl_Velocity[0] = (VicOrigin[0] - EntOrigin[0]) / fl_Time
fl_Velocity[1] = (VicOrigin[1] - EntOrigin[1]) / fl_Time
fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time
} else
{
fl_Velocity[0] = 0.0
fl_Velocity[1] = 0.0
fl_Velocity[2] = 0.0
}
entity_set_vector(ent, EV_VEC_velocity, fl_Velocity)
}
stock set_entity_anim(ent, anim)
{
entity_set_float(ent, EV_FL_animtime, get_gametime())
entity_set_float(ent, EV_FL_framerate, 1.0)
entity_set_int(ent, EV_INT_sequence, anim)
}
if, i remove this code:
PHP Code:
//if(pev(ent, pev_sequence) != SEQ_RUN)
set_entity_anim(ent, SEQ_RUN)
the model and entity follow me, but the run sequence play and play o faster (0.1 secs, check set_entity_anim stock), like this:
if i edit the entity think time (0.1 to 1.0), the sequence play correctly, but the entity run bad, not realistic.
i try a lot things, make a fix with variable, with task, edit framerate and animtime, use other stocks, and more, but i don't get good results, sorry for the long explication, and any question only ask me.
PD: i use engine and fakemeta, later i will edit the plugin, now i'm testing because i get weird errors...
Best regards, and sorry for my bad and basic english.
__________________