Raised This Month: $ Target: $400
 0% 

Random numbers ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 04-25-2007 , 13:40   Random numbers ?
Reply With Quote #1

How would you set up a Pseudo Random Number Generator in so...lets say when you spawn it would run through a list of random numbers...pick one then if that number is lets say < 10 it would give a player faster speed or lower gravity or a specified weapon. if someone can help me with the RNG i think i can figure out the rest of the code.
bwgrubbs1 is offline
Thaniominator
Junior Member
Join Date: Apr 2007
Old 04-25-2007 , 14:47   Re: Random numbers ?
Reply With Quote #2

Roll the dice?
Thaniominator is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 04-25-2007 , 15:15   Re: Random numbers ?
Reply With Quote #3

uhh..

random_float - Generates random floating point number from a to b
Float: random_float ( Float:a,Float:b )

random_num - Generates random integer from a to b.
random_num ( a,b )
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 04-25-2007 , 16:38   Re: Random numbers ?
Reply With Quote #4

ok..thank you, is there a way to call that number back like store it or can you just do this:

Code:
random_num(0,100) if ( get_pcvar_num(random_num) <= 5) {   //do this.... } else if ( get_pcvar_num(random_num) > 5 && get_pcvar(random_num) <= 15 ) {   //do this.... } //and so on...

Last edited by bwgrubbs1; 04-25-2007 at 16:52.
bwgrubbs1 is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 04-25-2007 , 16:50   Re: Random numbers ?
Reply With Quote #5

Code:
new rnd
rnd = random_num(0,100) /*Or rnd = random(101)*/
 
if( rnd <= 5) {
    //bla bla
}
 
else if (rnd >5 && rnd <= 15) {
    //bla bla
}
Every time when the function with random_num is called the number will be different.
__________________
Still...lovin' . Connor noob! Hello

Last edited by Alka; 04-25-2007 at 16:57.
Alka is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 04-25-2007 , 16:53   Re: Random numbers ?
Reply With Quote #6

ok...thank you +karma 4 u
bwgrubbs1 is offline
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 04-25-2007 , 17:01   Re: Random numbers ?
Reply With Quote #7

One more thing...im running into a small problem

Code:
    if( rnd <= 5)     {         set_user_footsteps(id, 0)     }       else if (rnd >5 && rnd <= 15)     {        //how would i give someone a weapon with a certain ammount of ammo ? aka give_item(id, "weapon_deagle", 7) for 7 bullets ?? and none in the clip     }
bwgrubbs1 is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 04-25-2007 , 17:07   Re: Random numbers ?
Reply With Quote #8

cs_get_user_bpammo
cs_get_weapon_ammo
cs_set_user_bpammo
cs_set_weapon_ammo

look them up in http://www.amxmodx.org/funcwiki.php
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
bwgrubbs1
Senior Member
Join Date: Sep 2006
Old 04-26-2007 , 01:35   Re: Random numbers ?
Reply With Quote #9

ok i got that working now...but for some reason i cannot set the ammo defined for the weapon...
I.E.

Code:
    new rnd     rnd = random_num(0,100)       if( rnd <= 5)     {         give_item(id, "weapon_awp")     cs_set_user_bpammo(id, CSW_AWP, 0)     cs_set_weapon_ammo(id, 3)     }   else if( rnd > 5) { set_user_footsteps(id, 0) }

FOR SOME REASON...it give you awp...if number is in range...but gives it to you with 10 bullets and none in the pack.
bwgrubbs1 is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 04-26-2007 , 20:13   Re: Random numbers ?
Reply With Quote #10

cs_set_user_bpammo(id, CSW_AWP, 30)
__________________
regalis is offline
Reply



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:35.


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