Engine Not Turning On/Variable problem?
#1

pawn Код:
command(engine, playerid, params[])
{
    #pragma unused params
    new string[128];
    SendClientMessage(playerid, WHITE, "pragma unsued params");
    if(IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid, WHITE, "Isplayerinanyvehicle");
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            SendClientMessage(playerid, WHITE, "playeR_state_driver");
            new vehicleid = GetPlayerVehicleID(playerid);
            new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            if(EngineOn[vehicleid] == 0) //turn off
            {
                SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
                format(string, sizeof(string), "* %s starts the engine of the %s", GetName(playerid), VehicleNames[vehicleid-400]);
                NearByMessage(playerid, NICESKY, string);
                EngineOn[vehicleid] = 1;
            }
            else if(EngineOn[vehicleid] == 1) //turn on
            {
                SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
                format(string, sizeof(string), "* %s stops the engine of the %s", GetName(playerid), VehicleNames[vehicleid-400]);
                NearByMessage(playerid, NICESKY, string);
                EngineOn[vehicleid] = 0;
            }
        }
    }
    return 1;
}
This is my engine command. Everything goes fine until it reaches the actual part where the engine goes on. Please help.
Reply
#2

You have the SetVehicleParams thing wrong.

Where engine is on that, should be

0 = turn off
1 = turn on

You have those two backwards on the if statements.
Reply
#3

Still doesn't work. What is that other thing called that replaces the "1", it's like ENGINE_ON or something.
Reply
#4

Slegde, 0 is false, 1 is true.

pawn Код:
SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective); // Off
SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective); // On
Where are you getting EngineOn[vehicleid] == 0 from? Should just be engine. Or, what is the default value for it?

Bit off topic here, but what movie is your signature from? Can't remember the name, and I haven't seen it in ages. If I can recall correctly, it's a Stephen King movie.
Reply
#5

Okay, I used SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_ON,lig hts,alarm,doors,bonnet,boot,objective); instead of my old one.

Here's my problem. The engine turns on, but it doesn't turn off. And when I turn it on, the text I want to execute doesn't show up. "* Name starts the engine of the CarName."

Here's my full command (new one):
pawn Код:
command(engine, playerid, params[])
{
    #pragma unused params
    new string[128];
    SendClientMessage(playerid, WHITE, "pragma unsued params");
    if(IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid, WHITE, "Isplayerinanyvehicle");
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            SendClientMessage(playerid, WHITE, "playeR_state_driver");
            new vehicleid = GetPlayerVehicleID(playerid);
            if(Engine[vehicleid] == 0)
            {
                new engine, lights, alarm, doors, bonnet, boot, objective;
                GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
                format(string, sizeof(string), "* %s starts the engine of the %s", GetName(playerid), VehicleNames[vehicleid-400]);
                NearByMessage(playerid, NICESKY, string); //this sends the message to all nearby players (String)
                Engine[vehicleid] = 1;
            }
            else if(Engine[vehicleid] == 1)
            {
                new engine, lights, alarm, doors, bonnet, boot, objective;
                GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);

                format(string, sizeof(string), "* %s stops the engine of the %s", GetName(playerid), VehicleNames[vehicleid-400]);
                NearByMessage(playerid, NICESKY, string);
                Engine[vehicleid] = 0;
            }
        }
        else
        {
            SendClientMessage(playerid, WHITE, "You are not the driver");
        }
    }
    else
    {
        SendClientMessage(playerid, WHITE, "You are not in a vehicle");
    }
    return 1;
}
Reply
#6

Well, the thing is you need to get the engine variable before checking if the engine is ON or OFF. Something like:
pawn Код:
CMD:engine(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid))
        return 1;

    new vehid = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vehid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(engine != 1)
        return SetVehicleParamsEx(vehid,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);

    else return SetVehicleParamsEx(vehid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
}
Reply
#7

Can someone just please fix my command? I spent time on it.
Reply
#8

pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);
new modelid = GetVehicleModel(vehicleid);
pawn Код:
format(string, sizeof(string), "* %s starts the engine of the %s", GetName(playerid), VehicleNames[modelid-400]);
pawn Код:
format(string, sizeof(string), "* %s stops the engine of the %s", GetName(playerid), VehicleNames[modelid-400]);
Reply
#9

fixed: format(string, sizeof(string), "* %s stops the engine of the %s", GetName(playerid), VehicleNames[vehicleid-400]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)