destroy all
#1

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;
}
Reply
#2

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;
}
Reply
#3

It works, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)