Help Animation

Hello,

I created a script to play animations from button. But I have two major problems:

  • I would like that if the players press the uncle while the animation is running, they stop the animation (buttonplay/stop)

  • Once the animation or scenario is launched, the player cannot move. I’d like as soon as he moves, it stops the animation.

function called when player click on button

function playAnim(data)
    if data.types == "animsAction" then
        RequestAnimDict(data.anim.lib)
        while not HasAnimDictLoaded(data.anim.lib) do
        Citizen.Wait(0)
        end
        if HasAnimDictLoaded(data.anim.lib) then
            TaskPlayAnim( GetPlayerPed(-1),data.anim.lib,data.anim.anim ,8.0, -8.0, -1, 0, 0, false, false, false )
        end
    elseif data.types == "animsActionScenario" then
        TaskStartScenarioInPlace( GetPlayerPed(-1), data.anim.anim, 0, false)
    end
end

Config data animation

animationAutreList ={
	{name ="Prendre des notes",anim ={ anim = "WORLD_HUMAN_CLIPBOARD" },type="animsActionScenario"},
	{name ="S assoir",anim ={ anim = "WORLD_HUMAN_PICNIC" },type="animsActionScenario"},
	{name ="Se gratter les couille",anim ={ lib = "mp_player_int_uppergrab_crotch", anim = "mp_player_int_grab_crotch" },type="animsAction"},
	{name ="Rock and Roll",anim ={ lib = "mp_player_int_upperrock", anim = "mp_player_int_rock" },type="animsAction"},
	{name ="Fumer une clope",anim ={ anim = "WORLD_HUMAN_SMOKING" },type="animsActionScenario"},
}
1 Like

Try taking a look at AB Software Development for a list of the GTA V natives, there could be a Boolean in there that could possibly detect player movement, if not take a look at some emote scripts and use it to inspire you. Hope I helped! :mascot:

Runtime is probably a better source for natives as its more relative to Five M

Also take a look at my code in Shit Script as it will help with what your trying todo

I’ll be sure to use this if I help other people in future, glad to see the poster marked this as a solution. Btw you’re shit script is rather interesting :stuck_out_tongue: :mascot:

1 Like

Thx you so mutch, all of your info has helped me.
So the solution is :

Function play/stop with button

function playAnim(data)
    local ped = GetPlayerPed(-1)
    if data.types == "animsAction" then
        if IsEntityPlayingAnim(ped, data.anim.lib, data.anim.anim, 3) then
            ClearPedTasksImmediately(ped)
            return
        end
        RequestAnimDict(data.anim.lib)
        while not HasAnimDictLoaded(data.anim.lib) do
        Citizen.Wait(0)
        end
        if HasAnimDictLoaded(data.anim.lib) then
            TaskPlayAnim(ped,data.anim.lib,data.anim.anim ,8.0, -8.0, -1, 0, 0, false, false, false )
        end
    elseif data.types == "animsActionScenario" then
        if IsPedUsingScenario(ped, data.anim.anim) then
            ClearPedTasksImmediately(ped)
            return
        end
        TaskStartScenarioInPlace(ped, data.anim.anim, 0, false)
    end
end

function cancel when player move

Citizen.CreateThread(function()
	  	while true do
		    Citizen.Wait(0)
                 if IsPedUsingAnyScenario(GetPlayerPed(-1)) then
                     if IsControlPressed(0, 32) or IsControlPressed(0, 33) or IsControlPressed(0, 34) or                         IsControlPressed(0, 35) or IsControlJustPressed(1, 8) or IsControlJustPressed(1, 9) then
                          ClearPedTasks(GetPlayerPed(-1))
                     end
                 end
		end
	end)
2 Likes

where would i add these functions ?

More info where to paste the code would be great.

Can you share your files?

https://forum.cfx.re/t/help-animation/114929/4
The solution was here. You just need to call playAnim with anim data. Format of data

data = {types= "animsAction",lib="",anim=""} => for animation
data = {types="animsActionScenario",anim=""}=>for sceneraio