So im currently working on a script that makes it possible to kill deers and then slaughter them. i have a problem though and need some help by someone a little more experienced. the script is done just need to get the locals working.
function Hunting()
LoadModel('a_c_deer')
LoadAnimDict('amb@medic@standing@kneel@base')
LoadAnimDict('anim@gangops@facility@servers@bodysearch@')
Citizen.CreateThread(function()
while true do
local sleep = 500
local plyCoords = GetEntityCoords(PlayerPedId())
local Animal = GetHashKey('a_c_deer')
local ClosestAnimal = GetClosestPed(Animal)
local AnimalCoords = GetEntityCoords(ClosestAnimal)
local distance = GetDistanceBetweenCoords(plyCoords, AnimalCoords, true)
local AnimalHealth = GetEntityHealth(ClosestAnimal)
if AnimalHealth <= 0 then
local AnimalBlip = AddBlipForEntity(ClosestAnimal)
SetBlipSprite(AnimalBlip, 153)
SetBlipColour(AnimalBlip, 1)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('Deer - Animal')
EndTextCommandSetBlipName(AnimalBlip)
if distance < 2.0 then
ESX.Game.Utils.DrawText3D({x = AnimalCoords.x, y = AnimalCoords.y, z = AnimalCoords.z + 1}, '[E] Slaughter Animal', 0.4)
if IsControlJustReleased(0, Keys['E']) then
if GetSelectedPedWeapon(PlayerPedId()) == GetHashKey('WEAPON_KNIFE') then
if DoesEntityExist(ClosestAnimal) then
SlaughterAnimal()
end
else
ESX.ShowNotification('You need to use the knife!')
end
end
end
Citizen.Wait(sleep)
end
end
end)
end
Thats the code i need help with. all hel is appreciated! thanks!
Hi is this for vRP? I try the french ESX version and works on the vRP for the hunting but once i gather the meat doesnt show it on my inventory so i can sell it to the butcher… Any help with that? At least poit me in a direction please.
@Loffe Hello i am making same hunting script that you can hunt deers around the map, did u find the solution how to get closest deer, cause i havent if you would like to help me, that will be very much appreciated!
Huh, this does work, however it makes no sense (to me) that you must use repeat and not other ways of looping. Is there any proper documentation about this?
Here’s how I did it
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local ped = PlayerPedId()
local random,npc = FindFirstPed()
repeat
if IsPedDeadOrDying(npc) and not IsPedAPlayer(npc) and not IsPedInAnyVehicle(ped) and not IsPedInAnyVehicle(npc) then
if GetEntityModel(npc) == 1581098148 then
local distance = GetDistanceBetweenCoords(GetEntityCoords(ped),GetEntityCoords(npc),true)
if distance <= 2.0 then
print('Press E to skin')
if IsControlJustPressed(0,38) then
local gunInHand = GetSelectedPedWeapon(ped)
if gunInHand == GetHashKey("WEAPON_KNIFE") or gunInHand == GetHashKey("WEAPON_DAGGER") or gunInHand == GetHashKey("WEAPON_MACHETE") or gunInHand == GetHashKey("WEAPON_SWITCHBLADE") or gunInHand == GetHashKey("WEAPON_HATCHET") or gunInHand == GetHashKey("WEAPON_BATTLEAXE") or gunInHand == GetHashKey("WEAPON_STONE_HATCHET") then
print('you filthy monster')
SetEntityCoords(ped, GetEntityCoords(npc),0,0,0,1)
success = true
end
end
end
end
end
success,npc = FindNextPed(random)
until not success
EndFindPed(random)
end
end)
You need to loop through all the closest peds that for performace sake is dead. and If the ped is a dear you can add a blip or whatever. Then If your distance to the animal is lets say > 400 then you should remove the animal so you dont keep unused stuff laying around