How do I know when a player is running?
#1

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.
Reply
#2

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
Reply
#3

No. That will obviously not be efficient.
Reply
#4

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

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;
}
Reply
#6

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.
Reply
#7

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

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

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
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)