SA-MP Forums Archive
How do I know when a player is running? - 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: How do I know when a player is running? (/showthread.php?tid=559230)



How do I know when a player is running? - Crayder - 21.01.2015

Like the title says, how do I know when a player is running? GetPlayerAnimationIndex won't actually work because it only tells the truth when the animation is executed.


Re: How do I know when a player is running? - Sawalha - 21.01.2015

by getting his velocity
pawn Код:
new Float:VX, Float:VY, Float:VZ;
GetPlayerVelocity(playerid, VX, VY, VZ);
if(VX > 5.0 || VY > 5.0 || VZ > 5.0)
{
      /* code */
}
not tested


Re: How do I know when a player is running? - Crayder - 21.01.2015

No. That will obviously not be efficient.


Re: How do I know when a player is running? - xVIP3Rx - 21.01.2015

Check if he's holding the "running" key while on foot ?


Re: How do I know when a player is running? - Schneider - 21.01.2015

This works:
pawn Код:
stock IsPlayerRunning(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    if(IsPlayerInAnyVehicle(playerid)) return 0;
    new keys, updown, leftright;
    GetPlayerKeys(playerid, keys, updown, leftright);
    if(keys & KEY_SPRINT) return 1;
    return 0;
}



Re: How do I know when a player is running? - Crayder - 21.01.2015

No, that won't work in my situation either unfortunately. I'm not "using player ped anims" (UsePlayerPedAnims). I'm applying the run anim to certain players.


Re: How do I know when a player is running? - Schneider - 21.01.2015

Well, this function just detects if the player is holding the sprint-key and if he does, it returns 1... simple as that..


Re: How do I know when a player is running? - Crayder - 21.01.2015

The players don't need to hold it if the animation is set to run -.-


AW: How do I know when a player is running? - Nero_3D - 22.01.2015

Well if you are forcing the player to run scriptwise with animations than just use a flag that you set to true if you apply it and to false if the anim stoppes


Re: How do I know when a player is running? - xVIP3Rx - 22.01.2015

Or, check if you forced him to run
pawn Код:
//untested
stock IsPlayerRunning(playerid)
{
    if(!IsPlayerConnected(playerid) || IsPlayerInAnyVehicle(playerid)) return 0;

    new keys, updown, leftright;
    GetPlayerKeys(playerid, keys, updown, leftright);
    if(keys & KEY_SPRINT) return 1;

    if(GetPlayerAnimationIndex(playerid))
    {
        new animlib[32], animname[32];
        GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
        if(!strcmp(animlib, "PED"))
        {
            new const names[8][] = { "run_fat", "run_fatold", "run_old", "swat_run", "woman_run", "WOMAN_runbusy", "woman_runpanic", "WOMAN_runsexy" };

            for(new i; i < sizeof(names); i++)
            {
                if(!strcmp(animname, names[i])) return 1;
            }
        }
    }
    return 0;
}