[Free Release] Animal Spawner

Hello, I was having issues with animals not spawning on our server, I want to share with you this script created to spawn animals in custom locations ready for you to hunt. You can edit the script to add any animal (or NPC) and determine the location it spawns in. For example i have a bigfoot that can spawn anywhere in the mountains, then added the bigfoot to a hunting script which allows you to hunt him down and loot his head for a nice reward.

  • No encryption.
  • Synced to all players.
  • Configurable zones using GET_ZONE_FROM_NAME_ID.
  • Configurable NPC quantity.

Technically doesn’t have to be animals…if you want actual NPC humans walking around in certain places just change the ped model.

Place file in your resources, add the file name to your server config. The script will do the rest. Happy hunting.

I havent tested the optimized one that someone posted so i cant confirm its working. Replaced the file with my original one:
LuxeAnimals.zip (1.3 KB)

25 Likes

This is awesome! I’ve been waiting for this type of script for so long. Is it synced to all player? If not I would say make it sync to all player that would be a LOT better. I love you!

4 Likes

Yes its synced to all players. I know this because i accidently added a deer location to south los santos and players were smashing into deer on grove street heheh.

6 Likes

I have been looking for something like this for ages. I bought an Animal Hunting Script and was having the same issues with Animals not spawning. Thank you soo much man!

2 Likes

Amazing thank you so much!!!

3 Likes

nice, but please format your scripts next time (it’s nicer to see and if you have to work in a team you learn to maintain an organization)

1 Like

Can you explain what you mean?

2 Likes

I’m just curious for example if I spawn a Shark on the water will it attack the player ? or I have to config

1 Like

I faced a situation when animals did not spawn, it was solved by deleting the start-up scripts from the config, as a result I found a map, yes, it was the MLO map that blocked the spawn of animals and NPCs

2 Likes

how long does it take to spawn ?

thanks for the script! If i want put other types of animal or NPC, in dealership, other places in same time how can i do this? thanks again!

-- 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 player = PlayerPedId()
local entities = {} 
Citizen.CreateThread(function()			 

	while true do
		Wait(0)		

		local pos = GetEntityCoords(player,1)
		local ground
		if (IsEntityInZone(player, "CMSW") 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		
		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.0

		ground,posZ = GetGroundZFor_3dCoord(posX+0.0,posY+0.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)
			etModelAsNoLongerNeeded(ped)
			etPedAsNoLongerNeeded(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)       			   

		 	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
end)

Here is optimized, formatted version ^^

6 Likes

@floatingdog, exactly in this sense

1 Like

Thanks very much :slight_smile:

1 Like

For me i just copied the entire code and pasted it underneath, then changed the npc model. There might be a more optimized way of doing it but im learning still.

1 Like

I haven’t figured out how to make the animals aggressive unless you attack them first. Let me know if you do!

2 Likes

its instant once you walk in the area. You can assign the animals blips so you can see them spawn on the map for testing.

1 Like

Re uploaded optimized version thanks to @Ege_Erdinc !! Thanks!!

1 Like

local AnimalHash = GetHashKey("Animal")

local playerHash = GetHashKey("PLAYER")

local underAttack = false

local dist = GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), GetEntityCoords(DeerPed), true)

AddRelationshipGroup("animal", AnimalHash)

Citizen.CreateThread(function()

  while true do

    Wait(1000)

    if dist < 10.0 then

      Attack()

    else

      StopAttack()

    end

  end

end)

function Attack()

  ClearPedTasks(AnimalPed)

  Wait(1)

    if IsEntityAPed(target) then

      TaskCombatPed(AnimalPed, target, 0, 16)

      SetRelationshipBetweenGroups(5, AnimalHash, playerHash)

      SetRelationshipBetweenGroups(5, playerHash, AnimalHash)

      underAttack = true

    end

end

function StopAttack()

  if underAttack then

      SetRelationshipBetweenGroups(1, AnimalHash, playerHash)

      SetRelationshipBetweenGroups(1, playerHash, AnimalHash)

      underAttack = false

  end

end

4 Likes

Legend <3

1 Like