ELM Light problem
#1

Hello there!

I have an issue with this script.

When I attempt to use it, it comes up saying that it both turns it off and on at the same time...



pawn Код:
COMMAND:elm(playerid, params[])
{
    new string[256], msg[200], vehicleid = GetPlayerVehicleID(playerid);
    if(PlayerInfo[playerid][pFaction] == 1 || PlayerInfo[playerid][pFaction] == 2)
    {
        new vehicle = GetPlayerVehicleID(playerid);
        if(VehicleInfo[vehicle][vFaction] != 1 && VehicleInfo[vehicle][vFaction] != 2) return SendClientMessage(playerid, COLOR_GREY, "This vehicle does not have a emergency light.");
        if(Flasher[vehicle] == 1)
        {
            Flasher[vehicle] = 0;
            new enginee, lights, alarm, doors, bonnet, boot, objective;
            SendClientMessage(playerid, -1, "You switched off the lights.");
            GetVehicleParamsEx(vehicleid, enginee, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, enginee, 0, alarm, doors, bonnet, boot, objective);
            format(string, sizeof(string), "* %s turns on the Emergency Lights of the vehicle. *", GetNameWithSpace(playerid));
            ProxDetector(12, playerid, msg, COLOR_PINK);
            new panelsx, doorsx, lightsx, tiresx, lightsxx = encode_lights(0, 0, 0, 0);
            GetVehicleDamageStatus(vehicleid,panelsx,doorsx,lightsx,tiresx);
            UpdateVehicleDamageStatus(vehicleid, panelsx, doorsx, lightsxx, tiresx);
        }
        else
        {
            Flasher[vehicle] = 1;
            new enginee, lights, alarm, doors, bonnet, boot, objective;
            SendClientMessage(playerid, -1, "You have turned on the emergency lights in this vehicle.");
            GetVehicleParamsEx(vehicle, enginee, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicle, enginee, 1, alarm, doors, bonnet, boot, objective);
            format(string, sizeof(string), "** %s turns on the Emergency Lights of the vehicle. **", GetNameWithSpace(playerid, 1));
            ProxDetector(12, playerid, msg, COLOR_PINK);
        }
    }
    return 1;
}
pawn Код:
public FlasherFunc()
{
    new panelsx, doorsx, lightsx, tiresx;
    for(new p=0; p<MAX_VEHICLES; p++)
    {
        if(Flasher[p] == 1)
        {
            if (FlasherState[p] == 1)
            {
                GetVehicleDamageStatus(p,panelsx,doorsx,lightsx,tiresx);
                UpdateVehicleDamageStatus(p, panelsx, doorsx, 4, tiresx);
                FlasherState[p] = 0;
            }
            else
            {
                GetVehicleDamageStatus(p,panelsx,doorsx,lightsx,tiresx);
                UpdateVehicleDamageStatus(p, panelsx, doorsx, 1, tiresx);
                FlasherState[p] = 1;
            }
        }
    }
    return 1;
}

encode_lights(light1, light2, light3, light4)
{
    return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
}
pawn Код:
new Flasher[MAX_VEHICLES];
new FlasherState[MAX_VEHICLES];
And then of course when they spawned, I put them to zero.

Even though it still happens. Any ideas?
Reply
#2

I managed to fix the issue.
Reply
#3

Oh... well just because I edited it anyway, here you go:

pawn Код:
COMMAND:elm(playerid, params[])
{
    if(!(1 <= PlayerInfo[playerid][pFaction] <= 2)) return 1;
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, -1, "You must be the driver of a vehicle to use this command.");
    new vehicle = GetPlayerVehicleID(playerid);
    if(VehicleInfo[vehicle][vFaction] != 1 && VehicleInfo[vehicle][vFaction] != 2) return SendClientMessage(playerid, COLOR_GREY, "This vehicle does not have a emergency light.");
    new enginee, lights, alarm, doors, bonnet, boot, objective, string[80];
    GetVehicleParamsEx(vehicle, enginee, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicle, enginee, (Flasher[vehicle]) ? (0) : (1), alarm, doors, bonnet, boot, objective);
    SendClientMessage(playerid, -1, (Flasher[vehicle]) ? ("You switched off the lights.") : ("You have turned on the emergency lights in this vehicle."));
    if(Flasher[vehicle])
    {
        format(string, sizeof(string), "* %s turns off the Emergency Lights of the vehicle. *", GetNameWithSpace(playerid));
        new panelsx, doorsx, lightsx, tiresx, lightsxx = encode_lights(0, 0, 0, 0);
        GetVehicleDamageStatus(vehicle,panelsx,doorsx,lightsx,tiresx);
        UpdateVehicleDamageStatus(vehicle, panelsx, doorsx, lightsxx, tiresx);
    }
    else format(string, sizeof(string), "** %s turns on the Emergency Lights of the vehicle. **", GetNameWithSpace(playerid, 1));
    ProxDetector(12, playerid, string, COLOR_PINK);
    Flasher[vehicle] = (Flasher[vehicle]) ? (0) : (1);
    return 1;
}
As you may have noticed, the problem was that you should have been using 'else if' statements rather than just an 'else' statement. Because the variable 'Flasher[vehicle]' would have changed by the time it reached the 'else' statement.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)