OnPlayerKeyStateChange
#1

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  new keys, updown, leftright;
    new Float:X, Float:Y, Float:Z;
    if (AirBreakMode[playerid] == 1)
    {
      GetPlayerKeys(playerid, keys, updown, leftright);

      if (updown == KEY_UP)
        {
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X, Y+2.5, Z);
            PlayerPlaySound(playerid, 1138, X, Y, Z);
        }
        else if (updown == KEY_DOWN)
        {
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X, Y-2.5, Z);
            PlayerPlaySound(playerid, 1138, X, Y, Z);
        }
       
        else if (leftright == KEY_RIGHT)
        {
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X+2.5, Y, Z);
            PlayerPlaySound(playerid, 1138, X, Y, Z);
        }
       
        else if (leftright == KEY_LEFT)
        {
            GetPlayerPos(playerid, X, Y, Z);
            SetPlayerPos(playerid, X-2.5, Y, Z);
            PlayerPlaySound(playerid, 1138, X, Y, Z);
        }
    }
    return 1;
}
I've been trying to make a little bit of code that when you type /amove. You enter a mode where you can press the UP, DOWN, LEFT, & RIGHT keys to move Y+/- and X+/-
It isn't going too well. I don't have much experience at all with OnPlayerKeyStateChange. When I press capslock though; my character moves Y-2.5. I need to know how to properly use this.
Reply
#2

Use "&" operator (bit and), e.g.:
pawn Код:
if (newkeys & KEY_ANALOG_UP)
{
    // Up arrow pressed
}
if (newkeys & KEY_ANALOG_LEFT)
{
    // left arrow pressed
}
....
etc.
Reply
#3

You can't detect keys UP, DOWN, LEFT or RIGHT at OnPlayerKeyStateChange callback, use GetPlayerKeys with the timer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)