SA-MP Forums Archive
Checking if a house is vaild from a random string - 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: Checking if a house is vaild from a random string (/showthread.php?tid=441058)



Checking if a house is vaild from a random string - AccountName - 01.06.2013

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);



Re: Checking if a house is vaild from a random string - Konstantinos - 01.06.2013

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);



Re: Checking if a house is vaild from a random string - AccountName - 01.06.2013

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


AW: Checking if a house is vaild from a random string - Skimmer - 01.06.2013

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);
}



Re: AW: Checking if a house is vaild from a random string - Konstantinos - 01.06.2013

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!