#include <amxmodx>
#include <hamsandwich>
#include <reapi>
#include <reapi>
enum {
HEGRENADE_IDLE,
HEGRENADE_PULLPIN,
HEGRENADE_THROW,
HEGRENADE_DRAW,
};
enum {
FLASHBANG_IDLE,
FLASHBANG_PULLPIN,
FLASHBANG_THROW,
FLASHBANG_DRAW,
};
enum {
SMOKEGRENADE_IDLE,
SMOKEGRENADE_PINPULL,
SMOKEGRENADE_THROW,
SMOKEGRENADE_DRAW,
};
new MsgBarTime;
new Float:Multiplier;
public plugin_init() {
register_plugin("Grenade Throw Multiplier", "0.4.0", "F@nt0M");
new const WeaponIdType:GRENADES[] = {
WEAPON_HEGRENADE,
WEAPON_FLASHBANG,
WEAPON_SMOKEGRENADE
};
for (new i = 0, wname[32]; i < sizeof GRENADES; i++) {
rg_get_weapon_info(GRENADES[i], WI_NAME, wname, charsmax(wname));
RegisterHam(Ham_Weapon_PrimaryAttack, wname, "Weapon_PrimaryAttack_Pre", false);
RegisterHam(Ham_Weapon_SecondaryAttack, wname, "Weapon_SecondaryAttack_Pre", false);
RegisterHam(Ham_Item_Holster, wname, "Item_Holster_Pre", false);
}
RegisterHookChain(RG_CBasePlayer_ThrowGrenade, "CBasePlayer_ThrowGrenade_Post", true);
MsgBarTime = get_user_msgid("BarTime");
bind_pcvar_float(create_cvar("gtm_multiplier", "0.3", .has_min = true, .min_val = 0.0), Multiplier);
}
public Weapon_PrimaryAttack_Pre(const weapon) {
if (get_member(weapon, m_flStartThrow) > 0.0) {
return HAM_IGNORED;
}
new player = get_member(weapon, m_pPlayer);
if (get_member(player, m_rgAmmo, get_member(weapon, m_Weapon_iPrimaryAmmoType)) <= 0) {
return HAM_IGNORED;
}
set_member(weapon, m_Weapon_iFamasShotsFired, 0);
return HAM_IGNORED;
}
public Weapon_SecondaryAttack_Pre(const weapon) {
if (get_member(weapon, m_flStartThrow) > 0.0) {
return HAM_IGNORED;
}
new player = get_member(weapon, m_pPlayer);
if (get_member(player, m_bOwnsShield)) {
return HAM_IGNORED;
}
if (get_member(player, m_rgAmmo, get_member(weapon, m_Weapon_iPrimaryAmmoType)) <= 0) {
return HAM_IGNORED;
}
set_member(weapon, m_flStartThrow, get_gametime());
set_member(weapon, m_flReleaseThrow, 0.0);
new anim;
switch (get_member(weapon, m_iId)) {
case WEAPON_HEGRENADE: {
anim = HEGRENADE_PULLPIN;
}
case WEAPON_FLASHBANG: {
anim = FLASHBANG_PULLPIN;
}
case WEAPON_SMOKEGRENADE: {
anim = SMOKEGRENADE_PINPULL;
}
}
ExecuteHamB(Ham_CS_Weapon_SendWeaponAnim, weapon, anim, false);
set_member(weapon, m_Weapon_flTimeWeaponIdle, 0.01);
set_member(weapon, m_Weapon_iFamasShotsFired, 1);
send_bartime(player, 1);
return HAM_IGNORED;
}
public Item_Holster_Pre(const weapon) {
if (!get_member(weapon, m_flStartThrow)) {
return HAM_IGNORED;
}
new player = get_member(weapon, m_pPlayer);
if (!is_user_connected(player)) {
return HAM_IGNORED;
}
send_bartime(player, 0);
return HAM_IGNORED;
}
public CBasePlayer_ThrowGrenade_Post(const player, const weapon, const Float:vecSrc[3], const Float:vecThrow[3]) {
if (!get_member(player, m_bOwnsShield)) {
set_member(weapon, m_Weapon_flNextSecondaryAttack, 0.5);
}
if (!get_member(weapon, m_Weapon_iFamasShotsFired)) {
return HC_CONTINUE;
}
send_bartime(player, 0);
new grenade = GetHookChainReturn(ATYPE_INTEGER);
if (is_nullent(grenade)) {
return HC_CONTINUE;
}
new Float:multiplier = floatclamp(Float:get_member(weapon, m_flReleaseThrow) - Float:get_member(weapon, m_flStartThrow), 0.1, 1.0) + Multiplier;
new Float:velocity[3];
velocity[0] = vecThrow[0] * multiplier;
velocity[1] = vecThrow[1] * multiplier;
velocity[2] = vecThrow[2];
set_entvar(grenade, var_velocity, velocity);
return HC_CONTINUE;
}[/SPOILER]
send_bartime(const player, const time) {
message_begin(MSG_ONE_UNRELIABLE, MsgBarTime, .player=player);
write_short(time);
message_end();
}