Key detection
#1

Hi. Is it possible in the function OnPlayerKeyStateChange to detect if I press a certain key, in this case R?
If I have understood it right the binary code for R is 01010010 (found here: http://www.control.com/thread/1014156798). I tried using it in my code but it didn't work at all.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(01010010))
    {
        if(GetPlayerAmmo(playerid) == 0)
        {
            SetTimerEx("PistolReload", 3000, false, "d", playerid);
        }
        else
        {
            SendClientMessage(playerid, 0xAAAAAAAA, "You are not out of ammo yet");
        }
    }
    return 1;
}
Should I add " or '? I don't know.
Reply
#2

https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Reply
#3

You can't detect it.
https://sampwiki.blast.hk/wiki/GetPlayerKeys
There's the list which keys you can detect
Reply
#4

No, OnPlayerKeyStateChange is only called when GTA: San Andreas keys are pressed. Which is whatever the user has specified for certain actions, such as KEY_FIRE. That's what we go by, so if you want to code a key to do something, you need to think in terms of, "I want it to happen when the player presses the fire key" and not, "I want it to happen when the player presses the left mouse button", as player mappings may be different.

I hope this information helps.

Edit: Too late
Reply
#5

Quote:

The keys which are watched are not all keyboard keys, but just San Andreas assigned function keys, this means that, for example, you can't detect when someone presses the "A" key, but can detect when they press their sprint key (which may, or may not, be assigned to "A").

Okay, so it's not possible?

Edit: Ops, didn't notice so many replied already. Ignore the above.


Thanks!
Reply
#6

Quote:
Originally Posted by Omecken
Посмотреть сообщение
Okay, so it's not possible?
It is not possible, at all. Unless the player has mapped a San Andreas action to the 'R' key on their keyboard. Which you cannot force or check if they have done.
Reply
#7

Maybe someone could write a Plugin (NOT ME)
Reply
#8

That would have been perfect. Really would have needed this!
Reply
#9

Quote:
Originally Posted by Meta
Посмотреть сообщение
Maybe someone could write a Plugin (NOT ME)
That's not possible either without having an additional client that sends keystrokes to the server for the plugin to interperet. Quite like how the skin plugin works if you know of it, it requires an additional client to be run along side of SA-MP aswell as the server requiring a plugin for the custom skins to download.

In which case I think is somewhat pointless, since you need all of your players to download additional software to run as well as SA-MP, otherwise the keystrokes won't be sent to the server.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)