Help with Engine on/off system? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with Engine on/off system? (
/showthread.php?tid=170061)
Help with Engine on/off system? -
Jmarr - 21.08.2010
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;
}
Re: Help with Engine on/off system? -
Mike_Peterson - 21.08.2010
Код:
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
Re: Help with Engine on/off system? -
Jmarr - 21.08.2010
didn't work.
Re: Help with Engine on/off system? -
boelie - 21.08.2010
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
}