SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 08/05/2017, 01:53 PM   #1
andrew2695
Big Clucker
 
Join Date: Oct 2010
Posts: 128
Reputation: 4
Default Trying to store pickup ids to delete them later in a dynamic pickup creator

Solved, thank you!

Last edited by andrew2695; 09/05/2017 at 12:25 AM.
andrew2695 is offline   Reply With Quote
Old 08/05/2017, 02:37 PM   #2
dotSILENT
Big Clucker
 
dotSILENT's Avatar
 
Join Date: Aug 2016
Location: Poland
Posts: 53
Reputation: 64
Default Re: Trying to store pickup ids to delete them later in a dynamic pickup creator

You are using streamer, so what I would suggest you to do is to use streamers internal "Extra ID" functionality, together with storing ID boundaries. You won't even need to store any data because you can obtain it using streamer's functions. You won't have your "custom pickups id" then, unless you will implement them on your own (also using streamer's extra_id)
That way you won't have any limit and you will save a lot of memory (since any arrays won't be needed, and you can implement limits on your own using just one variable and incrementing/decrementing it)
So, this is how I would do it:

Player's enum/data:
Code:
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)
Creating pickups:
Code:
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
On creation, show player the ID from CreateDynamicPickup, or implement your own IDs and also store them in pickup's EXTRA_ID.
Deleting a single pickup (player gives us ID from CreateDynamicPickup, so no need to do any looping just direct memory acces to confirm he created it)
Code:
    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
Deleting all player's pickups
Code:
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;
This is a much better approach, as it saves a lot of memory, gives us theoretically no limits, and if we wan't limits we can flexibly set them as we want even at runtime.

EDIT
I'm not sure what value streamer is using by default in EXTRA_ID, but if it's 0 then you would need to set data to playerid+1 and check data for playerid+1, otherwise player with id 0 could unintentionally delete normal pickups that don't have any EXTRA_ID set so it's 0. You should check what Streamer_GetIntData(..) returns for an freshly created pickup to see what the default value is.
dotSILENT is offline   Reply With Quote
Old 08/05/2017, 07:48 PM   #3
andrew2695
Big Clucker
 
Join Date: Oct 2010
Posts: 128
Reputation: 4
Default Re: Trying to store pickup ids to delete them later in a dynamic pickup creator

Thanks for such a quick answer, but It could be used on a different streamer later, thats why I'd prefer using the basic function, to edit it later. I still tried your code and and both codes creates many pickups when run the /createpickup command. It seems that something is wrong with my /createpickup command
andrew2695 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] H-Pickup - In-Game Pickup Creator haikalbintang Filterscripts 26 19/06/2018 09:51 PM
[FilterScript] S32_MyPickup - Dynamic pickup creator (Support change vehicle) System64 Filterscripts 24 19/02/2016 07:56 PM
[FilterScript] Dynamic Pickup Creator [User Friendly/Easy to use] -> Textdraws HY Filterscripts 9 21/02/2015 05:56 PM
[FilterScript] Pickup Creator Lós Lançamentos/Releases 37 22/01/2013 12:36 AM
[FilterScript] Pickup Creator Lós Filterscripts 2 06/10/2011 01:36 PM


All times are GMT. The time now is 12:55 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.