KeyCheck down
#1

Hi, im trying to get a boost when someone presses the key_down while driving im using on player update
I tested this code but it is only fired when i pres the downbutton on foot, however the downPressed message is shown when it should and the downReleased also. but still only on foot.
please help
Код:
public OnPlayerUpdate(playerid)
{
	new keys, updown, leftright;
	GetPlayerKeys(playerid, keys, updown, leftright);


	if(updown > 0 && pKey[playerid][1] != 1)
	{
		pKey[playerid][1] = 1; // Remember that they are pressing down
		print("downPressed");
	}
	if(!(updown > 0) && pKey[playerid][1] == 1){
 		pKey[playerid][1] = 0;
 		print("downReleased");
 		if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
		    new Float:x, Float:y, Float:z;
		    GetVehicleVelocity(playerid, x, y, z);
		    new playerVeh = GetPlayerVehicleID(playerid);
		    SetVehicleVelocity(playerVeh, x, y+50, z);
		    print("fired");
		}
	}
	return 1;
}
Edit:

I used the OnPlayerKeyStateChange with a different key so my problem is fixed. Thanks all
Reply
#2

man try this under onplayerkeystatechanged
Reply
#3

I tried, but onPlayerKeyStateChange doesn't fire when key_UP or key_Down is pressed
Reply
#4

It works, but y + 50 makes me go underground.
pawn Код:
public OnPlayerUpdate( playerid )
{
    new
        Keys,
        ud,
        lr
    ;
    GetPlayerKeys( playerid, Keys, ud, lr );
 
    if(ud > 0)
    {
        if( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
        {
            new
                Float:x,
                Float:y,
                Float:z
            ;
            GetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y, z );
            SetVehicleVelocity( GetPlayerVehicleID( playerid ), x, y + 50, z );
        }
    }
    return 1;
}
Reply
#5

I think there is a misunderstanding, i need to check for the down key to be pressed (KEY_DOWN or S) and not KEY_FIRE. Thanks for the answer though
Reply
#6

I thought another key, but then I realised that it's about up/down/left/right arrows, so I changed the code.
Read it and try it!
Reply
#7

Ok, great that works with the down key. Thanks . Does annyone know if you can also check for the "S" button or just a general backwards in vehicle button
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)