Object list & deleting - 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: Object list & deleting (
/showthread.php?tid=433769)
Object list & deleting -
Ananisiki - 28.04.2013
^^^^^^^^
Re: Object list & deleting -
Ananisiki - 30.04.2013
Bump
Re: Object list & deleting -
Pottus - 30.04.2013
You need some kind of global object pool for example....
pawn Код:
#define MAX_DYN_OBJECTS 1000
enum ObjectInfo {
ObjectID,
Float:ox,
Float:oy,
Float:oz,
Float:rx,
Float:ry,
Float:rz
}
new Objects[MAX_DYN_OBJECTS][ObjectInfo];
new PlayerObject[MAX_PLAYERS] = { INVALID_OBJECT_ID, ...};
// Make sure you initialize the objectids
public OnFilterScriptInit()
{
for(new = 0; i < MAX_DYN_OBJECTS; i++) { Objects[i][ObjectID] = INVALID_OBJECT_ID; }
}
AddObject(oid, Float:ox, Float:oy, Float:oz, Float:rx, Float:ry, Float:rz)
{
for(new i = 0; i < MAX_DYN_OBJECTS; i++)
{
if(Objects[i][ObjectID] == INVALID_OBJECT_ID)
{
Objects[i][ObjectID] = CreateDynamicObject(oid, ox, oy, oz, rx, ry, rz);
return i;
}
}
return INVALID_OBJECT_ID;
}
RemoveObject(oindex)
{
if(Objects[oindex][ObjectID] != INVALID_OBJECT_ID)
{
DestroyDynamicObject(Objects[oindex][ObjectID]);
Objects[oindex][ObjectID] = INVALID_OBJECT_ID;
return 1;
}
return 0;
}
Now when you create an object it will return the array index of the created object something like...
pawn Код:
PlayerObject[playerid] = AddObject(1334, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
So to reference the objectid you would use...
pawn Код:
Objects[PlayerObject[playerid]][ObjectID]
So once your get your object data array set up correctly deleting all objects is a breeze.
pawn Код:
DeleteAllObjects()
{
new deletecount;
for(new i = 0; i < MAX_DYN_OBJECTS; i++)
{
if(Objects[i][ObjectID] == INVALID_OBJECT_ID) continue;
DestroyDynamicObject(Objects[i][ObjectID]);
Objects[i][ObjectID] = INVALID_OBJECT_ID;
deletecount++;
}
for(new i = 0; i < MAX_PLAYERS; i++) { PlayerObject[i] = INVALID_OBJECT_ID; }
if(deletecount) return 1;
return 0;
}
Edit - Some more updates my bad.