30.06.2013, 11:52
My suggestion would be create a function which returns the next unused ID. In this case you need to add a new boolean in your enum.
This is the function which would return the next unused ID. You will need no global arrays which store the ID anymore using this method. This method is also a better way for this situation, since you MIGHT make a mistake somewhere in your script with these
or
So basically heres the function:
And make sure when you create a new door:
And do the opposite when removing the door.
Hope this helps.
EDIT: Theres also one improvement for making it more "automatic". Instead of creating a new boolean in the enum and switching its value to true/false and checking it to return the next ID, you simply can check the doors position. If the X, Y, Z are equal to 0.0 then its probably not created which means the ID is unused. Heres an example:
pawn Код:
bool: dUsed
pawn Код:
idx--;
pawn Код:
idx++;
pawn Код:
GetUnusedDoorID()
{
for (new i = 0; i < MAX_DOOR; i++) {
if (DoorInfo[i][dUsed]) continue;
return i;
}
return MAX_DOOR;
}
pawn Код:
DoorInfo[id][dUsed] = true;
Hope this helps.
EDIT: Theres also one improvement for making it more "automatic". Instead of creating a new boolean in the enum and switching its value to true/false and checking it to return the next ID, you simply can check the doors position. If the X, Y, Z are equal to 0.0 then its probably not created which means the ID is unused. Heres an example:
pawn Код:
GetUnusedDoorID()
{
for (new i = 0; i < MAX_DOOR; i++) {
if (DoorInfo[i][dX] == 0.0 && DoorInfo[i][dY] == 0.0 && DoorInfo[i][dZ] == 0.0) {
return i;
}
}
return MAX_DOOR;
}