OnPlayerKeyStateChange doesn't work
#1

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

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
Reply
#3

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
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)