#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Hand Grenade Explode"
#define AUTHOR "OT"
#define VERSION "1.0"
#define add_user_has_nade(%0) bs_userhasnade |= (1<<((%0)-1))
#define remove_user_has_nade(%0) bs_userhasnade &= ~(1<<((%0)-1))
#define user_has_nade(%0) (bs_userhasnade & (1<<((%0)-1)))
#define OFFSET_GRENADE_PINPULL_TIME 31
#define OFFSET_WEAPON_OWNER 41
#define OFFSET_WEAPON_ID 43
#define OFFSET_PLAYER_NEXT_ATTACK 83
#define EXTRA_OFFSET_WEAPON_LINUX 4
#define EXTRA_OFFSET_PLAYER_LINUX 5
#define pev_explodetime pev_dmgtime
new const NADE_RACE[] =
{
CSW_HEGRENADE,
CSW_FLASHBANG,
CSW_SMOKEGRENADE
}
new const NADE_MODEL[][] =
{
"w_hegrenade.mdl",
"w_flashbang.mdl",
"w_smokegrenade.mdl"
}
new weapon[33]
new must_explode[33]
new Float:cuttime[33]
new pcv_cut_dmgtime
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar("gren_hand_ex_vs", VERSION, (FCVAR_SPONLY | FCVAR_SERVER))
register_event("CurWeapon", "event_active_weapon", "be", "1=1")
RegisterHam(Ham_Think, "weapon_hegrenade", "fw_think")
RegisterHam(Ham_Think, "weapon_flashbang", "fw_think")
RegisterHam(Ham_Think, "weapon_smokegrenade","fw_think")
set_task(1.0, "task_reg_setmodel")
pcv_cut_dmgtime = register_cvar("hdex_cutexplotime", "1")
}
public task_reg_setmodel()
{
// Register it after to let other plugins make the modifications
register_forward(FM_SetModel, "fw_setmodel", 1)
}
public fw_think(ent)
{
new owner = get_pdata_cbase(ent, OFFSET_WEAPON_OWNER, EXTRA_OFFSET_WEAPON_LINUX)
new Float:explode_time
pev(ent, pev_explodetime, explode_time)
if (get_pdata_float(ent, OFFSET_GRENADE_PINPULL_TIME, EXTRA_OFFSET_WEAPON_LINUX) == 0.0 && explode_time == 0.0)
{
cuttime[owner] = get_gametime() + 0.4
set_pev(ent, pev_explodetime, get_gametime() + 2.0)
}
if (get_pdata_float(ent, OFFSET_GRENADE_PINPULL_TIME, EXTRA_OFFSET_WEAPON_LINUX) > 0.0)
{
set_pev(ent, pev_explodetime, 0.0)
}
if (explode_time < get_gametime() && explode_time != 0.0)
{
new weapon_id = get_pdata_int(ent, OFFSET_WEAPON_ID, EXTRA_OFFSET_WEAPON_LINUX)
if (weapon_id == weapon[owner])
{
must_explode[owner] = weapon[owner]
client_cmd(owner, "-attack")
}
else
{
new classname[32]
pev(ent, pev_classname, classname, charsmax(classname))
engclient_cmd(owner, classname)
must_explode[owner] = weapon_id
set_pdata_float(owner, OFFSET_PLAYER_NEXT_ATTACK, 0.0, EXTRA_OFFSET_PLAYER_LINUX)
client_cmd(owner, "+attack ; wait ; -attack")
}
set_pev(ent, pev_explodetime, 0.0)
}
return HAM_IGNORED
}
public event_active_weapon(id)
{
weapon[id] = read_data(2)
return PLUGIN_CONTINUE
}
public fw_setmodel(ent, model[])
{
if (!pev_valid(ent))
{
return FMRES_IGNORED
}
new Float:gravity
pev(ent, pev_gravity, gravity)
// Not yet thrown
if (gravity == 0.0)
{
return FMRES_IGNORED
}
new owner = pev(ent, pev_owner)
if (!must_explode[owner])
{
if (!get_pcvar_num(pcv_cut_dmgtime))
return FMRES_IGNORED
for (new i=0;i<3;i++)
{
if (containi(model, NADE_MODEL[i]) != -1)
{
new Float:substract
pev(ent, pev_dmgtime, substract)
substract -= get_gametime() - cuttime[owner]
set_pev(ent, pev_dmgtime, substract)
return FMRES_IGNORED
}
}
}
for (new i=0;i<3;i++)
{
if (containi(model, NADE_MODEL[i]) != -1)
{
if (NADE_RACE[i] == must_explode[owner])
{
set_pev(ent, pev_nextthink, get_gametime() + 0.02)
set_pev(ent, pev_movetype, MOVETYPE_FOLLOW)
set_pev(ent, pev_aiment, owner)
set_pev(ent, pev_dmgtime, 0.0)
set_pev(ent, pev_flags, pev(ent, pev_flags) & FL_ONGROUND)
must_explode[owner] = 0
return FMRES_IGNORED
}
}
}
return FMRES_IGNORED
}