Finding unused indexid - 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: Finding unused indexid (
/showthread.php?tid=665282)
Finding unused indexid -
SaiyanZ - 29.03.2019
um i still i don't know how do you find unused index id, for example
PHP Code:
//under createobject command
objects++;
objectsid[objects]=objectid;
new Float:X, Float:Y, Float:Z, str[128];
GetPlayerPos(playerid, X, Y, Z);
SpawnedObject[objects] = CreateObject(//etc etc
i take 'objects' as the objects like indexid to select it later on, what if i created 10 objects, i deleted one with object id 4, how can i find it
if you didnt get what i mean then another example
i created 5 numbers, 1 2 3 4 5 in a sequence, i deleted 3 from the sequence now how will i be able to find it
Re: Finding unused indexid -
introzen - 29.03.2019
pawn Code:
new freeObjectId;
for(new i=0; i<MAX_OBJECTS; i++) {
if(!IsValidObject(SpawnedObject[i])) {
freeObjectId = i;
break;
}
}
SpawnedObject[i] = CreateObject();
Should essentially check for the first entry in SpawnedObject array that isn't assigned a valid object, then return that as freeObjectId.
I don't know if it works and I'm sure there's a more efficient way of doing it. Haven't done this in a long time.
Re: Finding unused indexid -
SaiyanZ - 29.03.2019
Thanks and also i'll try that out, i wanted to ask another thing, how can i run a loop like backwards like i tried using
PHP Code:
for(new i =40; i>0; i--)
but i read somewhere that this wont work as condition is always true, i need something like 40 to 0
EDIT: My mistake while writing, (i was supposed to write 40) i tried using it but it doesn't seem to work
Re: Finding unused indexid -
bgedition - 29.03.2019
Quote:
Originally Posted by SaiyanZ
Thanks and also i'll try that out, i wanted to ask another thing, how can i run a loop like backwards like i tried using
PHP Code:
for(new i =0; i>0; i--)
but i read somewhere that this wont work as condition is always true, i need something like 40 to 0
|
Almost had it:
pawn Code:
for(new i = 40; i>0; i--)
EDIT: It should work. Condition is true when i is > 0. if i becomes 0 the condition is no longer true and the loop stops.