TaskPlayAnim not working

natives
help
animation

#1

I tried to play an animation for an npc and a player, but it wouldn’t work.
It was working before I changed my __resource.lua , but I don’t remember what it was.
All other things work except the RequestAnimDict and TaskPlayAnim.

My functions

			RequestAnimDict("idle_a")
			while (not HasAnimDictLoaded("amb@world_human_golf_player@male@idle_a")) do Citizen.Wait(0) end
			TaskPlayAnim(basePlayer,"amb@world_human_golf_player@male@idle_a","idle_a",1.0,-1.0, -1, 1, 1, true, true, true)
			RequestAnimDict("iron_idle_a")
			while (not HasAnimDictLoaded("mini@golfai")) do Citizen.Wait(0) end
			TaskPlayAnim(ped,"mini@golfai","iron_idle_a",1.0,-1.0, -1, 1, 1, true, true, true)

Values

local ped = CreatePed(type, hash, pos.x, pos.y, pos.z, pos.h, false, true)
local basePlayer = PlayerPedId()

Thanks in advance.


#2

Try this

RequestAnimDict("idle_a")
while (not HasAnimDictLoaded("idle_a")) do Citizen.Wait(0) end
TaskPlayAnim(basePlayer,"amb@world_human_golf_player@male@idle_a","idle_a",1.0,-1.0, -1, 1, 1, true, true, true)
RequestAnimDict("iron_idle_a")
while (not HasAnimDictLoaded("iron_idle_a")) do Citizen.Wait(0) end
TaskPlayAnim(ped,"mini@golfai","iron_idle_a",1.0,-1.0, -1, 1, 1, true, true, true)

#3

Still not working…


#4

The anim district is not idle_anything. Usually the idle is an animation IN the anim dict


#5

The “amb@world_human…” is the AnimDict the isles are the anims


#6

So I would flip them around?


#7
RequestAnimDict("idle_a")
while (not HasAnimDictLoaded("idle_a")) do Citizen.Wait(0) end
TaskPlayAnim(basePlayer,"amb@world_human_golf_player@male@idle_a","idle_a",1.0,-1.0, -1, 1, 1, true, true, true)
RequestAnimDict("iron_idle_a")
while (not HasAnimDictLoaded("iron_idle_a")) do Citizen.Wait(0) end
TaskPlayAnim(ped,"mini@golfai","iron_idle_a",1.0,-1.0, -1, 1, 1, true, true, true)

So leave the amb@wrld where it’s at. And also put it where the first two idles are. Then replace the first two iron idles with the mini@golf. Also leave the last mini@ where it is.

Also I’m sorry, I’m on mobile right now. I can totally explain better when i get home from work.

For now you can take a look at mine and use it for reference if youd like.


#8

I think I know what it is. After I got rid of my RegisterNetEvent, the animation part stopped working.

So I think the animations rely on the RegisterNetEvent.


#9

Depending on how you are trying to trigger the animations yes.

Here is a quick example for the middle finger animation using a RegisterCommand in nothing but a client.lua

“/bird”

RegisterCommand("bird",function(source, args)

	local ad = "anim@mp_player_intselfiethe_bird"
	local player = GetPlayerPed( -1 )
	
	if ( DoesEntityExist( player ) and not IsEntityDead( player )) then 
		loadAnimDict( ad )
		if ( IsEntityPlayingAnim( player, ad, "idle_a", 3 ) ) then 
			TaskPlayAnim( player, ad, "exit", 8.0, 1.0, -1, 49, 0, 0, 0, 0 )
			Wait (100)
			ClearPedSecondaryTask(GetPlayerPed(-1))
		else
			TaskPlayAnim( player, ad, "idle_a", 8.0, 1.0, -1, 49, 0, 0, 0, 0 )
			Wait (500)
		end     
	end
end, false)

I am working on the animations you have here but it seems to keep looping with the idle_a for some reason.

RegisterCommand("golf",function(source, args)
	while true do
	Wait(0)

	local ad = "amb@world_human_golf_player@male@idle_a"
	local ada = "idle_a"
	
	
	local ad2 =  "mini@golfai"
	local ad2a = "iron_idle_a"

	local ad4 = "amb@world_human_drinking@beer@male@exit"

	local basePlayer = GetPlayerPed(-1)
		if ( DoesEntityExist( basePlayer ) and not IsEntityDead( basePlayer )) then
		loadAnimDict( ad )
		loadAnimDict( ad2 )
		loadAnimDict( ad4 )
			if (IsEntityPlayingAnim(basePlayer, ad, ada, 3)) then
				TaskPlayAnim(basePlayer, ad4, "exit", 8.0, 1.0, -1, 49, 0, 0, 0, 0)
				Wait(1000)
				ClearPedSecondaryTask(basePlayer)
			else 
				TaskPlayAnim(basePlayer, ad, ada, 8.0, 1.0, -1, 49, 0, 0, 0, 0)
			end
		end
	end 
end, false)

Also if you dont want to have to type out the whole RequestAnims etc. You can use this function somewhere in the code, Then just put loadAnimDict(yourDictHere) at the top before anything relating to the choosen Dict.

function loadAnimDict(dict)
	while (not HasAnimDictLoaded(dict)) do
		RequestAnimDict(dict)
		Citizen.Wait(5)
	end
end

#10

I’m trying to trigger it with
if (IsControlPressed(0, 51))


#12

I need to start learning to make a backup of my file once it starts working. :laughing:


#13

BTW the (0, 38) im using is the [E] key.

Citizen.CreateThread(function()
		while true do
			Citizen.Wait(0)
			if IsControlJustPressed(0, 38) then then
				TaskPlayAnim(basePlayer, "amb@world_human_golf_player@male@idle_a", "idle_a", 8.0, 1.0, -1, 49, 0, 0, 0, 0)
			end
		end
	end)

Then you could use something like

if ( IsEntityPlayingAnim( player, "amb@world_human_golf_player@male@idle_a", "idle_a", 3 ) ) and IsControlJustPressed(0, 38) then
     -- your code to cancel or goto a different anim or whatever

Btw, where I have 49, thats the animation flags. I suggest looking at them and seeing which one you require. using 49 lets you do the anim on your upperbody AND walk around.

https://runtime.fivem.net/doc/reference.html#_0xEA47FE3719165B94

Here is the native, it has all the flags listed ^^^


#14

@davewazere How would I go on about have players do sit chair emote with out having them fly 1ft into the air

edit: a old clip


#15

I usually do something like this

SetEntityCoords(PlayerPedId(), 110.552, -1301.72, 27.7095, 240.968)
SetEntityHeading(PlayerPedId(), 211.968)
SetEntityCollision(playerPed,  false,  false)
FreezeEntityPosition(playerPed, true)
Wait(100)
TaskStartScenarioInPlace((playerPed, "PROP_HUMAN_SEAT_CHAIR", 0, false)

#16

It looks like you would have to lower their position. You could do something along the lines of

local x,y,z = table.unpack(GetEntityCoords(player, true))

then when they do the anim, use

SetEntityCoords(player, x, y, z-0.5, 1, 0, 0, 0)

With the z-0.5 being what would lower you on the z axis(up and down)

Youd prolly have to mess around with the value to your liking


#17

Alright have to give that a try…
oo and @davewazere I liked how you went around with this ‘RegisterCommand’ emote
my question is, Is their a way to add

WORLD_HUMAN_SMOKING_POT

With in this…so the prop is showen

RegisterCommand("bird",function(source, args)

	local ad = "amb@world_human_smoking_pot@female@base"
	local player = GetPlayerPed( -1 )
	
	if ( DoesEntityExist( player ) and not IsEntityDead( player )) then 
		loadAnimDict( ad )
		if ( IsEntityPlayingAnim( player, ad, "base", 3 ) ) then 
			TaskPlayAnim( player, ad, "exit", 8.0, 1.0, -1, 49, 0, 0, 0, 0 )
			Wait (100)
			ClearPedSecondaryTask(GetPlayerPed(-1))
		else
			TaskPlayAnim( player, ad, "base", 8.0, 1.0, -1, 49, 0, 0, 0, 0 )
			Wait (500)
		end     
	end
end, false)

#18

You release might have just given me that answer…


#19

I feel stupid… :man_facepalming:

So I looked very, very, VERY closely at my script and found out what was wrong.

Find the error

RequestAnimDict("idle_a")
while (not HasAnimDictLoaded("amb@world_human_golf_player@male@idle_a")) do Citizen.Wait(0) end
TaskPlayAnim(basePlayer,"amb@world_human_golf_player@male@idle_a","idle_a",1.0,-1.0, -1, 1, 1, true, true, true))
RequestAnimDict("iron_idle_a")
while (not HasAnimDictLoaded("mini@golfai")) do Citizen.Wait(0) end
TaskPlayAnim(ped,"mini@golfai","iron_idle_a",1.0,-1.0, -1, 1, 1, true, true, true)

PS: This one’s a little tough


#20

Extra ) on

TaskPlayAnim(basePlayer,“amb@world_human_golf_player@male@idle_a”,“idle_a”,1.0,-1.0, -1, 1, 1, true, true, true))

?


#21

Correct…
:+1: :+1: