#include < amxmodx >
#include < reapi >
#define TASK_DECOY 5765485768
new modelindex;
new const GRENADE_VIEW_MODEL[] = "models/v_decoy.mdl";
new const GRENADE_PLAYER_MODEL[] = "models/p_decoy.mdl";
new const GRENADE_WORLD_MODEL[] = "models/w_decoy.mdl";
new const ITEM_CLASSNAME[] = "weapon_smokegrenade";
public plugin_init()
{
RegisterHookChain(RG_ThrowSmokeGrenade, "CBasePlayer_ThrowGrenade", true);
RegisterHookChain(RG_CGrenade_ExplodeSmokeGrenade, "CBasePlayer_ExplodeSmokeGrenade_Post", false);
RegisterHookChain(RG_CGrenade_ExplodeSmokeGrenade, "CBasePlayer_ExplodeSmokeGrenade_Pre", true);
RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy, "CBasePlayerWeapon_DefaultDeploy_Pre", false);
}
public plugin_precache() {
precache_model(GRENADE_VIEW_MODEL);
precache_model(GRENADE_PLAYER_MODEL);
modelindex = precache_model(GRENADE_WORLD_MODEL);
}
public CBasePlayerWeapon_DefaultDeploy_Pre(const item, const szViewModel[], const szWeaponModel[], const iAnim, const szAnimExt[], const skiplocal) {
if (FClassnameIs(item, ITEM_CLASSNAME)) {
SetHookChainArg(2, ATYPE_STRING, GRENADE_VIEW_MODEL);
SetHookChainArg(3, ATYPE_STRING, GRENADE_PLAYER_MODEL);
}
}
public CBasePlayer_ThrowGrenade(iEnt)
{
new iEnt = GetHookChainReturn(ATYPE_INTEGER);
set_entvar(iEnt, var_modelindex, modelindex);
set_entvar(iEnt, var_model, GRENADE_WORLD_MODEL);
}
public CBasePlayer_ExplodeSmokeGrenade_Post(pId)
{
SetHookChainReturn(ATYPE_INTEGER, false);
return HC_SUPERCEDE;
}
public CBasePlayer_ExplodeSmokeGrenade_Pre(iEnt)
{
new pId = get_entvar(iEnt, var_owner)
new Date[2];
Date[0] = iEnt;
Date[1] = pId;
SetThink(iEnt, "Time", Date, sizeof(Date));
set_entvar( iEnt, var_nextthink, get_gametime( ) + 1.0);
set_task(10.0, "remove_ent", TASK_DECOY + iEnt);
}
public Time(iEnt)
{
new Float:Origin[3];
get_entvar(iEnt, var_origin, Origin);
spark(Origin);
set_entvar( iEnt, var_nextthink, get_gametime( ) + random_float(1.0, 3.0));
}
public remove_ent(iEnt)
{
iEnt -= TASK_DECOY;
if(is_entity(iEnt))
{
set_entvar( iEnt, var_flags, FL_KILLME );
set_entvar( iEnt, var_nextthink, get_gametime( ) + 0.1);
}
}
public spark(Float:vecOrigin[3])
{
message_begin(MSG_BROADCAST ,SVC_TEMPENTITY);
write_byte(TE_SPARKS);
write_coord(floatround(vecOrigin[0]));
write_coord(floatround(vecOrigin[1]));
write_coord(floatround(vecOrigin[2]));
message_end();
}