[HELP] Engine Car
#1

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;
}
Reply
#2

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 код:
#define KeyPressed(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) 
and rewrite code to something like this:
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new 
vehicleid GetPlayerVehicleID(playerid), enginelightsalarmdoorsbonnetbootobjective;
        
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
        if(
KeyPressed(KEY_LOOK_BEHIND))
        {
            
SetVehicleParamsEx(vehicle, !enginelightsalarmdoorsbonnetbootobjective);
            if(!
engineSendClientMessage(playeridCOLOR_YELLOW"You have turned your engine >{FFFFFF} ON");
            else 
SendClientMessage(playeridCOLOR_YELLOW"You have turned your engine >{FFFFFF} OFF");
        }
        if(
KeyPressed(KEY_NO))
        {
            
SetVehicleParamsEx(vehicleengine, !lightsalarmdoorsbonnetbootobjective);
            if(!
lightsSendClientMessage(playeridCOLOR_YELLOW"You have turned your lights >{FFFFFF} ON");
            else 
SendClientMessage(playeridCOLOR_YELLOW"You have turned your lights >{FFFFFF} OFF");
        }
    }
    return 
0;

I didn't checked if it is valid, hope it helps.
Reply
#3

I posted this Filterscript in the Brazilian area. You can translate and check if it's useful.
https://sampforum.blast.hk/showthread.php?tid=503069
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)