Keys problem
#1

I have problem with this:
Quote:

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (PRESSED(KEY_LEFT))
{
SendClientMessage(playerid, COLOR_RED, "SEX!");
}
if (PRESSED(KEY_RIGHT))
{
SendClientMessage(playerid, COLOR_RED, "WTFOMGBBQ");
}
return 1;
}

The KEY_RIGHT is on right mouse click instead on keyboard and I can't find KEY_LEFT.
Reply
#2

The arrow keys do not call OnPlayerKeyStateChange, you need to use GetPlayerKeys.
Reply
#3

KEY_ANALOG_LEFT
KEY_ANALOG_RIGHT
Reply
#4

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & KEY_LEFT)
    {
        SendClientMessage(playerid, COLOR_RED, "SEX!");
    }
    if (newkeys & KEY_RIGHT)
    {
        SendClientMessage(playerid, COLOR_RED, "WTFOMGBBQ");
    }
    return 1;
}
Reply
#5

Analog left&right are the numpad left and right, and some laptops don't have that.

When I get home I can make a direction key callback for you
Reply
#6

//OnGamemode
Quote:

SetTimer("UpdateAll", 500, 1);

Quote:

forward UpdateAll();
public UpdateAll()
{
for(new i; i < MAX_PLAYERS; i ++)
{
if(PlayerInfo[i][pSelection] == 1)
{
new keys,ud,lr;
GetPlayerKeys(i,keys,ud,lr);
new rand = random(sizeof(RandomVeh));
if(lr == KEY_RIGHT)
{
SendClient..

}
else if(lr == KEY_LEFT)
{
SendClient..
}
}
}
return 1;
}

now this doesn't work.. OnPlayerUpdate is just updating everything too fast and I don't like it, and idk how to make if he "pressed" it (I don't want it to work if he holds it).
Reply
#7

Okay, then just make a variable to check if he has already pressed it or not and reset it when it's released. For example:

pawn Код:
new bool:Pressed[MAX_PLAYERS] = false;
pawn Код:
forward UpdateAll();
public UpdateAll()
{
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(PlayerInfo[i][pSelection] == 1 && Pressed[i] == false)
        {
            new keys,ud,lr;
            GetPlayerKeys(i,keys,ud,lr);
            new rand = random(sizeof(RandomVeh));
            if(lr > 0)
            {
                print("Right");
                Pressed[i] = true;
            }
            else if(lr < 0)
            {
                print("Left");
                Pressed[i] = true;
            }
            else Pressed[i] = false;
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)