SA-MP Forums Archive
destroy all - 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: destroy all (/showthread.php?tid=379912)



destroy all - Why - 23.09.2012

Hello. I am making a barricade system, however when I am going to destroy the barricades, it only destroys the last one.

I know what is wrong, it's because it's only storing the last cade, but I don't know how to fix it. This is my code:

pawn Код:
CMD:cade(playerid, params[])
{
    for(new i;i<MAX_BARRICADES;i++)
    {
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, a);
        cade[i] = CreateObject(981, x, y, z, 0.0, 0.0, a);
        SetPlayerPos(playerid, x, y-1, z);
    }
    return 1;
}

CMD:destroycades(playerid, params[])
{
    for(new i;i<MAX_BARRICADES;i++)
    {
        DestroyObject(cade[i]);
    }
    return 1;
}



Re: destroy all - clarencecuzz - 23.09.2012

Try this:
pawn Код:
CMD:cade(playerid, params[])
{
    for(new i = 0; i < MAX_BARRICADES; i++)
    {
        if(!IsValidObject(cade[i])
        {
            new Float:x, Float:y, Float:z, Float:a;
            GetPlayerPos(playerid, x, y, z);
            GetPlayerFacingAngle(playerid, a);
            cade[i] = CreateObject(981, x, y, z, 0.0, 0.0, a);
            SetPlayerPos(playerid, x, y-1, z);
            break;
        }
        continue;
    }
    return 1;
}

CMD:destroycades(playerid, params[])
{
    for(new i = 0; i < MAX_BARRICADES; i++)
    {
        if(IsValidObject(cade[i])
        {
            DestroyObject(cade[i]);
        }
        continue;
    }
    return 1;
}



Re: destroy all - Why - 23.09.2012

It works, thank you.