I try to make an engine sistem...but doesn't work.... :
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new vehicleid = GetPlayerVehicleID(playerid);
//--------------------
if ((newkeys==KEY_LOOK_BEHIND))
{
if(Engine[vehicleid] == 0)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new Vehicle = GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(Vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
SendClientMessage(playerid, COLOR_YELLOW, "You have turned your engine >{FFFFFF} ON");
Engine[Vehicle] = 1, SetVehicleParamsEx(Vehicle, 1, lights, alarm, doors, bonnet, boot, objective);
}
}
}
else
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new Vehicle = GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(Vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
SendClientMessage(playerid, COLOR_YELLOW, "You have turned your engine >{FFFFFF} OFF");
Engine[Vehicle] = 0, SetVehicleParamsEx(Vehicle, 0, lights, alarm, doors, bonnet, boot, objective);
}
}
if ((newkeys==KEY_NO))
{
if(Lights[vehicleid] == 0)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new Vehicle = GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(Vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
SendClientMessage(playerid, COLOR_YELLOW, "You have turned your lights >{FFFFFF} ON");
Lights[Vehicle] = 1, SetVehicleParamsEx(Vehicle, engine, 1, alarm, doors, bonnet, boot, objective);
}
}
}
else
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new Vehicle = GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(Vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
SendClientMessage(playerid, COLOR_YELLOW, "You have turned your lights >{FFFFFF} OFF");
Lights[Vehicle] = 0, SetVehicleParamsEx(Vehicle, engine, 0, alarm, doors, bonnet, boot, objective);
}
}
return 0;
}
I believe the problem is in conditions. In fact, there is a lot of unnecessary code. Why do you create 2 variables to get and store player's vehicleID? The presence of two arrays to store states of lights and engine is unnecessary as well, 'cause you can get these values via GetVehicleParamsEx. And then there is a lot of code repeating (declare, get, set).
I would recommend you adding this macro for checking key press on the top of script:
PHP код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
if(KeyPressed(KEY_LOOK_BEHIND))
{
SetVehicleParamsEx(vehicle, !engine, lights, alarm, doors, bonnet, boot, objective);
if(!engine) SendClientMessage(playerid, COLOR_YELLOW, "You have turned your engine >{FFFFFF} ON");
else SendClientMessage(playerid, COLOR_YELLOW, "You have turned your engine >{FFFFFF} OFF");
}
if(KeyPressed(KEY_NO))
{
SetVehicleParamsEx(vehicle, engine, !lights, alarm, doors, bonnet, boot, objective);
if(!lights) SendClientMessage(playerid, COLOR_YELLOW, "You have turned your lights >{FFFFFF} ON");
else SendClientMessage(playerid, COLOR_YELLOW, "You have turned your lights >{FFFFFF} OFF");
}
}
return 0;
}
I posted this Filterscript in the Brazilian area. You can translate and check if it's useful.