Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed guards spawning every time a player joins. #10

Open
wants to merge 4 commits into
base: rewrite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions __resource.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ client_scripts {
"spawning/cl_player.lua",
"spawning/cl_zombies.lua",
"spawning/cl_savezones.lua"
}

server_scripts{
"spawning/sv_savezones.lua"
}
12 changes: 5 additions & 7 deletions spawning/cl_savezones.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,17 @@ local function HandleGuardSpawning()

for _, safezone in ipairs(Config.Spawning.Safezones.SAFEZONES) do
for _, guardSpawn in ipairs(safezone.GuardSpawns) do

if guardSpawn.Id and not spawnedIds[guardSpawn.Id] then
SpawnGuard(guardSpawn)
end
end
end
end

Utils.CreateLoadedInThread(function()
Wait(250)

if Player.IsSpawnHost() then
HandleGuardSpawning()
end
RegisterNetEvent("GuardSpawn")
AddEventHandler("GuardSpawn", function()
HandleGuardSpawning()
end)

Citizen.CreateThread(function()
Expand All @@ -88,4 +86,4 @@ Citizen.CreateThread(function()
id = id + 1
end
end
end)
end)
2 changes: 1 addition & 1 deletion spawning/cl_zombies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ Utils.CreateLoadedInThread(function()
end
end
end
end)
end)
15 changes: 15 additions & 0 deletions spawning/sv_savezones.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Citizen.CreateThread(function()
while true do
Citizen.Wait(500)
local count = 0
local spawned = false
players = GetPlayers()
for _ in ipairs(players) do
count = count + 1
if count == 1 and spawned == false then
TriggerClientEvent("GuardSpawn", -1)
spawned = true
end
end
end
end)