SA-MP Forums Archive
Checking for an open slot - 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: Checking for an open slot (/showthread.php?tid=520688)



Checking for an open slot - willsuckformoney - 19.06.2014

I'm making my own simple object editor but I'm not sure how to check for an open slot if an earlier created object was deleted to take its space. For example, I create 15 objects and delete object number 8, then I'll create another object and have it replace ID 8 then continue at 16 for the next object. I have a code that could be altered if it's needed. I'm not entirely sure if the method I have already works or not. Thanks in advance.
pawn Код:
CMD:createobject(playerid,params[])
{
    new Float:pos[3], str[128], objectid;
    GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
    for(new o; o < MAXOBJ; o++)
    {
        if(ObjInfo[o][used] == 0)
        {
            ObjInfo[o][objID] = CreateDynamicObject(objectid,pos[0]+2, pos[1]+3, pos[2],0,0,0);
            ObjInfo[o][used] = 1;
            ObjInfo[o][objX] = pos[0];
            ObjInfo[o][objY] = pos[1];
            ObjInfo[o][objZ] = pos[2];
            ObjInfo[o][objRX] = 0;
            ObjInfo[o][objRY] = 0;
            ObjInfo[o][objRZ] = 0;
            EditObject(playerid,o);
        }
    }
    return 1;
}



Re: Checking for an open slot - AiRaLoKa - 20.06.2014

pawn Код:
CMD:createobject(playerid,params[])
{
    new Float:pos[3], str[128], objectid;
    GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
    for(new o; o < MAXOBJ; o++)
    {
        if(ObjInfo[o][used] == 0)
        {
            ObjInfo[o][objID] = CreateDynamicObject(objectid,pos[0]+2, pos[1]+3, pos[2],0,0,0);
            ObjInfo[o][used] = 1;
            ObjInfo[o][objX] = pos[0];
            ObjInfo[o][objY] = pos[1];
            ObjInfo[o][objZ] = pos[2];
            ObjInfo[o][objRX] = 0;
            ObjInfo[o][objRY] = 0;
            ObjInfo[o][objRZ] = 0;
            EditObject(playerid,o);
            break;
        }
    }
    return 1;
}
maybe?


Re: Checking for an open slot - Haydz - 20.06.2014

Have you tried using IsValidDynamicObject? This should return the first free object slot where an object is not valid. Not tested !

pawn Код:
stock GetFreeObjectSlot()
{
    for(new o; o < MAXOBJ; o++)
    {
        if(!IsValidDynamicObject(o)) return o;
    }
    return -1;
}
pawn Код:
CMD:createobject(playerid,params[])
{
    new Float:pos[3], str[128], objectid,o = GetFreeObjectSlot();
    GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
    ObjInfo[o][objID] = CreateDynamicObject(objectid,pos[0]+2, pos[1]+3, pos[2],0,0,0);
    ObjInfo[o][used] = 1;
    ObjInfo[o][objX] = pos[0];
    ObjInfo[o][objY] = pos[1];
    ObjInfo[o][objZ] = pos[2];
    ObjInfo[o][objRX] = 0;
    ObjInfo[o][objRY] = 0;
    ObjInfo[o][objRZ] = 0;
    EditObject(playerid,o);
    return 1;
}