[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
#2

Cool, but little help
Reply
#3

Tottally needed this thank you sow much!

ps.:
Suggestion: put 3d text above the player saying "Joypadder"
Reply
#4

Quote:
Originally Posted by kacper55331
View Post
Cool, but little help
its not a beginner tutorial its a tutorial assuming you know wtf you are doing to solve a problem people thought was impossible in sa-mp previously.
Reply
#5

Quote:
Originally Posted by justsomeguy
View Post
Tottally needed this thank you sow much!

ps.:
Suggestion: put 3d text above the player saying "Joypadder"
Can't you be bothered to? Or can't?

This is practically showing us how to detect a joypadder, not to make fancy code .

Nice job whitetiger, awesome releases. Everything you make is pretty unique and your great dm'er :O
Reply
#6

This will work if I use it in OPKSC?
Reply
#7

Quote:
Originally Posted by whitetigerswt
View Post
its not a beginner tutorial its a tutorial assuming you know wtf you are doing to solve a problem people thought was impossible in sa-mp previously.
idc if you fucktards think its a well written tutorial.. this is just a way to detect joypad. its not an [FS]


Quote:

Instead you could have used OnPlayerKeyStateChange.....

OnPlayerKeyStateChange does not get called on up/down left/right changes...
Reply
#8

i'd suggest you use this maybe?:
pawn Code:
public OnPlayerConnect(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.");
        }
    return 1;
}
(not sure this even works! dont get mad at me! i havent tested it i only know that it does not give's errors!).
Reply
#9

Quote:
Originally Posted by justsomeguy
View Post
i'd suggest you use this maybe?:
pawn Code:
public OnPlayerConnect(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.");
        }
    return 1;
}
(not sure this even works! dont get mad at me! i havent tested it i only know that it does not give's errors!).
this would not work, because: when they connect and are not yet spawned GetPlayerKeys does not work at all, it only works when they are spawned, but even if it did work when they had just connected they would have to be holding down the up/down or left/right keys at the exact second that they connect.

you could do:

pawn Code:
new JoyPadders[MAX_PLAYERS];
OnPlayerUpdate(playerid) {
    if(JoyPadders[playerid] == 0) {
        new keys, ud, lr;
        GetPlayerKeys(playerid, keys, ud, lr);
        if((ud != 128 && ud != 0 && ud != -128) || (lr != 128 && lr != 0 && lr != -128))
            JoyPadders[playerid] = 1;
        else
            // nothing
    }
}
Reply
#10

Quote:
Originally Posted by whitetigerswt
View Post
this would not work, because: when they connect and are not yet spawned GetPlayerKeys does not work at all, it only works when they are spawned, but even if it did work when they had just connected they would have to be holding down the up/down or left/right keys at the exact second that they connect.

you could do:

pawn Code:
new JoyPadders[MAX_PLAYERS];
OnPlayerUpdate(playerid) {
    if(JoyPadders[playerid] == 0) {
        new keys, ud, lr;
        GetPlayerKeys(playerid, keys, ud, lr);
        if((ud != 128 && ud != 0 && ud != -128) || (lr != 128 && lr != 0 && lr != -128))
            JoyPadders[playerid] = 1;
        else
            // nothing
    }
}
No i tested it and when i connect it says: "Not a joypadder"(because i dont have an joypad connected:P).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)