PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <reapi>
#pragma semicolon 1
new const szEntityName[] = "remove_me";
new const szModelRemove[] = "models/w_usp.mdl";
new const szSoundRemove[] = "weapons/c4_explode1.wav";
new const szSoundThink[] = "weapons/he_bounce-1.wav";
public plugin_precache()
{
precache_model(szModelRemove);
precache_sound(szSoundRemove);
precache_sound(szSoundThink);
}
public plugin_init()
{
register_plugin("Remove Me", "0.0.1", "metal_upa");
register_clcmd("say /tt", "CmdCreateMe");
}
public CmdCreateMe(id)
{
if(!is_user_alive(id)) return;
new ent = rg_create_entity("info_target");
if(ent <= MaxClients) return;
new Float:vecSrc[3];
get_entvar(id, var_origin, vecSrc);
set_entvar(ent, var_classname, szEntityName);
set_entvar(ent, var_movetype, MOVETYPE_TOSS);
set_entvar(ent, var_solid, SOLID_TRIGGER);
set_entvar(ent, var_owner, id);
engfunc(EngFunc_SetOrigin, ent, vecSrc);
engfunc(EngFunc_SetModel, ent, szModelRemove);
engfunc(EngFunc_SetSize, ent, Float:{0.0,0.0,0.0}, Float:{0.0,0.0,0.0});
SetThink(ent, "OnThinkRemove");
SetTouch(ent, "OnTouchRemove");
new Float:flTime = get_gametime();
set_entvar(ent, var_fuser1, flTime + 10.0); //auto remove time
set_entvar(ent, var_nextthink, flTime + 0.4);
}
public OnThinkRemove(const ent)
{
if(!is_entity(ent)) return;
//owner not connected? remove the entity
new id = get_entvar(ent, var_owner);
if(!is_user_connected(id))
{
emit_sound(ent, CHAN_WEAPON, szSoundRemove, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
RemoveEntitySafe(ent);
return;
}
//entity time has expired? remove the entity
new Float:flTime = get_gametime();
if(get_entvar(ent, var_fuser1) < flTime)
{
client_print(id, print_chat, "[DEBUG] Entity:%i time expired!", ent);
emit_sound(ent, CHAN_WEAPON, szSoundRemove, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
RemoveEntitySafe(ent);
return;
}
//entity time is active? loop the think if you want.
//set the nextthink to any value you want.
client_print(id, print_chat, "[DEBUG] OnThinkRemove(%i) Think!", ent);
emit_sound(ent, CHAN_WEAPON, szSoundThink, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
set_entvar(ent, var_nextthink, flTime + 1.0);
}
public OnTouchRemove(const ent, const id)
{
if(!is_entity(ent) || !is_user_alive(id)) return HC_CONTINUE;
//owner not connected anymore
new atk = get_entvar(ent, var_owner);
if(!is_user_connected(atk))
{
emit_sound(ent, CHAN_WEAPON, szSoundRemove, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
RemoveEntitySafe(ent);
return HC_CONTINUE;
}
//owner touch their entity? block the touch
if(id == atk) return HC_SUPERCEDE;
//someone touch owner's entity? delete the entity
client_print(id, print_chat, "[DEBUG] OnTouchRemove(%i, %i) -- BAMM entity remove!", ent, id);
emit_sound(ent, CHAN_WEAPON, szSoundRemove, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
RemoveEntitySafe(ent);
return HC_CONTINUE;
}
RemoveEntitySafe(ent)
{
SetThink(ent, "");
SetTouch(ent, "");
set_entvar(ent, var_flags, FL_KILLME);
dllfunc(DLLFunc_Think, ent);
}