I have a problem with my code , it works almost perfectly, except instead of executing the code on only one player's ID it executes on all the ID's. I need a way to set a condition that will work with what i have and only pass the id of the player to go over the cvars set.
Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
// global shot varaible
new g_iShots;
public plugin_init()
{
register_plugin("Weapon Jam","0.1","The Specialist");
register_cvar("amx_weapon_jam","1");
register_cvar("amx_jam_ratio","100");
register_event("CurWeapon", "weapon_event", "be", "1=1", "3>0", "2!4", "2!6", "2!9", "2!25", "2!29");
register_forward(FM_PlayerPreThink, "weapon_jam");
register_forward(FM_UpdateClientData, "weapon_jam_update", 1);
}
// current weapon event
public weapon_event(id)
{
// if plugin is off end function
if(get_cvar_num("amx_weapon_jam")== 0)
{
return PLUGIN_HANDLED;
}else{
// if shots < ratio cvar increment varaible
if(g_iShots <= get_cvar_num("amx_jam_ratio"))
{
++g_iShots;
jam_sounds(id);
}
}
return PLUGIN_CONTINUE;
}
// pre-think
public weapon_jam(id )
{
// if shots == cvar execute functions
if( g_iShots == get_cvar_num("amx_jam_ratio"))
{
// show messages
set_hudmessage(255, 255, 255, -1.0, 0.33, 0, 6.0, 12.0)
show_hudmessage(id, "Weapon Jam Press Use To Clear")
// block attack button
set_pev( id, pev_button, pev(id,pev_button) & ~IN_ATTACK );
// execute clear chamber and sounds
clear_chamber(id);
}
return FMRES_HANDLED;
}
// client update data
public weapon_jam_update(id,sendweapons,cd_handle )
{
// if shots are = cvar execute functions
if( g_iShots == get_cvar_num("amx_jam_ratio"))
{
// show messages
set_hudmessage(255, 255, 255, -1.0, 0.33, 0, 6.0, 12.0)
show_hudmessage(id, "Weapon Jam Press Use To Clear")
// block weapon cd id
set_cd(cd_handle, CD_ID, 0);
// clear chamber and play sounds
clear_chamber(id);
return FMRES_HANDLED;
}
return FMRES_HANDLED;
}
public jam_sounds(id)
{
// if shots is = cvar execute function
if( g_iShots == get_cvar_num("amx_jam_ratio"))
{
// play sounds
emit_sound(id,CHAN_AUTO, "weapons/dryfire_rifle.wav", 1.0, ATTN_NORM, 0, PITCH_NORM);
}
}
public clear_chamber(id)
{
// if user presses use button execute functions
if(pev(id,pev_button) & IN_USE )
{
//re-set varaible to 0
g_iShots = 0;
// play sounds
emit_sound(id,CHAN_AUTO,"weapons/m4a1_boltpull.wav",1.0,ATTN_NORM,0,PITCH_NORM);
// show messages
set_hudmessage(255, 255, 255, -1.0, 0.3, 0, 6.0, 12.0);
show_hudmessage(id, "Chamber Clear");
// and stop functions
return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}