random with precents?
#3

A bit shorter:
PHP код:
new PlayerLuck[playerid];  // <------- Variable that player's luck stored in.
if(random(100) < PlayerLuck[playerid])
   
//> Success (random gives a value from 0 to 9)
else
   
//> Fail (random gives a value from 10 to 99) 
"random" returns values from 0 to value-1 (checking if "random" was below 0 is useless), so with the code above it can return values from 0 to 99, and we check if the valid value is from 0 to 9 (this would be 10%).
Reply


Messages In This Thread
random with precents? - by Lirbo - 19.01.2016, 08:26
Re: random with precents? - by M4D - 19.01.2016, 08:38
Re: random with precents? - by AmigaBlizzard - 19.01.2016, 12:56
Re: random with precents? - by AbyssMorgan - 19.01.2016, 13:06

Forum Jump:


Users browsing this thread: 1 Guest(s)