Good Evening, I’m trying to make a fairly simple script that has a singular functionality. Press K to toggle a hand on holster animation on / off. Whilst trying to make this work I’ve encountered two errors being the following:
If I leave the server and join back, I have to restart the script for it to work again. If I don’t restart the script after leaving and reconnecting the “K” key bind doesn’t do anything until I’m in the server and restart the script manually whilst I’m in game.
My second issue is that when I press “K” to toggle my hand on holster animation it then gets stuck on the animation, once I press “K” and then when I press “K” again it acts like it wants to cancel the animation but then starts it again. There’s no way to exit the animation unless I switch peds from male to female or female to male.
I’ll provide a video of my second issue to better demonstrate.
Here’s the code I’ve wrote I’m fairly new to this so I apologize if it looks messy / messed up to some.
Just trying to learn coding for the first time lol.
local ped = PlayerPedId()
local IsHolstering = false
RegisterCommand('+holster', function(source)
if IsPedInAnyPoliceVehicle(ped, true) then
return
end
if IsPedArmed(ped, 4 | 2) then
return
end
if not HasAnimDictLoaded("anim@hlstr_7360_walk") then
RequestAnimDict("anim@hlstr_7360_walk")
while not HasAnimDictLoaded("anim@hlstr_7360_walk") do
Wait(0)
end
end
TaskPlayAnim(ped, 'anim@hlstr_7360_walk', 'holster_walk', 8.0, -8, 0.01, 49, 0, 0, 0, 0)
IsHolstering = true
if IsHolstering == true and IsControlJustPressed(0, defaultParameter) then
CancelEmote()
end
end)
RegisterKeyMapping('+holster', 'Hold Onto Your Holster', 'keyboard', 'K')
function CancelEmote()
StopAnimTask(ped, 'anim@hlstr_7360_walk', 'holster_walk', 1.0)
IsHolstering = false
end
Thank you for any help ahead of time.