30.04.2013, 05:19
You need some kind of global object pool for example....
Now when you create an object it will return the array index of the created object something like...
So to reference the objectid you would use...
So once your get your object data array set up correctly deleting all objects is a breeze.
Edit - Some more updates my bad.
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;
}
pawn Код:
PlayerObject[playerid] = AddObject(1334, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
pawn Код:
Objects[PlayerObject[playerid]][ObjectID]
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;
}