SA-MP Forums Archive
Looking to make a player unable to sprint after they break their leg. - 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: Looking to make a player unable to sprint after they break their leg. (/showthread.php?tid=592223)



Looking to make a player unable to sprint after they break their leg. - rangerxxll - 22.10.2015

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



Re: Looking to make a player unable to sprint after they break their leg. - Gammix - 22.10.2015

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



Re: Looking to make a player unable to sprint after they break their leg. - rangerxxll - 22.10.2015

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.


Re: Looking to make a player unable to sprint after they break their leg. - Gammix - 22.10.2015

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