[Free Release] Animal Spawner

which mlo was it? and what startup scripts are we talking about here?

1 Like

which mlo was it? and whawhich mlo was it? and what startup scripts are we talking about here?t startup scripts are we talking about here?

1 Like

I’m pretty new for fixing the snippet of the code, but how can I implement this into the script? I try to put in Animals.lua after end of the main one. It wasn’t attack me at all. If you guys could help explain to me I would really be appreciated. :wink:

1 Like

thanks man <3

2 Likes

@floatingdog u can please explain me, how i can add new animal in Lua… :frowning:

1 Like

copy the entire script and paste it under the first bunch of code, i think it ends at line 55? Just paste it under the last “end” in the script, then change each instance of the NPC model, so highlight ac_deer, control F > Replace all to a_c_mtnlion or whatever animal you are using.

1 Like

to me the latest version does not work

MainThrd/ ^1SCRIPT ERROR: @LuxeAnimals/Animals.lua:30: attempt to call a nil value (global 'etModelAsNoLongerNeeded')^7
3 Likes

Heres the original -

– WE WERE HAVING ISSUES WITH HUNTING AND ONESYNC WHERE ANIMALS WERE NOT SPAWNING, CREATED THIS WITH THE HELP OF SOME OTHERS TO ENABLE ANIMAL SPAWNS IN CERTAIN LOCATIONS–
—YOU CAN COPY PASTE LINES 3 THROUGH 65 AND CHANGE ANIMAL MODELS TO SPAWN OTHER ANIMALS—

local entities = {}
Citizen.CreateThread(function()

while true do
Wait(0)

local player = GetPlayerPed(-1)
local pos = GetEntityCoords(player,1)
local ground
if (IsEntityInZone(player, “CMSW”)–These are the zones animals spawn in, to find more zones search google for int GET_ZONE_FROM_NAME_ID
or IsEntityInZone(player, “MTCHIL”)
or IsEntityInZone(player, “MTGORDO”)
or IsEntityInZone(player, “MTJOSE”)
or IsEntityInZone(player, “PALFOR”)
or IsEntityInZone(player, “PALHIGH”)
or IsEntityInZone(player, “SANCHIA”)
or IsEntityInZone(player, “TONGVAH”)
or IsEntityInZone(player, “PALHIGH”))
and #entities < 25 then–how many animals to spawn

RequestModel(“a_c_deer”) --model of animal, this is a deer (OBVIOUSLY xD).
while not HasModelLoaded(“a_c_deer”) or not HasCollisionForModelLoaded(“a_c_deer”) do
Wait(1)
end

posX = pos.x+math.random(-100,100)
posY = pos.y+math.random(-100,100)
Z = pos.z+999.0
heading = math.random(0,359)+.0

ground,posZ = GetGroundZFor_3dCoord(posX+.0,posY+.0,Z,1)

if(ground) then

ped = CreatePed(28, “a_c_deer”, posX, posY, posZ, heading, true, true)
SetEntityAsMissionEntity(ped, true, true)
TaskWanderStandard(ped, 10.0, 10)
SetModelAsNoLongerNeeded(ped)
SetPedAsNoLongerNeeded(ped) – despawn when player no longer in the area
table.insert(entities,ped)

local blip = AddBlipForEntity(ped)
SetBlipSprite(blip,0) --if you want the animals to have blips change the 0 to a different blip number
SetBlipColour(blip,0)
BeginTextCommandSetBlipName(“STRING”)
AddTextComponentString(“spawned entity”)
EndTextCommandSetBlipName(blip)
end
end

for i, ped in pairs(entities) do
if IsEntityInWater(ped) then --if the animal spawns in water it will auto delete
local model = GetEntityModel(ped)
SetEntityAsNoLongerNeeded(ped)
SetModelAsNoLongerNeeded(model)
DeleteEntity(ped)
table.remove(entities,i)
end
end
end
end)

2 Likes

The problem that @rocco34 is having is due to missing S on line 30 and 31 in the file
It’s currently:

			etModelAsNoLongerNeeded(ped)
			etPedAsNoLongerNeeded(ped) -- despawn when player no longer in the area

when it should be

			SetModelAsNoLongerNeeded(ped)
			SetPedAsNoLongerNeeded(ped) -- despawn when player no longer in the area
4 Likes
  1. Now it works too much when you’re too still a location you are 400 animals you risk the crash.
  2. The positions do not calculate them anymore.
2 Likes

how did you do bigfoot?

1 Like

You have to add it to end and trigger it.

1 Like

should add that below the spawn of the animal ?

2 Likes

how to to config that in to the spawn ?

1 Like

Tried to use that code and it keeps on spawning no matter what location I am and its ignoring the animal spawn number

1 Like

you change those names to whatever zone you want, check the locations here:

1 Like

Get the Ped list from here:
https://docs.fivem.net/docs/game-references/ped-models/

Bigfoot is called cs_orleans

i would not advise spawning 400 animals. You only need 10-20 set in the file.

1 Like

Yeah I saw saw mb , one thing do they spawn if a player steps in the area ?

1 Like

If it detects a player going into one of those zones the animals will spawn, yes. You can set the blip numbers to something else instead of 0, then ensure the script and will be able to see where abouts the animals spawn compared to the player, if its too close adjust the radius etc.

1 Like