GetPlayerVehicleEx
#1

When I am ingame my vehicle doesn't turn on the engine, as showed in the script. I tried digging into the problem, and I found where it's coming from.

Main Script:
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(newkeys == KEY_SUBMISSION)
	{
		if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		{
			new vehicle;
			vehicle = GetPlayerVehicleID(playerid);
			new lights, alarms, doors, bonnet, boot, objective;
			new engine;
			GetVehicleParamsEx(vehicle, engine, lights, alarms, doors, bonnet, boot, objective);
			
			if(engine == 0)//If the engine is off
			{
			    SetVehicleParamsEx(vehicle, 1, lights, alarms, doors, bonnet, boot, objective);
			
			}
			if(engine == 1)
			{
			    SetVehicleParamsEx(vehicle, 0, lights, alarms, doors, bonnet, boot, objective);
			
			}
		
		}
	}

	return 1;
}

Lines that don't work:
Код:
    		        new lights, alarms, doors, bonnet, boot, objective;
			new engine;
			GetVehicleParamsEx(vehicle, engine, lights, alarms, doors, bonnet, boot, objective);
			
			if(engine == 0)//If the engine is off
			{
			    SetVehicleParamsEx(vehicle, 1, lights, alarms, doors, bonnet, boot, objective);
			
			}
Somwhow the problem is that GetVehicleParamsEx doesn't save the engine status (0/1) to the 'engine' variable. I can't figure out why. Any suggestions? Thanks.
Reply
#2

Try to replace "if(engine == 0)" with this

Код:
if(engine != 1)
and "if(engine == 1)" with this

Код:
if(engine != 0)
Reply
#3

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == KEY_SUBMISSION)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vehicle;
vehicle = GetPlayerVehicleID(playerid);
new lights, alarms, doors, bonnet, boot, objective;
new engine;
GetVehicleParamsEx(vehicle, engine, lights, alarms, doors, bonnet, boot, objective);

if(engine == 0)//If the engine is off
{
SetVehicleParamsEx(vehicle, 1, lights, alarms, doors, bonnet, boot, objective);

}
else if(engine == 1)
{
SetVehicleParamsEx(vehicle, 0, lights, alarms, doors, bonnet, boot, objective);

}

}
}

return 1;
}
Reply
#4

PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
newkeys == KEY_SUBMISSION)
    {
        if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new 
vehicle;
            
vehicle GetPlayerVehicleID(playerid);
            new 
enginelightsalarmsdoorsbonnetbootobjective;
            
GetVehicleParamsEx(vehicleenginelightsalarmsdoorsbonnetbootobjective);
            
SetVehicleParamsEx(vehicle, (engine>0?0:1), lightsalarmsdoorsbonnetbootobjective);
        }
    }
    return 
1;

Reply
#5

So basically Denying's suggestion fixed it. Except I needed to do the same with if(engine == 0). Thank you.
Reply
#6

Just a note. Parameter does not have to be 0 or 1, it can also be unset (-1). Unset is if you never set it to 0 or 1.
Reply
#7

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
Just a note. Parameter does not have to be 0 or 1, it can also be unset (-1). Unset is if you never set it to 0 or 1.
That's why I told him to use the if statement I wrote.

Quote:
Originally Posted by Sheperc
Посмотреть сообщение
So basically Denying's suggestion fixed it. Except I needed to do the same with if(engine == 0). Thank you.
You're welcome.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)