Random part of array
#1

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?
Reply
#2

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

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

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;
}
Reply
#5

Thank you all. Problem solved
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)