08.05.2017, 13:53
(
Last edited by andrew2695; 09/05/2017 at 12:25 AM.
)
Solved, thank you!
enum pData { pickupsCreated, pickupsIDBounds[2] // i'd suggest to set default values for both cells to -1 so [pickupsIDBounds] = {-1, -1} }; // just be sure to reset this data on player connect/disconnect, or use PVars (which I don't recommend if you are obtaining/setting data very frequently)
new pid = CreateDynamicPickup(...); // set EXTRA_ID to our player's id so we know that he created it Streamer_SetIntData(STREAMER_TYPE_PICKUP, pid, E_STREAMER_EXTRA_ID, playerid); // update ID boundaries, assuming pickupsIDBounds is set by default to {-1, -1} if(pInfo[playerid][pickupsIDBounds][0] == -1 || pid < pInfo[playerid][pickupsIDBounds][0]) pInfo[playerid][pickupsIDBounds][0] = pid; if(pInfo[playerid][pickupIDBounds][1] == -1 || pid > pInfo[playerid][pickupIDBounds][1]) pInfo[playerid][pickupIDBounds][1] = pid; pInfo[playerid][pickupsCreated]++; // using pickupsCreated you can put an per player limit
new pid = strval(params); // get ID from cmd params or whatever if(!IsValidDynamicPickup(pid) || Streamer_GetIntData(STREAMER_TYPE_PICKUP, pid, E_STREAMER_EXTRA_ID) != playerid) return SendClientMessage(playerid, -1, "This isn't your pickup dude, or it doesn't exist"); DestroyDynamicPickup(pid); pInfo[playerid][pickupsCreated]--; // we don't need to update pickupIDBounds here because they still contain all the created pickups, although we could check if deleted pickup is first or last and update the values to new ones, but it doesn't matter that much
new deletedPickups = 0; // so we can stop if we hit pickupsCreated number, kind of optimization for(new i = pInfo[playerid][pickupsIDBounds][0]; i <= pInfo[playerid][pickupsIDBounds][1] && deletedPickups < pInfo[playerid][pickupsCreated]; i++) // very important to use less or equal (<=) not just < as it wouldn't delete the last pickup { if(IsValidDynamicPickup(i) && Streamer_GetIntData(STREAMER_TYPE_PICKUP, i, E_STREAMER_EXTRA_ID) == playerid) { DestroyDynamicPickup(i); deletedPickups++; } } // also important to reset his ID Bounds and pickupsCreated pInfo[playerid][pickupsIDBounds] = {-1, -1}; pInfo[playerid][pickupsCreated] = 0;