SA-MP Forums Archive
Function to check a certain animation - 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: Function to check a certain animation (/showthread.php?tid=563015)



Function to check a certain animation - MarcGonzales - 13.02.2015

Okay so I made a command to place your hands up

Код:
ApplyAnimation(playerid, "PED", "HANDSUP", 4.1, 0, 0, 0, 1, 0, 1);
Havn't tried it yet, though

Then wanted to make a command(/cuff) that applies only when the player has his hands up.

So, what's the function to check if the player has his hands up? Or has the animation on or something?

Thanks in advance.


Re: Function to check a certain animation - bartekdvd - 13.02.2015

Take a look at this:
https://sampwiki.blast.hk/wiki/GetPlayerAnimationIndex


Re: Function to check a certain animation - MarcGonzales - 13.02.2015

Quote:
Originally Posted by bartekdvd
Посмотреть сообщение
I did, and I'm not really sure how to apply this in my cuff command. Can you give me an example to check if the player has his hands up? Thanks.


Re: Function to check a certain animation - shadowdog - 13.02.2015

I think the easiest way would be to set a player variable for a player when he uses /handsup, and then check if the variable is true when you use /cuff.

If you're really into using the GetPlayerAnimationIndex
Approach like this:

Код:
new lib[32];
new index[32];
if(GetPlayerAnimationIndex(playerid)) GetAnimationName(GetPlayerAnimationIndex(playerid),lib,32,index,32);
if(strcmp(lib,"PED") == 0 && strcmp(index,"HANDSUP") == 0)
{
 //player will be cuffed
}
I did not test this


Re: Function to check a certain animation - bartekdvd - 13.02.2015

Here is an example:
pawn Код:
#include <a_samp>

bool:HasAnimationApplied(playerid, animlib[], animname[])
{
    new l_animlib[32];
    new l_animname[32];
    GetAnimationName(GetPlayerAnimationIndex(playerid),l_animlib,32,l_animname,32);
    if (strcmp(animlib, l_animlib, true) == 0 && strcmp(animname, l_animname, true) == 0)
        return true;
    return false;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    else if (strcmp("/up", cmdtext, true, 3) == 0)
    {
        ApplyAnimation(playerid, "PED", "HANDSUP", 4.1, 0, 0, 0, 1, 0, 1);
        return 1;
    }
    else if (strcmp("/down", cmdtext, true, 5) == 0)
    {
         ClearAnimations(playerid);
         return 1;
    }
    else if (strcmp("/isup", cmdtext, true, 5) == 0 )
    {
        if (HasAnimationApplied(playerid, "PED", "HANDSUP"))
            SendClientMessage(playerid, 0xFFFFFFFF, "HANDSUP");
        else
            SendClientMessage(playerid, 0xFFFFFFFF, "HANDSDOWN");
           
        return 1;
    }
    return 0;
}
I have tested it.