[HELP] Trying to add "Drink coffee animation"

Hello good people :smiley:

So, after buying Coffee from the shop, i want to have a ‘drinking coffee animation’ with a coffeecup.
Ive seen ai’s drinking from coffeecups ’ i think :stuck_out_tongue:

This is the standard coffeecup -

'p_amb_coffeecup_01'

Atm im only drinking beer anim.

This is the code i have but, i cant seem to figure out what the PlayerAnim/Scenario is for this, so if anyone know i would appreciate it so much!

File:
\resources[legacy][esx_addons]\esx_basicneeds\client\main.lua

RegisterNetEvent('esx_basicneeds:onCoffee')
AddEventHandler('esx_basicneeds:onCoffee', function(prop_name)
	if not IsAnimated then
		prop_name = prop_name or 'p_amb_coffeecup_01'
		IsAnimated = true

		Citizen.CreateThread(function()
			local playerPed = PlayerPedId()
			local x,y,z = table.unpack(GetEntityCoords(playerPed))
			local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
			local boneIndex = GetPedBoneIndex(playerPed, 18905)
			AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)

			ESX.Streaming.RequestAnimDict('amb@world_human_drinking@coffee@female@idle_a', function()
			TaskStartScenarioInPlace(playerPed, 'world_human_drinking', 1.0, -1.0, 2000, 0, 1, true, true, true)

				Citizen.Wait(3000)
				IsAnimated = false
				ClearPedSecondaryTask(playerPed)
				DeleteObject(prop)
			end)
		end)

	end
end)

Thanks for any reply!

Hey ! :slightly_smiling_face:

You could do something like this :

The only issue is that you need to let the animation play for 20sec (line 154), otherwise the ped might not drink from the cup before throwing it away (as the scenario make him drink at a random time).

Peace

Edit : doesn’t even need the [ prop_name = ‘p_ing…_coffee’ ] (line 147) as we don’t make the prop spawn this way.

1 Like

Ahh i didnt find that list of task animations :smiley:
I tried your code but that didn’t work like your screenshot.

So i added the WORLD_HUMAN_AA_COFFEE like you did and here is the final code :smiley:

I had to use ESX.Streaming.RequestAnimDict line, i tried to remove it but then no animation.

RegisterNetEvent('esx_basicneeds:onCoffee')
AddEventHandler('esx_basicneeds:onCoffee', function(prop_name)
	if not IsAnimated then
		IsAnimated = true

		Citizen.CreateThread(function()
			local playerPed = PlayerPedId()
			local x,y,z = table.unpack(GetEntityCoords(playerPed))
			local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
			local boneIndex = GetPedBoneIndex(playerPed, 18905)
			AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)

			ESX.Streaming.RequestAnimDict('amb@world_human_drinking@coffee@female@idle_a', function()
			TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_AA_COFFEE', 1.0, -1.0, 2000, 0, 1, true, true, true)
				
				Citizen.Wait(20000)
				IsAnimated = false
				ClearPedSecondaryTask(playerPed)
				DeleteObject(prop)
			
			end)
		end)

	end
end)

So thank you very much @thibaultD ! I really appreciate it!

Okay ! :slightly_smiling_face: