Chance code
#1

I couldn't find it anywhere, how could you script that something happens for lets say, with 50% possibility?

Like, with probability of 50% something happens, and with the rest probability it'll fail. How did you do it?
Reply
#2

Using random().

If you were to do 'random(2)' it will return either 0 or 1, 50% chance each, so you can do something if it's 0:

pawn Code:
if(random(2) == 0)
{
    // Do something
}
If you wanted a 25% chance you can swap out the 2 for a 4. If you want a 10 percent chance a 10 and so on.
Reply
#3

Oh yeah, it was random()! Shit it was so easy, didn't remember. I just thought it was a huge mess of codes lmao. Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)