Spawn zombie in a place that triggers

hello to all here, I had an idea during the night … I would like to create a game, enigma in the game, with spawn text 3d and blabla so that the player can pocket $ 10 million. …

but here is to do this I would need a little script, which would trigger, when he goes into the mine, 15-20 zombie that appear, when they are in an exact co-ordinate.

I found this script for an idea, I’m looking for but it’s really hard a boost is not refused … thank you all…

players = {}

RegisterNetEvent("Z:playerUpdate")
AddEventHandler("Z:playerUpdate", function(mPlayers)
	players = mPlayers
end)

peds = {}

Citizen.CreateThread(function()
	AddRelationshipGroup("zombeez")
	SetRelationshipBetweenGroups(5, GetHashKey("zombeez"), GetHashKey("PLAYER"))
	SetRelationshipBetweenGroups(5, GetHashKey("PLAYER"), GetHashKey("zombeez"))
	SetAiMeleeWeaponDamageModifier(50.0)

	while true do
		Wait(1)

		if #peds < 19 then
			x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))

			RequestModel(0xAC4B4506)
			while not HasModelLoaded(0xAC4B4506) do
				Wait(1)
			end

			repeat
				Wait(1)

				newX = x + math.random(-300, 300)
				newY = y + math.random(-300, 300)

				for _, player in pairs(players) do
					Wait(1)
					playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(player), true))
					if newX > playerX - 60 and newX < playerX + 60 or newY > playerY - 60 and newY < playerY + 60 then
						canSpawn = false
						break
					else
						canSpawn = true
					end
				end
			until canSpawn

			ped = CreatePed(4, 0xAC4B4506, newX, newY, z - 500, 0.0, true, true)

			SetPedArmour(ped, 100)
			SetPedAccuracy(ped, 25)
			SetPedSeeingRange(ped, 1000000.0)
			SetPedHearingRange(ped, 1000000.0)

			SetPedFleeAttributes(ped, 0, 0)
   			SetPedCombatAttributes(ped, 16, 1)
   			SetPedCombatAttributes(ped, 46, 1)
			SetAmbientVoiceName(ped, "ALIENS")
			SetPedEnableWeaponBlocking(ped, true)
			SetPedRelationshipGroupHash(ped, GetHashKey("zombeez"))
			DisablePedPainAudio(ped, true)
			SetPedDiesInWater(ped, false)
			SetPedDiesWhenInjured(ped, false)

			SetPedIsDrunk(ped, true)
			RequestAnimSet("move_m@drunk@verydrunk")
			while not HasAnimSetLoaded("move_m@drunk@verydrunk") do
				Wait(1)
			end
			SetPedMovementClipset(ped, "move_m@drunk@verydrunk", 1.0)

			--TaskCombatPed(ped, GetPlayerPed(-1), 0, 16)
			x, y, z = table.unpack(GetEntityCoords(ped, true))
			TaskWanderStandard(ped, 1.0, 10)

			chance = math.random(150)
			if chance == 50 then
				randomWep = math.random(1, #pedWeps)
				GiveWeaponToPed(ped, GetHashKey(pedWeps[randomWep]), 9999, true, true)

				Citizen.Trace("Spawned zombie with weapon " .. pedWeps[randomWep] .. "\n")
			else
				Citizen.Trace("Spawned zombie with no weapon\n")
			end

			table.insert(peds, ped)
		end

		for i, ped in pairs(peds) do
			if not DoesEntityExist(ped) then
				table.remove(peds, i)
			elseif IsPedDeadOrDying(ped, 1) then
				-- Set ped as no longer needed for despawning
				Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
				table.remove(peds, i)
			else
				playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
				pedX, pedY = table.unpack(GetEntityCoords(ped, true))

				if pedX < playerX - 400 or pedX > playerX + 400 or pedY < playerY - 400 or pedY > playerY + 400 then
					-- Set ped as no longer needed for despawning
					Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
					table.remove(peds, i)
				end
			end
		end
	end
end)

RegisterNetEvent("Z:cleanup")
AddEventHandler("Z:cleanup", function()
	for i, ped in pairs(peds) do
		-- Set ped as no longer needed for despawning
		Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))

		table.remove(peds, i)
	end
end)

Hi,

You just need to put all Citizen.CreateThread in an event, then trigger the event when you want to spawn zombies

2 Likes

thank you for your help it’s great, but I’m looking to trigger the event, when I arrive at a certain area/zone of co-ordination.

the zombies appear and when I leave this area/zone the zombies do not attack me anymore …

Just an exemple to trigger when someone is in area:

local isInArea = false
local area = { x = 1.0, y = 1.0, z = 1.0, radius = 10.0 }

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)

    local playerPed = GetPlayerPed(-1)
	local pedX, pedY, pedZ = table.unpack(GetEntityCoords(playerPed, true))

    if (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) <= area.radius and isInArea == false) then
		--spawn zombies
        TriggerEvent('yourevent')
		isInArea = true
	elseif  (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) > area.radius and isInArea == true) then 
		--stop zombies
		TriggerEvent('yourotherevent')
		isInArea = false
    end
  end
end)

I can’t test if it realy works, but I think it is.

1 Like

thank you with all my heart i will test it … thank you thank you thank you :kissing_heart: :smiling_face_with_three_hearts:

I have this error please help me

:sanglot:

Error parsing script client.lua in resource zombiemine: client.lua:75: unexpected symbol near ')'


local isInArea = false
local area = { x = 1.0, y = 1.0, z = 1.0, radius = 10.0 }

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)

    local playerPed = GetPlayerPed(-1)
	local pedX, pedY, pedZ = table.unpack(GetEntityCoords(playerPed, true))

    if (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) <= area.radius and isInArea == false) then
		
		ped = CreatePed(4, 0xAC4B4506, newX, newY, z - 500, 0.0, true, true)

			SetPedArmour(ped, 100)
			SetPedAccuracy(ped, 25)
			SetPedSeeingRange(ped, 1000000.0)
			SetPedHearingRange(ped, 1000000.0)

			SetPedFleeAttributes(ped, 0, 0)
   			SetPedCombatAttributes(ped, 16, 1)
   			SetPedCombatAttributes(ped, 46, 1)
			SetAmbientVoiceName(ped, "ALIENS")
			SetPedEnableWeaponBlocking(ped, true)
			SetPedRelationshipGroupHash(ped, GetHashKey("zombeez"))
			DisablePedPainAudio(ped, true)
			SetPedDiesInWater(ped, false)
			SetPedDiesWhenInjured(ped, false)

			SetPedIsDrunk(ped, true)
			RequestAnimSet("move_m@drunk@verydrunk")
			while not HasAnimSetLoaded("move_m@drunk@verydrunk") do
				Wait(1)
			end
			SetPedMovementClipset(ped, "move_m@drunk@verydrunk", 1.0)

			--TaskCombatPed(ped, GetPlayerPed(-1), 0, 16)
			x, y, z = table.unpack(GetEntityCoords(ped, true))
			TaskWanderStandard(ped, 1.0, 10)
		chance = math.random(150)
			if chance == 50 then
				randomWep = math.random(1, #pedWeps)
				GiveWeaponToPed(ped, GetHashKey(pedWeps[randomWep]), 9999, true, true)

				Citizen.Trace("Spawned zombie with weapon " .. pedWeps[randomWep] .. "\n")
			else
				Citizen.Trace("Spawned zombie with no weapon\n")
			end

			table.insert(peds, ped)
		end

		for i, ped in pairs(peds) do
			if not DoesEntityExist(ped) then
				table.remove(peds, i)
         TriggerEvent('"Z:playerUpdate"')
		isInArea = true
	elseif  (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) > area.radius and isInArea == true) then 
		--stop zombies
		Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
				table.remove(peds, i)
			else
				playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
				pedX, pedY = table.unpack(GetEntityCoords(ped, true))

				if pedX < playerX - 400 or pedX > playerX + 400 or pedY < playerY - 400 or pedY > playerY + 400 then
					-- Set ped as no longer needed for despawning
					Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
					table.remove(peds, i)
		TriggerEvent('Z:cleanup')  
		isInArea = false
    end
  end
end)

Je ne trouve pas l’erreur dans ce script aidez-moi les hommes !!!



local isInArea = false
local area = { x = 1.0, y = 1.0, z = 1.0, radius = 10.0 }

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)

    local playerPed = GetPlayerPed(-1)
	local pedX, pedY, pedZ = table.unpack(GetEntityCoords(playerPed, true))

    if (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) <= area.radius and isInArea == false) then
		
		ped = CreatePed(4, 0xAC4B4506, newX, newY, z - 500, 0.0, true, true)

			SetPedArmour(ped, 100)
			SetPedAccuracy(ped, 25)
			SetPedSeeingRange(ped, 1000000.0)
			SetPedHearingRange(ped, 1000000.0)

			SetPedFleeAttributes(ped, 0, 0)
   			SetPedCombatAttributes(ped, 16, 1)
   			SetPedCombatAttributes(ped, 46, 1)
			SetAmbientVoiceName(ped, "ALIENS")
			SetPedEnableWeaponBlocking(ped, true)
			SetPedRelationshipGroupHash(ped, GetHashKey("zombeez"))
			DisablePedPainAudio(ped, true)
			SetPedDiesInWater(ped, false)
			SetPedDiesWhenInjured(ped, false)

			SetPedIsDrunk(ped, true)
			RequestAnimSet("move_m@drunk@verydrunk")
			while not HasAnimSetLoaded("move_m@drunk@verydrunk") do
				Wait(1)
			end
			SetPedMovementClipset(ped, "move_m@drunk@verydrunk", 1.0)

			--TaskCombatPed(ped, GetPlayerPed(-1), 0, 16)
			x, y, z = table.unpack(GetEntityCoords(ped, true))
			TaskWanderStandard(ped, 1.0, 10)
		chance = math.random(150)
			if chance == 50 then
				randomWep = math.random(1, #pedWeps)
				GiveWeaponToPed(ped, GetHashKey(pedWeps[randomWep]), 9999, true, true)

				Citizen.Trace("Spawned zombie with weapon " .. pedWeps[randomWep] .. "\n")
			else
				Citizen.Trace("Spawned zombie with no weapon\n")
			end

			table.insert(peds, ped)
		end

		for i, ped in pairs(peds) do
			if not DoesEntityExist(ped) then
				table.remove(peds, i)
         TriggerEvent('"Z:playerUpdate"')
		isInArea = true
	elseif  (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) > area.radius and isInArea == true) then 
		--stop zombies
		Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
				table.remove(peds, i)
			else
				playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
				pedX, pedY = table.unpack(GetEntityCoords(ped, true))

				if pedX < playerX - 400 or pedX > playerX + 400 or pedY < playerY - 400 or pedY > playerY + 400 then
					-- Set ped as no longer needed for despawning
					Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
					table.remove(peds, i)
		TriggerEvent('Z:cleanup')  
		isInArea = false
    end
  end
end)

You just miss a ‘end’ to close your while loop

Should work:

local isInArea = false
local area = { x = 1.0, y = 1.0, z = 1.0, radius = 10.0 }

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)

		local playerPed = GetPlayerPed(-1)
		local pedX, pedY, pedZ = table.unpack(GetEntityCoords(playerPed, true))

		if (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) <= area.radius and isInArea == false) then
			
			ped = CreatePed(4, 0xAC4B4506, newX, newY, z - 500, 0.0, true, true)

			SetPedArmour(ped, 100)
			SetPedAccuracy(ped, 25)
			SetPedSeeingRange(ped, 1000000.0)
			SetPedHearingRange(ped, 1000000.0)

			SetPedFleeAttributes(ped, 0, 0)
			SetPedCombatAttributes(ped, 16, 1)
			SetPedCombatAttributes(ped, 46, 1)
			SetAmbientVoiceName(ped, "ALIENS")
			SetPedEnableWeaponBlocking(ped, true)
			SetPedRelationshipGroupHash(ped, GetHashKey("zombeez"))
			DisablePedPainAudio(ped, true)
			SetPedDiesInWater(ped, false)
			SetPedDiesWhenInjured(ped, false)

			SetPedIsDrunk(ped, true)
			RequestAnimSet("move_m@drunk@verydrunk")
			while not HasAnimSetLoaded("move_m@drunk@verydrunk") do
				Wait(1)
			end
			SetPedMovementClipset(ped, "move_m@drunk@verydrunk", 1.0)

			--TaskCombatPed(ped, GetPlayerPed(-1), 0, 16)
			x, y, z = table.unpack(GetEntityCoords(ped, true))
			TaskWanderStandard(ped, 1.0, 10)
			chance = math.random(150)
			if chance == 50 then
				randomWep = math.random(1, #pedWeps)
				GiveWeaponToPed(ped, GetHashKey(pedWeps[randomWep]), 9999, true, true)

				Citizen.Trace("Spawned zombie with weapon " .. pedWeps[randomWep] .. "\n")
			else
				Citizen.Trace("Spawned zombie with no weapon\n")
			end

			table.insert(peds, ped)
		end

		for i, ped in pairs(peds) do
			if not DoesEntityExist(ped) then
				table.remove(peds, i)
			TriggerEvent('"Z:playerUpdate"')
			isInArea = true
		elseif  (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) > area.radius and isInArea == true) then 
			--stop zombies
			Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
			table.remove(peds, i)
		else
			playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
			pedX, pedY = table.unpack(GetEntityCoords(ped, true))

			if pedX < playerX - 400 or pedX > playerX + 400 or pedY < playerY - 400 or pedY > playerY + 400 then
				-- Set ped as no longer needed for despawning
				Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
				table.remove(peds, i)
				TriggerEvent('Z:cleanup')  
				isInArea = false
			end
		end
	end
end)
1 Like

I will try to make it work, thank you thank you thank you with all my heart !!! :heart_eyes:

Pas de problème :wink:

Excuse me for bothering you, again … I have this error that appears I do not understand, why …

thanks again really :kissing_heart:



Error parsing script client.lua in resource zombiemine: client.lua:76: unexpected symbol near ‘)’
Failed to load script client.lua.

Ho yes, un anthor ‘end’ is missing

local isInArea = false
local area = { x = 1.0, y = 1.0, z = 1.0, radius = 10.0 }

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)

		local playerPed = GetPlayerPed(-1)
		local pedX, pedY, pedZ = table.unpack(GetEntityCoords(playerPed, true))

		if (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) <= area.radius and isInArea == false) then
			
			ped = CreatePed(4, 0xAC4B4506, newX, newY, z - 500, 0.0, true, true)

			SetPedArmour(ped, 100)
			SetPedAccuracy(ped, 25)
			SetPedSeeingRange(ped, 1000000.0)
			SetPedHearingRange(ped, 1000000.0)

			SetPedFleeAttributes(ped, 0, 0)
			SetPedCombatAttributes(ped, 16, 1)
			SetPedCombatAttributes(ped, 46, 1)
			SetAmbientVoiceName(ped, "ALIENS")
			SetPedEnableWeaponBlocking(ped, true)
			SetPedRelationshipGroupHash(ped, GetHashKey("zombeez"))
			DisablePedPainAudio(ped, true)
			SetPedDiesInWater(ped, false)
			SetPedDiesWhenInjured(ped, false)

			SetPedIsDrunk(ped, true)
			RequestAnimSet("move_m@drunk@verydrunk")
			while not HasAnimSetLoaded("move_m@drunk@verydrunk") do
				Wait(1)
			end
			SetPedMovementClipset(ped, "move_m@drunk@verydrunk", 1.0)

			--TaskCombatPed(ped, GetPlayerPed(-1), 0, 16)
			x, y, z = table.unpack(GetEntityCoords(ped, true))
			TaskWanderStandard(ped, 1.0, 10)
			chance = math.random(150)
			if chance == 50 then
				randomWep = math.random(1, #pedWeps)
				GiveWeaponToPed(ped, GetHashKey(pedWeps[randomWep]), 9999, true, true)

				Citizen.Trace("Spawned zombie with weapon " .. pedWeps[randomWep] .. "\n")
			else
				Citizen.Trace("Spawned zombie with no weapon\n")
			end

			table.insert(peds, ped)
		end

		for i, ped in pairs(peds) do
			if not DoesEntityExist(ped) then
				table.remove(peds, i)
			end
			TriggerEvent('"Z:playerUpdate"')
			isInArea = true
		elseif  (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) > area.radius and isInArea == true) then 
			--stop zombies
			Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
			table.remove(peds, i)
		else
			playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
			pedX, pedY = table.unpack(GetEntityCoords(ped, true))

			if pedX < playerX - 400 or pedX > playerX + 400 or pedY < playerY - 400 or pedY > playerY + 400 then
				-- Set ped as no longer needed for despawning
				Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
				table.remove(peds, i)
				TriggerEvent('Z:cleanup')  
				isInArea = false
			end
		end
	end
end)

should be good

I’m sorry to annoy you with that but I have this mistake now …thanks again for everything:kissing_heart: :man_facepalming:

Error parsing script client.lua in resource zombiemine: client.lua:60: 'end' expected (to close 'for' at line 54) near 'elseif'
Failed to load script client.lua.

I tried the script and I fixed syntax errors:

local isInArea = false
local area = { x = 1.0, y = 1.0, z = 1.0, radius = 10.0 }

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)

        local playerPed = GetPlayerPed(-1)
        local pedX, pedY, pedZ = table.unpack(GetEntityCoords(playerPed, true))

        if (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) <= area.radius and isInArea == false) then

            ped = CreatePed(4, 0xAC4B4506, newX, newY, z - 500, 0.0, true, true)

            SetPedArmour(ped, 100)
            SetPedAccuracy(ped, 25)
            SetPedSeeingRange(ped, 1000000.0)
            SetPedHearingRange(ped, 1000000.0)

            SetPedFleeAttributes(ped, 0, 0)
            SetPedCombatAttributes(ped, 16, 1)
            SetPedCombatAttributes(ped, 46, 1)
            SetAmbientVoiceName(ped, "ALIENS")
            SetPedEnableWeaponBlocking(ped, true)
            SetPedRelationshipGroupHash(ped, GetHashKey("zombeez"))
            DisablePedPainAudio(ped, true)
            SetPedDiesInWater(ped, false)
            SetPedDiesWhenInjured(ped, false)

            SetPedIsDrunk(ped, true)
            RequestAnimSet("move_m@drunk@verydrunk")
            while not HasAnimSetLoaded("move_m@drunk@verydrunk") do
                Wait(1)
            end
            SetPedMovementClipset(ped, "move_m@drunk@verydrunk", 1.0)

            --TaskCombatPed(ped, GetPlayerPed(-1), 0, 16)
            x, y, z = table.unpack(GetEntityCoords(ped, true))
            TaskWanderStandard(ped, 1.0, 10)
            chance = math.random(150)
            if chance == 50 then
                randomWep = math.random(1, #pedWeps)
                GiveWeaponToPed(ped, GetHashKey(pedWeps[randomWep]), 9999, true, true)

                Citizen.Trace("Spawned zombie with weapon " .. pedWeps[randomWep] .. "\n")
            else
                Citizen.Trace("Spawned zombie with no weapon\n")
            end

            table.insert(peds, ped)
        end

        for i, ped in pairs(peds) do
            if not DoesEntityExist(ped) then
                table.remove(peds, i)
                TriggerEvent('"Z:playerUpdate"')
                isInArea = true
            elseif  (Vdist2(area.x, area.y, area.z, pedX, pedY, pedZ) > area.radius and isInArea == true) then
                --stop zombies
                Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
                table.remove(peds, i)
            else
                playerX, playerY = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
                pedX, pedY = table.unpack(GetEntityCoords(ped, true))

                if pedX < playerX - 400 or pedX > playerX + 400 or pedY < playerY - 400 or pedY > playerY + 400 then
                    -- Set ped as no longer needed for despawning
                    Citizen.InvokeNative(0xB736A491E64A32CF, Citizen.PointerValueIntInitialized(ped))
                    table.remove(peds, i)
                    TriggerEvent('Z:cleanup')
                    isInArea = false
                end
            end
        end
    end
end)

But, I saw other problems, when you create a zombie, there’re 3 undefined variables: newX, newY and z. You need to defined them.

You forgot 2 other variables: pedWeps and peds. they’re array and you can define them at the begining of your script. pedWeps contain all weapons name.

local peds = {}
local pedWeps = {
	"WEAPON_BAT",
	"WEAPON_CROWBAR"
}

I thank you wholeheartedly, I have this error that appears, in any case I hope one day, can make you the same. :kissing_heart:

Error resuming coroutine: client.lua:9: attempt to call a nil value (global 'GetPlayerPed')
stack traceback:
        client.lua:9: in function <client.lua:5>

Did you correctly fixed all problem I have listed?

GetPlayerPed is a fiveM function, so either your game isn’t up to date or the problem is about another thing as often with lua

i’m going to see all this, how to define newx newy and new z … thanks really with all my heartm for this advanced on this script, it’s time to try to finish alone …
thanks again !!!
to show that women too can do scripting. :kissing_heart:

If you still need help with this, i could help you out.

@SuisseGames @fauconjona @SneakGaming understand, that you gave up the subject, 3 hours that I try to define newX, newY and newZ without any result it’s a pity it could have been fun. We only see zombie gamemode but nothing level of a fivem RP server.

the idea of ​​creating zombies in an area is a nice idea though.

The zombies don’t spawn on me

1 Like