Checking if a house is vaild from a random string
#1

How would I check if the house is vaild and is made in my script, here what I am using to select a random house id
pawn Код:
new RandomHouseID = random(MAX_HOUSES);
Reply
#2

In OnGameModeInit callback, you should load the houses. Use a global variable and reset it before you load the houses. After you're done with the loading, assign the value of the last houseid + 1 to that variable.
pawn Код:
// At some callback
{
    LoadedHouses = 0;
   
    for(new h = 0; h < MAX_HOUSES; h++)
    {
        // loading...
        if( .. id does not exist .. )
        {
            LoadedHouses = h + 1;
            break;
        }
    }
    return 1;
}
Then you can simply do
pawn Код:
new RandomHouseID = random(LoadedHouses);
Reply
#3

Quote:
Originally Posted by _Zeus
Посмотреть сообщение
In OnGameModeInit callback, you should load the houses. Use a global variable and reset it before you load the houses. After you're done with the loading, assign the value of the last houseid + 1 to that variable.
pawn Код:
// At some callback
{
    LoadedHouses = 0;
   
    for(new h = 0; h < MAX_HOUSES; h++)
    {
        // loading...
        if( .. id does not exist .. )
        {
            LoadedHouses = h + 1;
            break;
        }
    }
    return 1;
}
Then you can simply do
pawn Код:
new RandomHouseID = random(LoadedHouses);
Cheers
Reply
#4

You can use while-loop and use HouseID variable to check is valid or not.

pawn Код:
new RandomHouseID = random(MAX_HOUSES);

while(HouseID[RandomHouseID] == -1) // House is not valid
{
    RandomHouseID = random(MAX_HOUSES);
}
Reply
#5

Quote:
Originally Posted by MouseBreaker
Посмотреть сообщение
You can use while-loop and use HouseID variable to check is valid or not.

pawn Код:
new RandomHouseID = random(MAX_HOUSES);

while(HouseID[RandomHouseID] == -1) // House is not valid
{
    RandomHouseID = random(MAX_HOUSES);
}
Of course, there're many ways to do something but he would still need to set all of them to -1 in the beginning of the mode

pawn Код:
for(new h = 0; h < MAX_HOUSES; h++) Houses[h][houseid] = -1; // Or however you've called it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)