SA-MP Forums Archive
Create and Destroy Dynamic(Player)Objects - 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: Create and Destroy Dynamic(Player)Objects (/showthread.php?tid=661223)



Create and Destroy Dynamic(Player)Objects - GospodinX - 26.11.2018

Hi guys

I have Roleplay server and for Winter I'm think to add snow objects.But I'm think to do that players can disable and enable snow objects.I have 500 snow objects,so my question is:Is it possible to do,and how?
I need to create 500 variable for all player?I hope no.

Quote:

native STREAMER_TAG_OBJECT CreateDynamicObject(modelid, Float, Float:y, Float:z, Float:rx, Float:ry, Float:rz, worldid = -1, interiorid = -1, playerid = -1, Floattreamdistance = STREAMER_OBJECT_SD, Float:drawdistance = STREAMER_OBJECT_DD, STREAMER_TAG_AREA areaid = STREAMER_TAG_AREA -1, priority = 0);

I will use parametar playerid from CreateDynamicObject to create objects for player which is enable snow objects.But I don't know how to disable(destroy) objects when players want it(and on disconnect)

I need to use DestroyDynamicObject,but I need to know all object id's.But it's 500 variable per player,i don't think that it's smart..( 500 * 250 = 125000 )

What is best to do in my case? Thanks


Re: Create and Destroy Dynamic(Player)Objects - GospodinX - 01.12.2018

Thank you very much for your answer.

I did it successfully.It works as I wanted..
I just have question about destroy object,is there any better way to destroy all playerobject then for loop through the whole objects.(I have many objects,so it's very big loop with many checks). (~30,000 objects...)

My code

Код:
DestroySnowObject(playerid)
{
    new data;
    for(new i; i < Streamer_GetUpperBound(STREAMER_TYPE_OBJECT); ++i) //for loop for all objects
    {
        if(!IsValidDynamicObject(i)) continue;
        Streamer_GetArrayData(STREAMER_TYPE_OBJECT, i, E_STREAMER_PLAYER_ID, data);
        if(data == playerid) 
        {
            DestroyDynamicObject(i);
        }
    }

    return 0;
}
If not.It's okay,it works.
Sorry for my English..