Help, engine system with keys
#1

PHP код:
#define PRESSED(%0) \
    
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) //Detecting keys 
PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if (
PRESSED(KEY_FIRE))
    {
        if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new 
str[60], vehicle GetPlayerVehicleID(playerid);
        
GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
        if(
engine != 1)
        {
            
SetVehicleParamsEx(vehicle,1,1,alarm,doors,bonnet,boot,objective);
            
format(strsizeof(str), "* %s accende il motore del veicolo"GetICName(playerid));
            
SendNearByMessage(playeridACTION_COLORstr10);
            }
        if (
PRESSED (KEY_JUMP))
        {
            
SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);
            
format(strsizeof(str), "* %s spegne il motore del veicolo"GetICName(playerid)); /// this is the message that appears the first time I type /engine, even if the vehicle is turned off
            
SendNearByMessage(playeridACTION_COLORstr10);
            }
        }
        }
    return 
1;
    } 
As soon as I get on a vehicle and press a button, the vehicle lights.
Then, however, does not turn off in any way.
Reply
#2

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(KEY_FIRE))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new str[60], vehicle = GetPlayerVehicleID(playerid);
            GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
            if(engine != 1 && lights !=1)
            {
                SetVehicleParamsEx(vehicle,1,1,alarm,doors,bonnet,boot,objective);
                format(str, sizeof(str), "* %s accende il motore del veicolo", GetICName(playerid));
                SendNearByMessage(playerid, ACTION_COLOR, str, 10);
            }
        }
    }
    if (PRESSED (KEY_JUMP))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new str[60], vehicle = GetPlayerVehicleID(playerid);
            GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
            if(engine == 1 && lights ==1)
            {
                SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);
                format(str, sizeof(str), "* %s spegne il motore del veicolo", GetICName(playerid)); /// this is the message that appears the first time I type /engine, even if the vehicle is turned off
                SendNearByMessage(playerid, ACTION_COLOR, str, 10);
            }
        }
    }
    return 1;
}
You were checking the KEY_JUMP inside the KEY_FIRE. And I have added a check for lights also.
Reply
#3

Thanks a lot, I solved ...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)