[Help] Bind animation on key

Hello,

how can I bind an animation on a key?

Write a function… Inside this function you put the animation… Call the function if you specified Key is pressed/released

Can you write me an example? I don´t know how to write a function


Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)
		if IsControlJustReleased(0, 38) then --E
			Dostuff()
		end
	end
end)

function Dostuff()
	local Dict = "amb@world_human_push_ups@male@base"
	local Name  = "base"
	RequestAnimDict(Dict)
	while not HasAnimDictLoaded(Dict) do
		Citizen.Wait(100)
	end
	TaskPlayAnim(GetPlayerPed(-1), Dict, Name, 8.0, 8.0, -1, 50, 0, false, false, false)
end
1 Like

Thank you very much

How can i disable this animation in cars?

Check if the player is in a car, if so stop their animation

https://runtime.fivem.net/doc/natives/#_0xAAA34F8A7CB32098

https://runtime.fivem.net/doc/natives/#_0x997ABD671D25CA0B

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)
		if IsControlJustReleased(0, 38) then --E
			Dostuff()
		end
                if IsPedInAnyVehicle(PlayerPedId(), false) then
                CLEAR_PED_TASKS_IMMEDIATELY(Ped ped);
               end
	end
end)

function Dostuff()
	local Dict = "amb@world_human_push_ups@male@base"
	local Name  = "base"
	RequestAnimDict(Dict)
	while not HasAnimDictLoaded(Dict) do
		Citizen.Wait(100)
	end
	TaskPlayAnim(GetPlayerPed(-1), Dict, Name, 8.0, 8.0, -1, 50, 0, false, false, false)
end

Is this right?

CLEAR_PED_TASKS_IMMEDIATELY(Ped ped);

I have a feeling you clearly do not know how to use natives. However, you do have the vehicle stuff correct.

Fix this and it will probably work.

Yes, I don´t know how I use natives. What do I have to fix?

I edited a little bit. Is this right or totaly wrong?

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)               
		        if IsControlJustReleased(0, 182) then --E
			     Dostuff()
		        end
                        if IsPedInAnyVehicle(lPed, false) and IsPedSwimming(lPed) and IsPedShooting(lPed) and IsPedClimbing(lPed) and IsPedCuffed(lPed) and IsPedDiving(lPed) and IsPedFalling(lPed) and IsPedJumping(lPed) and IsPedJumpingOutOfVehicle(lPed) then
                        ClearPedTasksImmediately(GetPlayerPed(-1))
                        end
                end
	end
end)

function Dostuff()
	local Dict = "missfbi_s4mop"
	local Name  = "guard_idle_a"
	RequestAnimDict(Dict)
	while not HasAnimDictLoaded(Dict) do
		Citizen.Wait(100)
	end
	TaskPlayAnim(GetPlayerPed(-1), Dict, Name, 8.0, 8.0, -1, 50, 0, false, false, false)
end

@d0p3t ?

You know you could’ve tried it in the past 14 days to figure out if it works