How to detect joypad. -
Whitetiger - 10.05.2011
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.");
}
Re: How to detect joypad. -
kacper55331 - 10.05.2011
Cool, but little help
Re: How to detect joypad. -
justsomeguy - 10.05.2011
Tottally needed this thank you sow much!
ps.:
Suggestion: put 3d text above the player saying "Joypadder"
Re: How to detect joypad. -
Whitetiger - 11.05.2011
Quote:
Originally Posted by kacper55331
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.
Re: How to detect joypad. -
Lorenc_ - 11.05.2011
Quote:
Originally Posted by justsomeguy
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
Re: How to detect joypad. -
Gh0sT_ - 11.05.2011
This will work if I use it in OPKSC?
Re: How to detect joypad. -
Whitetiger - 11.05.2011
Quote:
Originally Posted by whitetigerswt
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...
Re: How to detect joypad. -
justsomeguy - 11.05.2011
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!).
Re: How to detect joypad. -
Whitetiger - 11.05.2011
Quote:
Originally Posted by justsomeguy
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
}
}
Re: How to detect joypad. -
justsomeguy - 21.05.2011
Quote:
Originally Posted by whitetigerswt
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).