Raised This Month: $ Target: $400
 0% 

Random Numbers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
The Specialist
BANNED
Join Date: Nov 2006
Old 11-11-2006 , 20:27   Random Numbers
Reply With Quote #1

Ok for my "weapon Jams" plugin im trying to make a random weapon jam function . but what I have seems to be crashing my server . any ideas whats wrong with this function here?
Code:
// Random number generator public random_jam_gen() {  // if random cvars is 0 (off) end function    if(get_pcvar_num(g_iRandom)==0)  {   return PLUGIN_HANDLED;  }else{   // else ratio == a random number between random cvar and ratio cvar     g_iRatio =  random_num(get_pcvar_num(g_iRandom),get_pcvar_num(g_iRatio));  }  return PLUGIN_HANDLED; }
Thanks
The Specialist is offline
Send a message via AIM to The Specialist
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 11-11-2006 , 20:42   Re: Random Numbers
Reply With Quote #2

Everything look fine but I don't know why you did that above. Your just putting more use code into your plugin that you really don't need too. Checking if it the cvar is zero and returning. When you can do like below and remove unnecessary code.

I suggest you try loading up the AMX Mod X Bin Logger. It will tell you the exact line it crashed on. It a useful tool when debugging stuff too

Code:
// Random number generator public random_jam_gen() {     // if random cvars is 0 (off) end function         if(get_pcvar_num(g_iRandom))     {         g_iRatio =  random_num(get_pcvar_num(g_iRandom), get_pcvar_num(g_iRatio));     }     return PLUGIN_HANDLED; }
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
The Specialist
BANNED
Join Date: Nov 2006
Old 11-11-2006 , 20:59   Re: Random Numbers
Reply With Quote #3

well the idea was that if the random cvars is 0 , which is the default , then not to run that function at all . other wise it will generate a random number between 0 and 200 the other cvar. so first it checks to see if there using the random function cvar , if they are and the number is not 0 , then it will generate a number. i found the problem that made it crash .
Code:
// Random number generator public random_jam_gen() {  // if random cvars is 0 (off) end function    if(get_pcvar_num(g_iRandom)==0)  {   return PLUGIN_HANDLED;  }else{   // else ratio == a random number between random cvar and ratio cvar     g_iRatio =  random_num(get_pcvar_num(g_iRandom),get_pcvar_num(g_iRatio));  }  return PLUGIN_HANDLED; }

using only 1 = sign (assignemnt) made it crash , but its still not generating a random number any ideas ???
The Specialist is offline
Send a message via AIM to The Specialist
k007
BANNED
Join Date: Mar 2006
Location: bacon?
Old 11-11-2006 , 21:16   Re: Random Numbers
Reply With Quote #4

try this and tell me
Code:
// Random number generator public random_jam_gen() {  if(!get_pcvar_num(g_iRandom))   return PLUGIN_HANDLED;    g_iRatio =  random_float(get_pcvar_float(g_iRandom),get_pcvar_float(g_iRatio));    return PLUGIN_HANDLED; }
k007 is offline
Send a message via MSN to k007
k007
BANNED
Join Date: Mar 2006
Location: bacon?
Old 11-11-2006 , 21:18   Re: Random Numbers
Reply With Quote #5

i didn't mean to bump but when u try editing a post with a small tags it will goes screwed up..anyways thats not the point if that didn't work try switchin from random_float to random_num and leaving the pcvars on floarts and then try doing the oppiste
k007 is offline
Send a message via MSN to k007
The Specialist
BANNED
Join Date: Nov 2006
Old 11-11-2006 , 21:46   Re: Random Numbers
Reply With Quote #6

yes i know the psots are very weird when you try to edit it ends up a very weird code . lol . np . but if the cvars are both integers why try them as flaots ? here let me show my whole code LOL
Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> // global shot varaible new g_iShots[33]; new g_iRatio; new weapon; new ammo; new g_iRandom; public plugin_init() {  register_plugin("Weapon Jam","0.5","The Specialist");  register_cvar("amx_weapon_jam","1");  g_iRatio = register_cvar("amx_jam_ratio","200");  g_iRandom = register_cvar("amx_random_jam","0");  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_pcvar_num(g_iRatio))   {    ++g_iShots[id];    random_jam_gen();    jam_sounds(id);    client_print(id,print_chat,"THe shots fired is %i",g_iShots[id]);   }  }  return PLUGIN_CONTINUE; } // pre-think public weapon_jam(id ) {  // if shots == cvar execute functions    if( g_iShots[id]  >= get_pcvar_num(g_iRatio))  {   // get the currently held weapon and jam that weapon only     if(get_user_weapon(id,weapon ,ammo)== weapon)   {    // 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);   }else{    return PLUGIN_HANDLED;   }  }  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_pcvar_num(g_iRatio))  {   // get the currently held weapon and jam that weapon only     if(get_user_weapon(id,weapon ,ammo)== weapon)   {        // 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;   }else{    return PLUGIN_HANDLED;   }  }  return FMRES_HANDLED; } public jam_sounds(id) {  // if shots is = cvar execute function    if( g_iShots [id]>= get_pcvar_num(g_iRatio))  {   // 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 or user is bot end functions    if(pev(id,pev_button) &  IN_USE   || is_user_bot(id)==1)  {     //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; } // Random number generator public random_jam_gen() {  // if random cvars is 0 (off) end function    if(get_pcvar_num(g_iRandom)==0)  {   return PLUGIN_HANDLED;  }else{   // else ratio == a random number between random cvar and ratio cvar     g_iRatio ==  random_num(get_pcvar_num(g_iRandom),get_pcvar_num(g_iRatio));  }  return PLUGIN_HANDLED; }
thanks again guys
The Specialist is offline
Send a message via AIM to The Specialist
jim_yang
Veteran Member
Join Date: Aug 2006
Old 11-11-2006 , 22:35   Re: Random Numbers
Reply With Quote #7

g_iRatio == random_num(get_pcvar_num(g_iRandom),get_pcvar _num(g_iRatio));

to

g_iRatio = random_num(get_pcvar_num(g_iRandom),get_pcvar _num(g_iRatio));
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 11-11-2006 , 22:38   Re: Random Numbers
Reply With Quote #8

also when you check a value if equals zero. you don't need to "if(a==0)" just"if(!a)"
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>

Last edited by jim_yang; 11-12-2006 at 00:26.
jim_yang is offline
The Specialist
BANNED
Join Date: Nov 2006
Old 11-11-2006 , 23:50   Re: Random Numbers
Reply With Quote #9

no that was the first way i did it . with 2 == instead of 1 . and it crashed my server . then i took it out and 2 worked but didnt generate a radnom number
The Specialist is offline
Send a message via AIM to The Specialist
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 11-12-2006 , 00:13   Re: Random Numbers
Reply With Quote #10

It's stupid that you're not following teame06's advice. While it doesn't make too much of a performance difference, logic would dictate you do it the way teame06 advised. If nothing else, it looks a hell of a lot cleaner his way.
__________________
Brad is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:49.


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