SA-MP Forums Archive
KeyCheck down - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: KeyCheck down (/showthread.php?tid=423760)



KeyCheck down - klotebandit - 19.03.2013

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


Re: KeyCheck down - CBCandyBoy - 19.03.2013

man try this under onplayerkeystatechanged


Re: KeyCheck down - klotebandit - 19.03.2013

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


Re: KeyCheck down - Konstantinos - 19.03.2013

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;
}



Re: KeyCheck down - klotebandit - 19.03.2013

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


Re: KeyCheck down - Konstantinos - 19.03.2013

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!


Re: KeyCheck down - klotebandit - 19.03.2013

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