PDA

View Full Version : Pop grenade


EFFx
01-10-2017, 22:00
Is possible make a plugin that allow players to use pop grenade like in CSGO?
If someone don't know whats this, i'll explain:

When someone use the left mouse for throw a grenade, it will fall far away.
When someone use the right mouse for throw a grenade, it will fall close to you.
When someone use both click for throw a grenade,it will fall a little further than the right button.

I just want to know how set the animation for throw the grenade.

EFFx
01-10-2017, 22:45
Information update:

Thats what I have on this moment:


#include <amxmodx>
#include <fakemeta>
#include <engine>

#define PLUGIN "Nade Velocity"
#define VERSION "1.0"
#define AUTHOR "hlstriker"

new const Grenades[] =
{
"models/w_hegrenade.mdl",
"models/w_flashbang.mdl",
"models/w_smokegrenade.mdl"
}

enum ClickTypes
{
Left,
Right,
Both
}

new ClickTypes:UserClickTypes[33]

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)

register_forward(FM_SetModel, "fwd_SetModel")
}

public client_PreThink(id)
{
new Button = get_user_button(id)

if(Button & IN_ATTACK)
{
UserClickTypes[id] = Left
}
else if(Button & IN_ATTACK2)
{
UserClickTypes[id] = Right
}
else if((Button & IN_ATTACK) && (Button & IN_ATTACK2))
{
UserClickTypes[id] = Both
}
}

public fwd_SetModel(iEnt, const szModel[])
{
new bool:isGrenade

for(new i;i < sizeof Grenades;i++)
{
if(equal(szModel, Grenades[i]))
{
isGrenade = true
}
}
if(isGrenade)
{
new id = pev(iEnt,pev_owner)

static Float:flVelocity[3], Float:flGravity[3]

pev(iEnt, pev_velocity, flVelocity)
pev(iEnt, pev_gravity, flGravity)

switch(UserClickTypes[id])
{
case Left:
{
flVelocity[0] *= 1.0
flVelocity[1] *= 1.0
flVelocity[2] *= 1.0

flGravity[0] *= 1.0
flGravity[1] *= 1.0
flGravity[2] *= 1.0
}
case Right:
{
flVelocity[0] *= 0.5
flVelocity[1] *= 0.5
flVelocity[2] *= 0.5

flGravity[0] *= 1.5
flGravity[1] *= 1.5
flGravity[2] *= 1.5
}
case Both:
{
flVelocity[0] *= 0.7
flVelocity[1] *= 0.7
flVelocity[2] *= 0.7

flGravity[0] *= 1.5
flGravity[1] *= 1.5
flGravity[2] *= 1.5
}
}
set_pev(iEnt, pev_velocity, flVelocity)
set_pev(iEnt, pev_gravity, flGravity)
}
}

The format at setModel is working, I need just know how can I set the animation when the player is pressing the right button, and makes the grenade throw.

HamletEagle
01-11-2017, 10:03
Don't use PreThink for detecting a button.


#include <amxmodx>
#include <hamsandwich>
#include <csx>
#include <fakemeta>
#include <xs>

enum
{
regular,
slower,
medium
}

const m_pPlayer = 41
const XoCGrenade = 4

new const GrenadeClassNames[][] =
{
"weapon_flashbang",
"weapon_hegrenade",
"weapon_smokegrenade"
}

new const Float:VelocityMultiplier[] =
{
1.0,
0.5,
0.7
}

new HandleThrowType[33]

public plugin_init()
{
for(new i; i < sizeof GrenadeClassNames; i++)
{
RegisterHam(Ham_Weapon_SecondaryAttack, GrenadeClassNames[i], "CBasePlayerWpn_SecondaryAttack", false)
}
}

public CBasePlayerWpn_SecondaryAttack(const grenadeEntity)
{
if(pev_valid(grenadeEntity))
{
new id = get_pdata_cbase(grenadeEntity, m_pPlayer, XoCGrenade)
new buttons = pev(id, pev_button)

if(buttons & IN_ATTACK)
{
HandleThrowType[id] = medium
}
else
{
HandleThrowType[id] = slower
}

ExecuteHamB(Ham_Weapon_PrimaryAttack, grenadeEntity)
}
}

public grenade_throw(id, grenadeEntity, grenadeWeaponIndex)
{
if(pev_valid(grenadeEntity))
{
new Float:grenadeVelocity[3]
pev(grenadeEntity, pev_velocity, grenadeVelocity)

new Float:multiplier = VelocityMultiplier[HandleThrowType[id]]
xs_vec_mul_scalar(grenadeVelocity, multiplier, grenadeVelocity)
set_pev(grenadeEntity, pev_velocity, grenadeVelocity)

HandleThrowType[id] = regular
}
}

EFFx
01-11-2017, 12:24
Thank you. Its working perfect.