Add animation when player give item

I would like to add an animation when people give object eachother. I tried to find it but i cannot find a solution for this. I will be gratefull if somebody will help. Thx

1 Like

what do you use for you invetory/item giving? ESX?

yes i use esx

I’m not familiar with ESX, but you’ll likely have to find what part of ESX handles giving objects and simply play an animation like any other situation. E.g. load the animation and play it, etc. TaskPlayAnim(ped, "missminuteman_1ig_2", "handsup_enter", 8.0, 8.0, 20, 50, 0, false, false, false)
The annoying part is finding the animation you’re looking for.

the point idk where to put this taskanim to show when they pass items eachother :confused:

Have a look at around line 962 here in ESX source code. It seems to deal with the giving of items/objects/resources/whatever to other players. Again, I’ve never used ESX and this is what I could find with a few minutes of looking at the source code. If it isn’t what you’re looking for you could try reaching out to one of the repository maintainers.

https://github.com/ESX-Org/es_extended/blob/master/client/functions.lua

1 Like

im not able to find a solution im really confused about that. nobody knows?

Following, interested too

nobody can give an answer?

1 Like

anyone know how to do that?

You could add a TriggerClientEvent(“esx:giveAnimation”, playerId)

then add a client event,

function loadAnimDict(dict)
    while not HasAnimDictLoaded(dict) do
        RequestAnimDict(dict)
        
        Citizen.Wait(1)
    end
end

RegisterNetEvent('esx:giveAnimation')
AddEventHandler('esx:giveAnimation', function()
       local playerPed = PlayerPedId()
       loadAnimDict('mp_common')
       TaskPlayAnim(playerPed, "mp_common", "givetake1_a", 8.0, 8.0, 20, 50, 0, false, false, false)
end)

And note that this timing might be incorrect so you need to tinker with it your self.

These are the parameters that TaskPlayAnim native takes

TaskPlayAnim(
	ped --[[ Ped ]], 
	animDictionary --[[ string ]], 
	animationName --[[ string ]], 
	blendInSpeed --[[ number ]], 
	blendOutSpeed --[[ number ]], 
	duration --[[ integer ]], 
	flag --[[ integer ]], 
	playbackRate --[[ number ]], 
	lockX --[[ boolean ]], 
	lockY --[[ boolean ]], 
	lockZ --[[ boolean ]]
)

I have not yet tested this code but it should work, cheers

1 Like

not work for me, u can help me? :smiley:

ty bro

Please show me all the code that you have changed, don’t just say “it does not work” what can I help you if I don’t know anything

1 Like

server:

client :

i try everything, but dont work … thank mate

yea its because you did not follow it correctly in the server.
You need to change the

TriggerClientEvent('esx:giveAnimation', sourceXPlayer, targetXPlayer

to

TriggerClientEvent('esx:giveAnimation', playerId)
2 Likes

dont work bro, i dnt know the problem … work for u?

client :

function loadAnimDict(dict)
    while not HasAnimDictLoaded(dict) do
        RequestAnimDict(dict)
        
        Citizen.Wait(1)
    end
end

RegisterNetEvent('esx:giveAnimation')
AddEventHandler('esx:giveAnimation', function()
	local playerPed = PlayerPedId()
	loadAnimDict('mp_common')
	TaskPlayAnim(playerPed, "mp_common", "givetake1_a", 8.0, 8.0, 20, 50, 0, false, false, false)
end)

server :

RegisterNetEvent('esx:giveInventoryItem')

AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)

    local playerId = source

    local sourceXPlayer = ESX.GetPlayerFromId(playerId)

    local targetXPlayer = ESX.GetPlayerFromId(target)

    if type == 'item_standard' then

        local sourceItem = sourceXPlayer.getInventoryItem(itemName)

        if itemCount > 0 and sourceItem.count >= itemCount then

            if targetXPlayer.canCarryItem(itemName, itemCount) then

                sourceXPlayer.removeInventoryItem(itemName, itemCount)

                targetXPlayer.addInventoryItem   (itemName, itemCount)

                sourceXPlayer.showNotification(_U('gave_item', itemCount, sourceItem.label, targetXPlayer.name))

                targetXPlayer.showNotification(_U('received_item', itemCount, sourceItem.label, sourceXPlayer.name))

                sourceXPlayer.triggerEvent('esx:giveAnimation')

                targetXPlayer.triggerEvent('esx:giveAnimation')

            else

                sourceXPlayer.showNotification(_U('ex_inv_lim', targetXPlayer.name))

            end

        else

            sourceXPlayer.showNotification(_U('imp_invalid_quantity'))

        end

    elseif type == 'item_account' then

        if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then

            sourceXPlayer.removeAccountMoney(itemName, itemCount)

            targetXPlayer.addAccountMoney   (itemName, itemCount)

            sourceXPlayer.showNotification(_U('gave_account_money', ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName], targetXPlayer.name))

            targetXPlayer.showNotification(_U('received_account_money', ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName], sourceXPlayer.name))

            sourceXPlayer.triggerEvent('esx:giveAnimation')

            targetXPlayer.triggerEvent('esx:giveAnimation')

        else

            sourceXPlayer.showNotification(_U('imp_invalid_amount'))

        end

    elseif type == 'item_weapon' then

        if sourceXPlayer.hasWeapon(itemName) then

            local weaponLabel = ESX.GetWeaponLabel(itemName)

            if not targetXPlayer.hasWeapon(itemName) then

                local _, weapon = sourceXPlayer.getWeapon(itemName)

                local _, weaponObject = ESX.GetWeapon(itemName)

                itemCount = weapon.ammo

                sourceXPlayer.removeWeapon(itemName)

                targetXPlayer.addWeapon(itemName, itemCount)

                if weaponObject.ammo and itemCount > 0 then

                    local ammoLabel = weaponObject.ammo.label

                    sourceXPlayer.showNotification(_U('gave_weapon_withammo', weaponLabel, itemCount, ammoLabel, targetXPlayer.name))

                    targetXPlayer.showNotification(_U('received_weapon_withammo', weaponLabel, itemCount, ammoLabel, sourceXPlayer.name))

                    

                    sourceXPlayer.triggerEvent('esx:giveAnimation')

                    targetXPlayer.triggerEvent('esx:giveAnimation')

                else

                    sourceXPlayer.showNotification(_U('gave_weapon', weaponLabel, targetXPlayer.name))

                    targetXPlayer.showNotification(_U('received_weapon', weaponLabel, sourceXPlayer.name))

                    sourceXPlayer.triggerEvent('esx:giveAnimation')

                    targetXPlayer.triggerEvent('esx:giveAnimation')

                end

            else

                sourceXPlayer.showNotification(_U('gave_weapon_hasalready', targetXPlayer.name, weaponLabel))

                targetXPlayer.showNotification(_U('received_weapon_hasalready', sourceXPlayer.name, weaponLabel))

            end

        end

    elseif type == 'item_ammo' then

        if sourceXPlayer.hasWeapon(itemName) then

            local weaponNum, weapon = sourceXPlayer.getWeapon(itemName)

            if targetXPlayer.hasWeapon(itemName) then

                local _, weaponObject = ESX.GetWeapon(itemName)

                if weaponObject.ammo then

                    local ammoLabel = weaponObject.ammo.label

                    if weapon.ammo >= itemCount then

                        sourceXPlayer.removeWeaponAmmo(itemName, itemCount)

                        targetXPlayer.addWeaponAmmo(itemName, itemCount)

                        sourceXPlayer.showNotification(_U('gave_weapon_ammo', itemCount, ammoLabel, weapon.label, targetXPlayer.name))

                        targetXPlayer.showNotification(_U('received_weapon_ammo', itemCount, ammoLabel, weapon.label, sourceXPlayer.name))

                        

                        sourceXPlayer.triggerEvent('esx:giveAnimation')

                        targetXPlayer.triggerEvent('esx:giveAnimation')

                    end

                end

            else

                sourceXPlayer.showNotification(_U('gave_weapon_noweapon', targetXPlayer.name))

                targetXPlayer.showNotification(_U('received_weapon_noweapon', sourceXPlayer.name, weapon.label))

            end

        end

    end

end)
2 Likes

I’m going to test, I’ll let you know how the solution is going, thank you very much

the fix anim is : TaskPlayAnim(playerPed, “mp_common”, “givetake1_a”, 8.0, 8.0, 2000, 50, 0, false, false, false)

and work perfect <3

1 Like

What’s the ESX version you use?