Starting Engine dures twice :?
#10

Quote:
Originally Posted by R0
Посмотреть сообщение
you have defined engine as:
pawn Код:
new engine;
right?if ye change it to
pawn Код:
new engine[MAX_VEHICLES];
The engine variable is created and used within the command for GetVehicleParamsEx, he shouldn't need to redefine it for the vehicle.

As you can read here: https://sampwiki.blast.hk/wiki/GetVehicleParamsEx
Quote:

"If a parameter is unset (SetVehicleParamsEx not used beforehand) the value will be -1 ('unset')."

Therefore you need to check if the engine parameter is unset aswell, not just 0 or 1.

Read the changes I made carefully and learn from them, also read the notes on the Wiki before you use a function that you do not know anything about.
pawn Код:
CMD:engine(playerid, params[])
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new vehicle = GetPlayerVehicleID(playerid);
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
        if(engine == 0 || engine == -1)
        {
            SetVehicleParamsEx(vehicle, 1, 1, alarm, doors, bonnet, boot, objective);
            new string[128], name[24];
            GetPlayerName(playerid, name, sizeof(name));
            format(string, sizeof(string), "* %s turns the ignition and starts the engine.", name);
            SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        }
        else if(engine == 1)
        {
            SetVehicleParamsEx(vehicle, 0, 0, alarm, doors, bonnet, boot, objective);
            new string[128], name[24];
            GetPlayerName(playerid, name, sizeof(name));
            format(string, sizeof(string), "* %s turns the ignition and turns off the engine.", name);
            SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        }
    }
    return 1;
}
     
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SUBMISSION))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new vehicle = GetPlayerVehicleID(playerid);
            new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
            if(engine == 0 || engine == -1)
            {
                SetVehicleParamsEx(vehicle, 1, 1, alarm, doors, bonnet, boot, objective);
                new string[128], name[24];
                GetPlayerName(playerid, name, sizeof(name));
                format(string, sizeof(string), "* %s turns the ignition and starts the engine.", name);
                SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
            }
            else
            {
                SetVehicleParamsEx(vehicle, 0, 0, alarm, doors, bonnet, boot, objective);
                new string[128], name[24];
                GetPlayerName(playerid, name, sizeof(name));
                format(string, sizeof(string), "* %s turns the ignition and turns off the engine.", name);
                SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
            }
        }
    }
    return 1;
}
Reply


Messages In This Thread
Starting Engine dures twice :? - by Mey6155 - 29.05.2014, 12:58
Re: Starting Engine dures twice :? - by R0 - 29.05.2014, 13:02
Re: Starting Engine dures twice :? - by d3ll - 29.05.2014, 13:05
Re: Starting Engine dures twice :? - by Mey6155 - 29.05.2014, 13:07
Re: Starting Engine dures twice :? - by Mey6155 - 29.05.2014, 13:12
Re: Starting Engine dures twice :? - by nickdodd25 - 29.05.2014, 13:18
Re: Starting Engine dures twice :? - by Mey6155 - 29.05.2014, 13:20
Re: Starting Engine dures twice :? - by R0 - 29.05.2014, 14:05
Re: Starting Engine dures twice :? - by bogdyutzu - 29.05.2014, 14:28
Re: Starting Engine dures twice :? - by [NWA]Hannes - 29.05.2014, 14:37

Forum Jump:


Users browsing this thread: 3 Guest(s)