AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with random bool:[id] (https://forums.alliedmods.net/showthread.php?t=93067)

dstopgunner 05-23-2009 21:50

Help with random bool:[id]
 
Im trying to give random people chainsaws to people when they spawned.
Somehow my random num's like not working becuase none of us got a chainsaw. HelpZ?

PHP Code:

public spawned(id)
{
chainsaw[id] = false
 
if(is_user_alive(id))
{
new 
rand random_num(1,2)
switch(
rand)
{
case 
1: (chainsaw[id] = true)
case 
2: (chainsaw[id] = false)
}
}
return 
PLUGIN_HANDLED



Emp` 05-23-2009 22:36

Re: Help with random bool:[id]
 
Make sure your spawn hook is post spawn (so it will detect they are alive).

Exolent[jNr] 05-23-2009 23:18

Re: Help with random bool:[id]
 
Once you have checked what Emp` said, you can make this easy code optimization:
PHP Code:

public spawned(id)
{
chainsaw[id] = false
 
if(is_user_alive(id))
{
chainsaw[id] = bool:random(2)
}



--kml-- 05-29-2009 09:59

Re: Help with random bool:[id]
 
so
is a random num is an operator?
or i can do like this
ZOMG(1,2)?

Bugsy 05-29-2009 10:07

Re: Help with random bool:[id]
 
It's not an operator, it's a native function.

random : http://www.amxmodx.org/funcwiki.php?go=func&id=41
random_float: http://www.amxmodx.org/funcwiki.php?go=func&id=285
random_num: http://www.amxmodx.org/funcwiki.php?go=func&id=286

AntiBots 05-29-2009 12:45

Re: Help with random bool:[id]
 
Someone know with random(0) return 145345 something like that.

--kml-- 05-29-2009 20:43

Re: Help with random bool:[id]
 
ooo
i c
so it is only a too b?
cannot do a b c?
or 1 , 2 , 3?

and yet are there an alternative to random num O.O

SnoW 05-30-2009 03:33

Re: Help with random bool:[id]
 
Quote:

Originally Posted by --kml-- (Post 837700)
ooo
i c
so it is only a too b?
cannot do a b c?
or 1 , 2 , 3?

and yet are there an alternative to random num O.O

If you read the link what bugsy specified, you should now that it returns a random number between the two parameters. So I don't understand what random_num(1, 2, 3) could return? If you want a random number from 1, 2, 3 you would obviously use random_num(1, 3).


All times are GMT -4. The time now is 01:25.

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