Hi , I saw some posts about this to try to do it by myself, but I can't get it to work, I don't know what I'm doing wrong
What I want to do is that if someone is near the entity, they "activate" and apply what I put
PHP Code:
public doggy_create(id, aimvec[3])
{
new entity
while ((entity = find_ent_by_class(entity, "Doggy")) > 0) {
entity_set_int(entity, EV_INT_flags, FL_KILLME)
entity_set_int(entity, EV_INT_effects, EF_NODRAW)
entity_set_int(entity, EV_INT_solid, SOLID_NOT)
}
new Float:vOrigin[3]
vOrigin[0] += aimvec[0]
vOrigin[1] += aimvec[1]
vOrigin[2] += aimvec[2] + 7
new Doggy = create_entity("info_target")
entity_set_string(Doggy, EV_SZ_classname, "Doggy")
entity_set_model(Doggy, "models/shmod/shacobox.mdl")
entity_set_size(Doggy, Float:{-2.5, -2.5, -1.5}, Float:{2.5, 2.5, 1.5})
entity_set_edict(Doggy, EV_ENT_owner, id)
entity_set_int(Doggy, EV_INT_solid, SOLID_TRIGGER)
entity_set_int(Doggy, EV_INT_movetype, MOVETYPE_FLY)
entity_set_vector(Doggy, EV_VEC_origin, vOrigin)
set_task(1.0, "find_target", Doggy, _, _, "b")
I tried these two ways, and neither worked for me, where "Doggy" is the entity above, and target would be an enemy player
PHP Code:
public find_target(Doggy)
{
static id;
new Float:rOrigin[3]
id = entity_get_edict(Doggy, EV_ENT_owner);
entity_get_vector(Doggy, EV_VEC_origin, rOrigin);
new target = find_ent_in_sphere(Doggy, rOrigin, get_pcvar_float(gPcvarRadius) )
if(is_user_alive(target) && cs_get_user_team(target) != cs_get_user_team(id) ) {
sh_set_stun(target, get_pcvar_float(gPcvarStun), 1.0); //its only a stun
doggy_teleport(id);
remove_entity(Doggy);
}
}
PHP Code:
public find_target(Doggy)
{
new Float:origin[3] = { 0.0, 0.0, 0.0 } // Origin to search from, could be a player origin or something
new Float:radius = get_pcvar_float(gPcvarRadius) // Size of the sphere to search in
while((Doggy = find_ent_in_sphere(Doggy, origin, radius)) > 0) {
static id;
id = entity_get_edict(Doggy, EV_ENT_owner);
new classname[32], target
entity_get_string(target, EV_SZ_classname, classname, 31)
if ( equal(classname, "Player") ) {
new Float:entityOrigin[3]
entity_set_vector(target, EV_VEC_origin, entityOrigin)
new Float:distance = vector_distance( origin, entityOrigin )
if(is_user_alive(id) && cs_get_user_team(id) != cs_get_user_team(target) ) {
if( distance < get_pcvar_float(gPcvarRadius) ) {
sh_set_stun(target, get_pcvar_float(gPcvarStun), 1.0); //its only a stun
doggy_teleport(id);
remove_entity(Doggy);
}
}
}
}
}