[Help] Lightbars
#1

This command is supposed to add two lightbars, and then remove them with this following command.

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/siren", cmdtext, true, 6) == 0)
    {
        if (GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
        {
            return SendClientMessage(playerid, -1, "* You are not the driver!");
        }
        new pveh = GetPlayerVehicleID(playerid);
        if (!GetVehicleModel(pveh)) return SendClientMessage(playerid, -1, "* You are not in a vehicle!");
        for (new i = 0; i < MAX_VEHICLES; i++)
        if (VObject(obj[pveh])) return SendClientMessage(playerid, -1, "* You switched off the lights."), DObject(obj[pveh]);
        if (VObject(obj2[pveh])) return SendClientMessage(playerid, -1, "* You switched off the lights."), DObject(obj2[pveh]);
        switch (GetVehicleModel(pveh))
        {
            case 426:
            {
                obj[pveh] = CObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                obj2[pveh] = CObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                AObject(obj[pveh], pveh, 0.000000, -1.574999, 0.344999, -5.000000, 0.000000, 0.000000);
                AObject(obj2[pveh], pveh, 0.000000, 2.574999, 0.344999, -5.000000, 0.000000, 0.000000);
            }
            default:
            {
                return SendClientMessage(playerid, -1, "* You are not in a CODE 2 compatible police vehicle!");
            }
        }
        return SendClientMessage(playerid, -1, "* Lights on, you are now in a CODE 2 run!");
    }
    return 0;
}
Before I added the second lightbar to the premier, everything was working fine. When I do /siren it adds the two light bars but when I do it again, only the first one goes away. But this line is supposed to get rid of it.

Код:
if (VObject(obj2[pveh])) return SendClientMessage(playerid, -1, "* You switched off the lights."),DObject(obj2[pveh]);
Can anyone help me fix this little issue by taking off both sirens on the command?
Reply
#2

Bump.
Reply
#3

Well that's why it add 2 objects on your car
pawn Код:
obj[pveh] = CObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                obj2[pveh] = CObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                AObject(obj[pveh], pveh, 0.000000, -1.574999, 0.344999, -5.000000, 0.000000, 0.000000);
                AObject(obj2[pveh], pveh, 0.000000, 2.574999, 0.344999, -5.000000, 0.000000, 0.000000);
and use DestroyObject to remove it...
Reply
#4

Quote:
Originally Posted by Lajko1
Посмотреть сообщение
Well that's why it add 2 objects on your car
pawn Код:
obj[pveh] = CObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                obj2[pveh] = CObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                AObject(obj[pveh], pveh, 0.000000, -1.574999, 0.344999, -5.000000, 0.000000, 0.000000);
                AObject(obj2[pveh], pveh, 0.000000, 2.574999, 0.344999, -5.000000, 0.000000, 0.000000);
and use DestroyObject to remove it...
I am using DObject ( Destroy Object ) to remove it. And that code is exactly what I have under the case. I want to know how to remove them both when /siren is done for the second time ( So /siren is exectuted, both sirens show up, and then I want it to remove both not only one when /siren is done again. )
Reply
#5

Just destory both object? with your function DObject / DestroyObject
Reply
#6

Quote:
Originally Posted by Lajko1
Посмотреть сообщение
Just destory both object? with your function DObject / DestroyObject
That is what these lines are for:

Код:
        if (VObject(obj[pveh])) return SendClientMessage(playerid, -1, "* You switched off the lights."), DObject(obj[pveh]);
        if (VObject(obj2[pveh])) return SendClientMessage(playerid, -1, "* You switched off the lights."), DObject(obj2[pveh]);
It checks to see if obj and obj2 are valid objects, and if they are it removes them.
Reply
#7

Fixed with:

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/code2", cmdtext, true, 6) == 0)
    {
        if (GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
        {
            return SendClientMessage(playerid, -1, "* You are not the driver!");
        }
        new pveh = GetPlayerVehicleID(playerid);
        if (!GetVehicleModel(pveh)) return SendClientMessage(playerid, -1, "* You are not in a vehicle!");
        if (VObject(obj[pveh])) return SendClientMessage(playerid, -1, "* You switched off the lights."), DObject(obj[pveh]), DObject(obj2[pveh]);
        switch (GetVehicleModel(pveh))
        {
            case 426:
            {
                obj[pveh] = CObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                obj2[pveh] = CObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                AObject(obj[pveh], pveh, 0.000000, -1.574999, 0.344999, -5.000000, 0.000000, 0.000000);
                AObject(obj2[pveh], pveh, 0.000000, 2.574999, 0.344999, -5.000000, 0.000000, 0.000000);
            }
            default:
            {
                return SendClientMessage(playerid, -1, "* You are not in a CODE 2 compatible police vehicle!");
            }
        }
        return SendClientMessage(playerid, -1, "* Lights on, you are now in a CODE 2 run!");
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)