SA-MP Forums Archive
Keys problem - 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: Keys problem (/showthread.php?tid=208444)



Keys problem - Exxious - 08.01.2011

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.


Re: Keys problem - JaTochNietDan - 08.01.2011

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


Re: Keys problem - Mr.Stranger - 08.01.2011

KEY_ANALOG_LEFT
KEY_ANALOG_RIGHT


Re: Keys problem - HyperZ - 08.01.2011

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;
}



Re: Keys problem - Joe Staff - 08.01.2011

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


Re: Keys problem - Exxious - 09.01.2011

//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).


Re: Keys problem - JaTochNietDan - 09.01.2011

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;
}