#1

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ((newkeys & KEY_FIRE) && (IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
{
new vehicle = GetPlayerVehicleID(playerid);
AddVehicleComponent(vehicle, 1010);
}
else if ((newkeys & KEY_SECONDARY_ATTACK) && (IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
{
new vehicle = GetPlayerVehicleID(playerid);
RemoveVehicleComponent(vehicle, 1010);
}
}



Why doesnt the second attack works?
Reply
#2

Try without - else if - just - else -
Reply
#3

No, it's just if, because the player can be pressing two keys at the same time.

Try:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ((newkeys & KEY_FIRE) && (IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
{
new vehicle = GetPlayerVehicleID(playerid);
AddVehicleComponent(vehicle, 1010);
}
if ((newkeys & KEY_SECONDARY_ATTACK) && (IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
{
new vehicle = GetPlayerVehicleID(playerid);
RemoveVehicleComponent(vehicle, 1010);
}
return 1;
}
Reply
#4

None of them works.
Reply
#5

Quote:
Originally Posted by Christoffer
Посмотреть сообщение
None of them works.
PHP код:
if ((newkeys == KEY_FIRE) && (IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
{
new 
vehicle GetPlayerVehicleID(playerid);
AddVehicleComponent(vehicle1010);
}
if ((
newkeys == KEY_SECONDARY_ATTACK) && (IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
{
new 
vehicle GetPlayerVehicleID(playerid);
RemoveVehicleComponent(vehicle1010);
}
return 
1;

try this beacause newkeys return the number of the new key which is pressing
if you want all key numbers you can print them
PHP код:
printf("%d",newkeys); 
Reply
#6

pawn Код:
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

stock IsVehicleNosAble(vehicleid)
{
    new InvalidNosVehicles[MAX_INVALID_NOS_VEHICLES] =
    {
        581,523,462,521,463,522,461,448,468,586,
        509,481,510,472,473,493,595,484,430,453,
        452,446,454,590,569,537,538,570,449
    };
    for(new i; i<sizeof(InvalidNosVehicles); i++) if(InvalidNosVehicles[i] == vehicleid) return 0;
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(KEY_FIRE) && (IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
    {
        new vehicle = GetPlayerVehicleID(playerid);
        if(IsVehicleNosAble(vehicle) AddVehicleComponent(vehicle, 1010);
    }
    /*if (PRESSED(KEY_SECONDARY_ATTACK) && (IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
    {
         new vehicle = GetPlayerVehicleID(playerid);
         if(IsVehicleNosAble(vehicle) RemoveVehicleComponent(vehicle, 1010);
    }*/

    return 1;
}
Although KEY_SECONDARY_ATTACK is the key ENTER which will exit you from the car making the statement invalid.
Reply
#7

I changed KEY_SECONDARY_ATTACK to KEY_ACTION and then it worked like it should. Thanks guys!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)