[Confused] Playing Animation On The Player

@Lex_The_Great said in [Confused] Playing Animation On The Player:

I got it working. Here is a way to use it if anyone needs to run animations!

Citizen.CreateThread(function()
    local pid = PlayerPedId()
    RequestAnimDict("random")
    RequestAnimDict("random@arrests")
    RequestAnimDict("random@arrests@busted")
    while (not HasAnimDictLoaded("random@arrests@busted")) do Citizen.Wait(0) end
    TaskPlayAnim(pid,"random@arrests","idle_2_hands_up",1.0,-1.0, 5000, 0, 1, true, true, true)
end)

Don’t know if you need all 3 RequestAnimDict’s but I did it and it worked :tada:

EDIT: This can only be run on the client, so fire an event from the server to the client like:

-Server
TriggerClientEvent('arrestme', target)
-Client
RegisterNetEvent("arrestme")
AddEventHandler('arrestme', function()
    Here
end)

Hello, I’m looking to force an animation on a player. The Event is working but I can’t get the animation to run. I think I’m misusing the function.

After searching around I found this, but it still didn’t work. I just get “Got arrestme” (My debug text) in the chat in-game.

Thanks in advance.

PS Is there a better way to get a list of the players? I currently put each player that joins in a list for later, and call a function I created getPlayerByName()

2 Likes

Alright after doing more searching I came up with this:

RegisterNetEvent("arrestme")
RegisterNetEvent("cuffme")
AddEventHandler('arrestme', function()
	TriggerEvent('chatMessage', 'SYSTEM', {0, 255, 0}, "Got arrestme")
	Citizen.CreateThread(function()
		local pid = PlayerPedId()
		while (not HasAnimDictLoaded("random@arrests@busted")) do Citizen.Wait(10) end
		TaskPlayAnim(pid,"random@arrests@busted","enter",2.0,-2.0,-1,49,0, true, false, true)
	end)
end)

I get no errors in the server or client logs but nothing happens in-game apart from the NetEvent arrestme fire’n

2 Likes

Did u look at the HandsUp script? Maybe it can help!- I’ll do some test’s later my self and get back to you.

1 Like

Yeah I looked at it, it uses the native function TaskHandsUp() to play the animation.

function TaskHandsUp(ped, duration, facingPed, p3, p4)

I’ve looked on multiple sites and most of them say different things about how to use this function. Not sure what works because I’ve tried them with no success…
function TaskPlayAnim(ped, animDictionary, animationName, speed, speedMultiplier, duration, flag, playbackRate, lockX, lockY, lockZ)

2 Likes

Hmm, Can’t say I can get it to work.
Have u looked into

function TaskPlayAnimAdvanced(p0, animDict, animName, posX, posY, posZ, rotX, rotY, rotZ, speed, speedMultiplier, duration, flag, animTime, p14, p15)

U know what this do:

SetEnableHandcuffs(GetPlayerPed(-1))
1 Like

Still nothing:

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if IsControlJustPressed(0, 323) then --Start holding X
            TaskArrestPed(GetPlayerPed(-1), 1000, GetPlayerPed(-1), -1, true) -- Perform animation.
             RequestAnimDict("random@arrests@busted")
             RequestAnimDict("get_up@cuffed")
            TaskPlayAnim("random@arrests@busted")
            TaskPlayAnim("get_up@cuffed")
        end
    end
end)
1 Like

hmm make sure to use the right natives, http://www.dev-c.com/nativedb/

1 Like

@GanjaMonster I just saw your post here https://forum.fivereborn.com/topic/2112/how-to-play-an-animation-in-lua/7
Have u had any success since?

1 Like

i personally have not but i know some people got it working but its not public

1 Like

@GanjaMonster U have any idea if we are way off? I don’t understand that non-public way. Jesus it’s just an animation.

1 Like

well mine is set that its per command not a button key press

1 Like

@GanjaMonster Okay. No problem I have the ability to make it as a command. What else :smiley:

1 Like

well need to make a function for the command and i think i would try a different native maybe but u need the client and server script to make sure it works right

1 Like

@GanjaMonster Ok. U are making me sweat for it. So maybe the “TaskPlayAnimAdvanced” would be a nice choice-. Do u know what the first param is “p0” is? Is it PlayerId,PlayerPedID or even GetPlayerPed(-1)? U know when to use what? :=)

1 Like

@kanersps @Boss these guys might be able to help you it depends how u script it in the function

1 Like

I got it working. Here is a way to use it if anyone needs to run animations!

Citizen.CreateThread(function()
    local pid = PlayerPedId()
    RequestAnimDict("random")
    RequestAnimDict("random@arrests")
    RequestAnimDict("random@arrests@busted")
    while (not HasAnimDictLoaded("random@arrests@busted")) do Citizen.Wait(0) end
    TaskPlayAnim(pid,"random@arrests","idle_2_hands_up",1.0,-1.0, 5000, 0, 1, true, true, true)
end)

Don’t know if you need all 3 RequestAnimDict’s but I did it and it worked :tada:

EDIT: This can only be run on the client, so fire an event from the server to the client like:

-Server
TriggerClientEvent('arrestme', target)
-Client
RegisterNetEvent("arrestme")
AddEventHandler('arrestme', function()
    Here
end)
2 Likes

@GanjaMonster Like said in the op; “The Event is working but I can’t get the animation to run.” :stuck_out_tongue: I’m experienced in many languages (And lua is one) it’s just there is no information on how to use most of the functions. I had to look around, and found 2 different ways to use Wait() and CreateThread, but the working one is Citizen.Wait() and Citizen.CreateThread. The native functions are worse no idea what does what just putting numbers in places and it worked D:

I’ll release my full rp player arrest script when it’s done just have to setup walking when hands are cuffed :tada:

I got the two commands finished so far have to get detaining working :santa:
/arrest PlayerName
/cuff PlayerName

1 Like

https://forum.fivereborn.com/topic/2587/wiki-server-functions

some of these might help

1 Like

@Lex_The_Great That’s freaking awesome. Thanks for sharing and looking forward to your release :slight_smile:

2 Likes

@Lex_The_Great said in [Confused] Playing Animation On The Player:

I got the two commands finished so far have to get detaining working
/arrest PlayerName
/cuff PlayerName

Can’t it be PlayerId instad of name?
I just tried every thing and I can’t get it to work. Am just testing on my own player which should also work right?

1 Like