Object list & deleting
#1

^^^^^^^^
Reply
#2

Bump
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)