SA-MP Forums Archive
Add 1 when creating the command. - 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: Add 1 when creating the command. (/showthread.php?tid=338440)



Add 1 when creating the command. - Shockey HD - 29.04.2012

Im working on a /createhouse system, and it is going well at the moment. The house command is needing a House ID system. What im going for is that, When you type /createhouse, A variable gets added by one. For an example.

1'st House = House ID 1
2'nd House = House ID 2
3'rd House = House ID 3

And i want it continue to do such, How would i be able to do this?


Re: Add 1 when creating the command. - SuperViper - 30.04.2012

pawn Code:
new nextHouseID;

for(new i = 0; i < MAX_HOUSES; i++)
{
    if(check for house not existing)
    {
        nextHouseID = i;
        break;
    }
}
Replace the 'check for house not existing' with your code to check if house ID doesn't exist. After that, your new house ID is nextHouseID.


Re: Add 1 when creating the command. - Jack_Leslie - 30.04.2012

If you want it to start at 1, use this loop:
pawn Code:
for(new i = 1; i < MAX_HOUSES; i++)
{
    if(check for house not existing)
    {
        nextHouseID = i;
        break;
    }
}