SA-MP Forums Archive
GetPlayerVehicleEx - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: GetPlayerVehicleEx (/showthread.php?tid=595527)



GetPlayerVehicleEx - Sheperc - 04.12.2015

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.


Re: GetPlayerVehicleEx - Denying - 04.12.2015

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

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

Код:
if(engine != 0)



Re: GetPlayerVehicleEx - SupperRobin6394 - 04.12.2015

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;
}


Re: GetPlayerVehicleEx - AbyssMorgan - 04.12.2015

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;




Re: GetPlayerVehicleEx - Sheperc - 04.12.2015

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


Re: GetPlayerVehicleEx - DRIFT_HUNTER - 04.12.2015

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.


Re: GetPlayerVehicleEx - Denying - 05.12.2015

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.