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
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!
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
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)