Help with Engine on/off system?
#1

Hello,

I'm trying to make a code that starts and stops the engine with the same button (LShift), I have it working with no errors and the engine starts but then when hold s (brake) it ejects me out and says engine off, and if i stop the car it kicks me out and says engine off.

Heres the code:
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	new vehicle = GetPlayerVehicleID(playerid);
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
	if ((newkeys & KEY_JUMP) && !(oldkeys & KEY_JUMP))
{
	if(Vehicle[vehicle][Engine] == 0)
{
	TogglePlayerControllable(playerid, true);
	Vehicle[vehicle][Engine] = 1;
	SendClientMessage(playerid, COLOR_GREEN, "[VEHICLE]:: Engine started.");
}
	else
{
	RemovePlayerFromVehicle(playerid);
	Vehicle[vehicle][Engine] = 0;
	SendClientMessage(playerid, COLOR_RED, "[VEHICLE]:: Engine off.");
}
}
}
	return 1;
}
Reply
#2

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	new vehicle = GetPlayerVehicleID(playerid);
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
	if ((newkeys & KEY_JUMP) && !(oldkeys & KEY_JUMP))
{
	if(Vehicle[vehicle][Engine] == 0)
{
	TogglePlayerControllable(playerid, true);
	Vehicle[vehicle][Engine] = 1;
	SendClientMessage(playerid, COLOR_GREEN, "[VEHICLE]:: Engine started.");
}
	else if(Vehicle[vehicle][Engine] == 1)
{
	RemovePlayerFromVehicle(playerid);
	Vehicle[vehicle][Engine] = 0;
	SendClientMessage(playerid, COLOR_RED, "[VEHICLE]:: Engine off.");
}
}
}
	return 1;
}
dno, maybe it works, what i added is: else if
Reply
#3

didn't work.
Reply
#4

you need to use 'switch'

take a look at this code (its for switching lights on and of) it might help you out

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{

//------------------------------------------------------------------------------
	if(newkeys & 4)//the lightswitch
	{
 		new panels, doors, lights, tires;
		GetVehicleDamageStatus(GetPlayerVehicleID(playerid), panels, doors, lights, tires);
		switch(GetPVarInt(playerid, "VehON"))
		{
		    case 0:
			{
		        lights = encode_lights(0, 0, 0, 0);//on
      			SetPVarInt(playerid, "VehON", 1);
			}
			case 1:
			{
				lights = encode_lights(1, 1, 1, 1);//off
				SetPVarInt(playerid, "VehON", 0);
			}
		}
		UpdateVehicleDamageStatus(GetPlayerVehicleID(playerid), panels, doors, lights, tires);
	}

return 1
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)