GetPlayerKeys released state
#1

is there any possible way to check if left, right key been released ?
im using GetPlayerKeys in onplayerupdate callback, not OnPlayerKeyStateChange
Reply
#2

pawn Код:
new lastKeyStatus[MAX_PLAYERS][2];

public OnPlayerConnect(playerid)
{
    lastKeyStatus[playerid][0] = 0;
    lastKeyStatus[playerid][1] = 0;
    return 1;
}

public OnPlayerUpdate(playerid)
{
    new keys, upDown, leftRight;
    GetPlayerKeys(playerid, keys, upDown, leftRight);

    if(upDown < 0)
    {
        // up
    }
    else if(upDown > 0)
    {
        // down
    }

    if(leftRight < 0)
    {
        // left
    }
    else if(leftRight > 0)
    {
        // right
    }

    if(leftRight == 0 && leftRight != lastKeyStatus[playerid][0])
    {
        if(leftRight < 0)
        {
             // left released
        }
        else if(leftRight > 0)
        {
            // right released
        }
    }

    if(upDown == 0 && upDown != lastKeyStatus[playerid][1])
    {
        if(upDown < 0)
        {
             // up released
        }
        else if(upDown > 0)
        {
            // down released
        }
    }

    lastKeyStatus[playerid][0] = upDown;
    lastKeyStatus[playerid][1] = leftRight;
    return 1;
}
Untested.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)