Looking to make a player unable to sprint after they break their leg.
#1

However, the message only gets sent when they press the key - not hold it. I don't want a player to spam press sprint, OR hold it. Is there anyway to prevent them from doing this?

pawn Код:
if (GetPlayerState(playerid) == 1 && (newkeys & KEY_SPRINT) && !(oldkeys & KEY_SPRINT))
    {
        if(PLAYER_BROKEN_LEGS[playerid] == true && HOLDING(KEY_SPRINT))
        {
            SCM(pid, COLOR_GREY, "You're unable to sprint, as your leg is broken.");
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z);
            ClearAnimations(playerid);
            return 1;
        }
    }
Reply
#2

Just perform the keys check once.
Modify the check:
pawn Код:
if (PLAYER_BROKEN_LEGS[playerid] == true && GetPlayerState(playerid) == 1 && HOLDING(KEY_SPRINT))
{
}
Reply
#3

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Just perform the keys check once.
Modify the check:
pawn Код:
if (PLAYER_BROKEN_LEGS[playerid] == true && GetPlayerState(playerid) == 1 && HOLDING(KEY_SPRINT))
{
}
Player can still hold the key and sprint. However, they can't spam press it which is good.
Reply
#4

Actually you need to check for movement keys as well. Since you have to use SPRINT key as well, use GetPlayerKeys under this callback.

Example:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PLAYER_BROKEN_LEGS[playerid] == true && GetPlayerState(playerid) == 1)
    {
        new keys, updown, leftright;
        GetPlayerKeys(playerid, keys, updown, leftright);

        if (HOLDING(KEY_WALK) && ((updown & KEY_UP || updown & KEY_DOWN) || (leftright & KEY_LEFT || leftright & KEY_RIGHT)))
        {
        }
    }

    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)