AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random numbers ? (https://forums.alliedmods.net/showthread.php?t=54432)

bwgrubbs1 04-25-2007 13:40

Random numbers ?
 
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.

Thaniominator 04-25-2007 14:47

Re: Random numbers ?
 
Roll the dice?

Nican 04-25-2007 15:15

Re: Random numbers ?
 
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 )

bwgrubbs1 04-25-2007 16:38

Re: Random numbers ?
 
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...

Alka 04-25-2007 16:50

Re: Random numbers ?
 
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.

bwgrubbs1 04-25-2007 16:53

Re: Random numbers ?
 
ok...thank you +karma 4 u

bwgrubbs1 04-25-2007 17:01

Re: Random numbers ?
 
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     }

Nican 04-25-2007 17:07

Re: Random numbers ?
 
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

bwgrubbs1 04-26-2007 01:35

Re: Random numbers ?
 
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.

regalis 04-26-2007 20:13

Re: Random numbers ?
 
cs_set_user_bpammo(id, CSW_AWP, 30)


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

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