Vehicle Engine not turning on?
#1

Basically my vehicle's engine should be turning on; however it is not, quite obviously. Below is the code posted that has been completely confusing me:
pawn Код:
command(engineon, playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new string[128];
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, ERROR, "ERROR: You need to be in a vehicle to use this command!");
    if (GetVehicleModel(GetPlayerVehicleID(playerid)) == 509 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 510 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 511)
    {
        SendClientMessage(playerid, ERROR, "ERROR: Pedal bikes do not have engines!");
    }
    else
    {
        if(vehEngine[vehicleid] == 0)
        {
            if(Vehicles[vehicleid][Fuel] >= 1)
            {
                vehEngine[vehicleid] = 2;
                SetTimerEx("StartEngine", 3000, 0, "i", playerid);
                format(string, sizeof(string), "* %s twists the key in the ignition, powering up their vehicle. *", ActionName(playerid));
                NearByMessage(playerid, 0xFFA8FFFF, string);
                GameTextForPlayer(playerid, "~Y~Starting...", 3000, 4);
            }
            else
            {
                if(IsPlayerInAnyVehicle(playerid))
                {
                    SendClientMessage(playerid, ERROR, "ERROR: This vehicle vehicle is out of fuel!");
                }
            }
        }
        else
        {
            SendClientMessage(playerid, 0xAFAFAFFF, "Your car's engine is already powered on!");
        }
    }
    return 1;
}
pawn Код:
public StartEngine(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new Float:health;
    new rand = random(4);
    new engine, lights, alarm, doors, boot, objective, bonnet;
    GetVehicleHealth(vehicleid, health);
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(vehEngine[vehicleid] == 2)
        {
            if(health > 900)
            {
                vehEngine[vehicleid] = 1;
                GameTextForPlayer(playerid, "~G~ENGINE ON!", 2000, 4);
                GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
            }
            else if(health < 800)
            {
                if(rand == 0)
                {

                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 2000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
                if(rand == 1)
                {
                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 2000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
                if(rand == 2)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 2000, 4);
                }
            }
            else if(health < 700)
            {
                if(rand == 0)
                {
                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 2000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
                if(rand == 1)
                {
                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 2000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
                if(rand == 2)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 2000, 4);
                }
            }
            else if(health < 600)
            {
                if(rand == 0)
                {
                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 2000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
                if(rand == 1)
                {
                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 2000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
                if(rand == 2)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 2000, 4);
                }
                if(rand == 3)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 2000, 4);
                }
            }
            else if(health < 500)
            {
                if(rand == 0)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 2000, 4);
                }
                if(rand == 1)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 2000, 4);
                }
                if(rand == 2)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 2000, 4);
                }
                if(rand == 3)
                {
                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 5000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
                if(rand == 4)
                {
                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 5000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
            }
            else if(health < 400)
            {
                if(rand == 0)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 5000, 4);
                }
                if(rand == 1)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 5000, 4);
                }
                if(rand == 2)
                {
                    vehEngine[vehicleid] = 0;
                    GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 5000, 4);
                }
                if(rand == 3)
                {
                    vehEngine[vehicleid] = 1;
                    GameTextForPlayer(playerid, "~G~ENGINE ON!", 5000, 4);
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                }
            }
            else if(health < 300)
            {
                vehEngine[vehicleid] = 0;
                SendClientMessage(playerid, 0xFF0000FF, "Vehicle engine failed to start due to damage");
                GameTextForPlayer(playerid, "~R~ENGINE FAILURE!", 5000, 4);
            }
        }
    }
    return 1;
}
Any and all help will be appreciated; however reputation points cannot be guaranteed but very much possible.

~Nmader
Reply
#2

Have you tested both damaged and undamaged vehicles, do both not work? Have you placed
pawn Код:
ManualVehicleEngineAndLights();
in OnGameModeInit?
Reply
#3

Quote:
Originally Posted by zDevon
Посмотреть сообщение
Have you tested both damaged and undamaged vehicles, do both not work? Have you placed
pawn Код:
ManualVehicleEngineAndLights();
in OnGameModeInit?
Yes, I have.

However I did figure out the problem, I have misplaced the timer so it was never being ran through by the script. I moved it to a lower location in the file and it works like a charm!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)