SA-MP Forums Archive
Random part of array - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Random part of array (/showthread.php?tid=426595)



Random part of array - dusk - 29.03.2013

Hello,

I have this:
pawn Код:
new bool:House[4];
My goal is every once in a while, one of the Houses would become true. How can i set a random one?


Re: Random part of array - [XST]O_x - 29.03.2013

pawn Код:
House[random(4)] = false;



Re: Random part of array - zxc1 - 29.03.2013

You've got to use a timer, which inside you will set which house will be come 'true', in any part of time.


Re: Random part of array - SuperViper - 29.03.2013

pawn Код:
forward public SelectRandomHouse();

new bool: Houses[4], currentHouse;

public OnGameModeInit()
{
    SelectRandomHouse();
    SetTimer("SelectRandomHouse", 600000, 1);
    return 1;
}

public SelectRandomHouse()
{
    Houses[currentHouse] = false;
    currentHouse = random(sizeof(Houses));
    Houses[currentHouse] = true;
    return 1;
}



Re: Random part of array - dusk - 29.03.2013

Thank you all. Problem solved