A RedM Lua example that recreates the Naturalist role's animal sampling animation. The snippet spawns and attaches a syringe prop to the player's hand before playing the native sample collection animation, making it ideal for hunting, veterinary, and wildlife-related scripts:
local ANIM_DICT = "mech_skin@sample@base"
local ANIM_NAME = "sample_mid"
local PROP_MODEL = "p_cs_syringe02x"
local function LoadAnimDict(dict)
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Wait(0)
end
end
RegisterCommand("sample", function()
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
-- Spawn syringe
local syringe = CreateObject(
GetHashKey(PROP_MODEL),
coords.x,
coords.y,
coords.z,
true,
false,
true
)
SetEntityAsMissionEntity(syringe, true, true)
-- Attach to left hand
AttachEntityToEntity(
syringe,
ped,
GetEntityBoneIndexByName(ped, "PH_L_Hand"),
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
true, true, false, true, 1, true
)
-- Play animation
LoadAnimDict(ANIM_DICT)
TaskPlayAnim(
ped,
ANIM_DICT,
ANIM_NAME,
8.0,
-8.0,
5000,
1,
0.0,
true,
0,
false,
0,
false
)
-- Cleanup after animation
CreateThread(function()
Wait(5000)
if DoesEntityExist(syringe) then
DeleteEntity(syringe)
end
end)
end)