[Tutorial] How to detect joypad.
#1

To detect joypad is very simple, it is not complicated as people think.

pawn Code:
new keys, ud, lr;
GetPlayerKeys(playerid, ud, lr);
When you are using a keyboard, you are not using a joystick, when using a keyboard you are either pressing down the key, or you are not. When you are pressing down a key it will return either 128, or -128 (128 = down, -128 = up, 0 = neither, and the same for left and right) however, when you are using a joystick since it is not a "is the key down or not" but rather a stick that can be moved around in a circular motion a range of values (could return anything from -128 to 128 ), could be used.

So, contrary to popular belief, you do not need to do some insane math functions to detect aim and etc etc, this is False. all you need is the following.


pawn Code:
OnPlayerUpdate(playerid) {
    new keys, ud, lr;
    GetPlayerKeys(playerid, keys, ud, lr);
    if((ud != 128 && ud != 0 && ud != -128) || (lr != 128 && lr != 0 && lr != -128))
        SendClientMessage(playerid, 0x0FFFFFFA, "JOYPADDER!");
    else
        SendClientMessage(playerid, 0x0FFFFFFA, "Not a joypadder.");
}
Reply


Messages In This Thread
How to detect joypad. - by Whitetiger - 10.05.2011, 05:56
Re: How to detect joypad. - by kacper55331 - 10.05.2011, 05:57
Re: How to detect joypad. - by justsomeguy - 10.05.2011, 09:31
Re: How to detect joypad. - by Whitetiger - 11.05.2011, 05:52
Re: How to detect joypad. - by Lorenc_ - 11.05.2011, 08:06
Re: How to detect joypad. - by Gh0sT_ - 11.05.2011, 10:44
Re: How to detect joypad. - by Whitetiger - 11.05.2011, 10:45
Re: How to detect joypad. - by justsomeguy - 11.05.2011, 19:19
Re: How to detect joypad. - by Whitetiger - 11.05.2011, 22:43
Re: How to detect joypad. - by justsomeguy - 21.05.2011, 09:33

Forum Jump:


Users browsing this thread: 1 Guest(s)