OnPlayerKeyStateChange doesn't work - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: OnPlayerKeyStateChange doesn't work (
/showthread.php?tid=278559)
OnPlayerKeyStateChange doesn't work -
Padarom - 22.08.2011
Hello everyone,
I have quite a big problem, but I dont know how to solve it. Currently I have a menu (out of textdraws) when connecting, where you have to select whether you want to login/register, forgot password or change your name.
I wanted this menu to be used with arrow keys (key_up & key_down), but when I press them nothing happens.
Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (Menu[playerid] != 0)
{
if ((newkeys & (KEY_UP)) == (KEY_UP))
{
if (Menu[playerid] == 1)
{
Menu[playerid] = 2;
TextDrawSetOutline(Welcomesz, 1);
TextDrawSetOutline(Welcomese, 0);
}
if (Menu[playerid] == 2)
{
Menu[playerid] = 3;
TextDrawSetOutline(Welcomesd, 1);
TextDrawSetOutline(Welcomesz, 0);
}
}
if ((newkeys & (KEY_DOWN)) == (KEY_DOWN))
{
if (Menu[playerid] == 3)
{
Menu[playerid] = 2;
TextDrawSetOutline(Welcomesz, 1);
TextDrawSetOutline(Welcomesd, 0);
}
if (Menu[playerid] == 2)
{
Menu[playerid] = 1;
TextDrawSetOutline(Welcomese, 1);
TextDrawSetOutline(Welcomesz, 0);
}
}
}
return 1;
}
I hope you can help me.
Regards
Padarom
Re: OnPlayerKeyStateChange doesn't work -
Padarom - 22.08.2011
Well, I would try it out in OnPlayerUpdate instead, but I have no idea on how to use GetPlayerKeys. Can you please give me a hint? (playerid, &keys, &updown, &leftright) from wiki doesn't help me to explain this function :/
thanks
Padarom
Re: OnPlayerKeyStateChange doesn't work -
Padarom - 22.08.2011
Yep, it helped me- Thanks. But it still doesn't work... Could this be, because the player is still in ClassSelection (the menu is shown on OnPlayerConnect -> ClassSelection and the player is refused to spawn until logged in)? But also when I force-spawn the player on OnPlayerConnect it doesn't work
pawn Code:
public OnPlayerUpdate(playerid)
{
GetPlayerKeys(playerid,Keys[playerid],ud[playerid],lr[playerid]);
if (Menu[playerid] != 0)
{
if (ud[playerid] > 0)
{
if (Menu[playerid] == 1)
{
Menu[playerid] = 2;
TextDrawSetOutline(Welcomesz, 1);
TextDrawSetOutline(Welcomese, 0);
}
if (Menu[playerid] == 2)
{
Menu[playerid] = 3;
TextDrawSetOutline(Welcomesd, 1);
TextDrawSetOutline(Welcomesz, 0);
}
}
else if (ud[playerid] < 0)
{
if (Menu[playerid] == 3)
{
Menu[playerid] = 2;
TextDrawSetOutline(Welcomesz, 1);
TextDrawSetOutline(Welcomesd, 0);
}
if (Menu[playerid] == 2)
{
Menu[playerid] = 1;
TextDrawSetOutline(Welcomese, 1);
TextDrawSetOutline(Welcomesz, 0);
}
}
}
return 1;
}
Thanks again for your help
Padarom
Re: OnPlayerKeyStateChange doesn't work -
Padarom - 23.08.2011
Looks like, I've printed out every key I pressed in OnPlayerUpdate at ClassSelection and nothing was in the log. Now I've solved it with spawning, and afterwards the menu shows up. But now I've got another problem: The outline of the text doesn't change. Everytime I press KEY_UP or KEY_DOWN the outline of the textdraws stay, but the bool menu is changed.