Engine system with pressing button is not working -
sidney123 - 03.08.2012
Hello SA-MP community,
I'm having troubles with an engine system. I want it that if the player is in a vehicle and the player presses the 'Y' button, the engine turns on. If the player presses 'Y' again, the engine turns off.
The problem is that if I press 'Y', my screen is overloaded with the 'You are not driving a vehicle!' message AND 'My_Name turns the engine on.' How can I fix that?
pawn Код:
new engine, lights, alarm, doors, bonnet, boot, objective, vehicleid, string[128];
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle.");
if(IsPlayerInAnyVehicle(playerid))
if(vehicleid == 509 || vehicleid == 481 || vehicleid == 510) return SendClientMessage(playerid, COLOR_GREY, "Bicycles have no engine.");
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
if(!engine)
{
if(PRESSED(KEY_YES))
SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh])
{SetVehicleParamsEx(vehicleid, 1, lights, alarm, PlayerInfo[playerid][vLocked], bonnet, boot, objective);}
else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVVeh])
{SetVehicleParamsEx(vehicleid, 1, lights, alarm, PlayerInfo[playerid][vVLocked], bonnet, boot, objective);}
format(string, sizeof(string), "* %s turns the vehicle's engine on.", RPN(playerid));
SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
}
else
{
SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh])
{SetVehicleParamsEx(vehicleid, 0, lights, alarm, PlayerInfo[playerid][vLocked], bonnet, boot, objective);}
if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVVeh])
{SetVehicleParamsEx(vehicleid, 0, lights, alarm, PlayerInfo[playerid][vVLocked], bonnet, boot, objective);}
format(string, sizeof(string), "* %s turns the vehicle's engine off.", RPN(playerid));
SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
}
I already defined it on top of my script with
pawn Код:
#define PRESSED(%0) \
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
I don't either know if that is correct.
Any help will be respected of course.
Kind regards,
sidney123.
Re: Engine system with pressing button is not working -
bloodrocklee - 03.08.2012
try
if (newkeys & KEY_YES)
Re: Engine system with pressing button is not working -
sidney123 - 03.08.2012
The same problem occurs, only with the 'Y' button included. When I press KEY_FIRE, it gives me the same message as before and when I press the handbrake key, right mouse button, sub-mission key..
Re: Engine system with pressing button is not working -
sidney123 - 04.08.2012
No-one who can help me?
PS: Sorry for the double post.
Re: Engine system with pressing button is not working -
Devilxz97 - 04.08.2012
pawn Код:
new engine[MAX_VEHICLES]; //top of script
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
if(PRESSED(KEY_YES))
{
if(GetPlayerState(playerid) == 2) return SendClientMessage(playerid, -1, "You are not driving a vehicle.");
{
if(vehicleid == 509 || vehicleid == 481 || vehicleid == 510) return SendClientMessage(playerid, -1, "Bycycle have no engine");
{
if(engine[vehicleid] == 0)
{
new Engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, Engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
engine[vehicleid] = 1;
SendClientMessage(playerid, -1, "You have turn on this vehicle Engine!");
}
else
{
new Engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, Engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
engine[vehicleid] = 0;
SendClientMessage(playerid, -1, "You have turn off this vehicle Engine!");
}
}
}
}
return 1;
}
try this..
rep if this works fine for u