SA-MP Forums Archive
Detect if player is HOLDING a key. - 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)
+--- Thread: Detect if player is HOLDING a key. (/showthread.php?tid=430166)



Detect if player is HOLDING a key. - PaulDinam - 12.04.2013

How can I detect it?
not pressing holding without leaving.


Re: Detect if player is HOLDING a key. - vvhy - 12.04.2013

pawn Код:
new bool:HoldingKey[MAX_PLAYERS];
   
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY && !HoldingKey[playerid])
    {
        KeyCheck(playerid);
        HoldingKey[playerid] = true;
    }

    return 1;
}

forward KeyCheck(playerid);
public KeyCheck(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        new
            keys, ud, lr;
           
        GetPlayerKeys(playerid, keys, ud, lr);
       
        if(keys & KEY)
        {
            SetTimerEx("KeyCheck", 100, 0, "i", playerid);
           
            return 0;
        }
    }
   
    HoldingKey[playerid] = false;
    return 0;
}
Credit Tannz0rz for this piece of code.


Re: Detect if player is HOLDING a key. - PaulDinam - 12.04.2013

When I use it, even if I press AIM key or ENTER key it works..
and I did
if(keys & KEY_FIRE)


Re: Detect if player is HOLDING a key. - MP2 - 12.04.2013

https://sampwiki.blast.hk/wiki/OnPlayerK..._holding_a_key