AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Passing A Single ID (https://forums.alliedmods.net/showthread.php?t=46908)

The Specialist 11-05-2006 04:54

Passing A Single ID
 
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; }
Thank You For Your Time :grrr:

schnitzelmaker 11-05-2006 07:59

Re: Passing A Single ID
 
you need to change
new g_iShots; -> new g_iShots[33];

and all other : g_iShots -> g_iShots[id]

The Specialist 11-05-2006 13:53

Re: Passing A Single ID
 
hmm , Im getting some errors and i wont be able to declare my varaibles glaobalyif it has [id] at the end . could you show me an example of what you would do with my code that compiles please , thank you :oops:

stupok 11-05-2006 13:59

Re: Passing A Single ID
 
Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> // global shot varaible new  g_iShots[33]; 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[id] <= get_cvar_num("amx_jam_ratio"))         {             ++g_iShots[id];             jam_sounds(id);         }     }     return PLUGIN_CONTINUE; } // pre-think public weapon_jam(id ) {       // if shots == cvar execute functions         if( g_iShots[id]  == 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[id] == 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[id] == 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[id] = 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; }

The Specialist 11-05-2006 15:10

Re: Passing A Single ID
 
thanks it worked , all i did was forgot to index it ++karma:grrr:


All times are GMT -4. The time now is 04:56.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.