So the animation is setup but i am woundering if anyone knows how to attatch the weapon to the player once they reach above there head instead of when the animations ends as seen in the video below.
Video:
local weapons = {
`WEAPON_MICROSMG`,
`WEAPON_SMG`,
`WEAPON_ASSAULTSMG`,
`WEAPON_MINISMG`,
`WEAPON_MACHINEPISTOL`,
`WEAPON_COMBATPDW`,
`WEAPON_PUMPSHOTGUN`,
`WEAPON_SAWNOFFSHOTGUN`,
`WEAPON_ASSAULTSHOTGUN`,
`WEAPON_BULLPUPSHOTGUN`,
`WEAPON_HEAVYSHOTGUN`,
`WEAPON_ASSAULTRIFLE`,
`WEAPON_CARBINERIFLE`,
`WEAPON_ADVANCEDRIFLE`,
`WEAPON_SPECIALCARBINE`,
`WEAPON_BULLPUPRIFLE`,
`WEAPON_COMPACTRIFLE`,
`WEAPON_MG`,
`WEAPON_COMBATMG`,
`WEAPON_GUSENBERG`,
`WEAPON_SNIPERRIFLE`,
`WEAPON_HEAVYSNIPER`,
`WEAPON_MARKSMANRIFLE`,
`WEAPON_GRENADELAUNCHER`,
`WEAPON_RPG`,
`WEAPON_STINGER`,
`WEAPON_HOMINGLAUNCHER`,
`WEAPON_RAILGUN`,
`WEAPON_DBSHOTGUN`,
`WEAPON_AUTOSHOTGUN`,
`WEAPON_COMPACTLAUNCHER`,
`WEAPON_PIPEBOMB`,
`WEAPON_DOUBLEACTION`,
}
local holstered = true
local canFire = true
local currWeapon = `WEAPON_UNARMED`
Citizen.CreateThread(function()
currWeapon = GetSelectedPedWeapon(PlayerPedId())
while true do
Citizen.Wait(0)
local player = PlayerPedId()
if DoesEntityExist( player ) and not IsEntityDead( player ) and not IsPedInAnyVehicle(PlayerPedId(-1), true) and not IsPedInParachuteFreeFall(player) and GetPedParachuteState(player) == -1 then
if currWeapon ~= GetSelectedPedWeapon(player) then
pos = GetEntityCoords(player, true)
rot = GetEntityHeading(player)
local newWeap = GetSelectedPedWeapon(player)
SetCurrentPedWeapon(player, currWeapon, true)
if CheckWeapon(newWeap) then
if holstered then
canFire = false
grab2h()
SetCurrentPedWeapon(player, newWeap, true)
currWeapon = newWeap
Citizen.Wait(2000)
holstered = false
canFire = true
elseif newWeap ~= currWeapon and CheckWeapon(currWeapon) then
canFire = false
grab2h()
SetCurrentPedWeapon(player, GetHashKey('WEAPON_UNARMED'), true)
--ClearPedTasks(player)
grab2h()
SetCurrentPedWeapon(player, newWeap, true)
currWeapon = newWeap
Citizen.Wait(2000)
holstered = false
canFire = true
else
SetCurrentPedWeapon(player, GetHashKey('WEAPON_UNARMED'), true)
--ClearPedTasks(player)
grab2h()
SetCurrentPedWeapon(player, newWeap, true)
currWeapon = newWeap
Citizen.Wait(2000)
holstered = false
canFire = true
end
else
if not holstered and CheckWeapon(currWeapon) then
canFire = false
grab2h()
SetCurrentPedWeapon(player, GetHashKey('WEAPON_UNARMED'), true)
SetCurrentPedWeapon(player, newWeap, true)
holstered = true
canFire = true
currWeapon = newWeap
else
SetCurrentPedWeapon(player, newWeap, true)
holstered = false
canFire = true
currWeapon = newWeap
end
end
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if not canFire then
DisableControlAction(0, 25, true)
DisablePlayerFiring(player, true)
end
end
end)
function CheckWeapon(newWeap)
for i = 1, #weapons do
if weapons[i] == newWeap then
return true
end
end
return false
end
function loadAnimDict(dict)
while (not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Citizen.Wait(5)
end
end
function grab2h()
local dict = "amb@world_human_golf_player@male@idle_a"
local anim = "idle_a"
local ped = GetPlayerPed(-1)
loadAnimDict(dict)
TaskPlayAnim(ped, dict, anim, 1.5, 1.5, -1, 49, 10, 0, 0, 0)
Citizen.Wait(1100)
ClearPedTasks(ped)
end