From d30952e84aaadd88eda25aeb42ab8ded470f49cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:56:55 +0300 Subject: [PATCH 1/3] Fix NPC maker not respecting spawn frequency -1 --- entities/entities/lambda_npcmaker.lua | 35 ++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/entities/entities/lambda_npcmaker.lua b/entities/entities/lambda_npcmaker.lua index b503541b..58a1e920 100644 --- a/entities/entities/lambda_npcmaker.lua +++ b/entities/entities/lambda_npcmaker.lua @@ -137,10 +137,9 @@ function ENT:Initialize() BaseClass.Initialize(self) self:SetSolid(SOLID_NONE) if self:GetNWVar("Disabled") == false then - self:NextThink(CurTime() + 0.1) - self.Think = self.MakerThink + self:Disable() else - self.Think = self.StubThink + self:Enable() end end @@ -275,7 +274,13 @@ end function ENT:Enable() self:SetNWVar("Disabled", false) self.Think = self.MakerThink - self:NextThink(CurTime()) + local spawnFrequency = self:GetNWVar("SpawnFrequency") + local curTime = CurTime() + if spawnFrequency ~= -1 then + self.NextSpawnTime = curTime + spawnFrequency + else + self.NextSpawnTime = curTime + end end function ENT:Disable() @@ -358,6 +363,8 @@ function ENT:CanMakeNPC(ignoreSolidEnts) end function ENT:StubThink() + self:NextThink(CurTime() + 1) + return true end --DbgPrint(self, "ENT:StubThink", ent) @@ -369,9 +376,23 @@ function ENT:MakerThink() self.CachedPlayerCount = player.GetCount() end - self:NextThink(CurTime() + self:GetNWVar("SpawnFrequency")) + local curTime = CurTime() + self:NextThink(curTime + 0.1) + + if self.NextSpawnTime == -1 or self.NextSpawnTime > curTime then + return true + end + + -- Spawn the next NPC. self:MakeNPC() + local spawnFrequency = self:GetNWVar("SpawnFrequency") + if spawnFrequency ~= -1 then + self.NextSpawnTime = curTime + spawnFrequency + else + self.NextSpawnTime = -1 + end + return true end @@ -381,8 +402,10 @@ function ENT:DeathNotice(ent) end self:SetNWVar("LiveChildren", self:GetNWVar("LiveChildren") - 1) + if self:GetNWVar("SpawnFrequency") == -1 then - self:MakeNPC() + -- Allow it to spawn again. + self.NextSpawnTime = CurTime() end if self:GetNWVar("LiveChildren") <= 0 then From 967382f5f4155eac81d5c143200f6cfd006d928a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:57:49 +0300 Subject: [PATCH 2/3] Updated changelog.md --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 98d8c147..45ee5464 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ 0.9.26 (in development) - Improved: Going in and out of the settings no longer clips into the player model. +- Fixed: NPC makers not respecting the spawn frequency -1 causing a lot of NPCs being spawned in some cases. 0.9.25 - Improved: Hints will no longer show duplicates, instead it will renew the existing hint that has the same text. From 8fe431e01228604d143deabe40867d327a43618f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:02:45 +0300 Subject: [PATCH 3/3] Make sure the npc maker can spawn with the given frequency --- entities/entities/lambda_npcmaker.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/entities/entities/lambda_npcmaker.lua b/entities/entities/lambda_npcmaker.lua index 58a1e920..188d34db 100644 --- a/entities/entities/lambda_npcmaker.lua +++ b/entities/entities/lambda_npcmaker.lua @@ -281,6 +281,7 @@ function ENT:Enable() else self.NextSpawnTime = curTime end + self:NextThink(self.NextSpawnTime) end function ENT:Disable() @@ -377,9 +378,9 @@ function ENT:MakerThink() end local curTime = CurTime() - self:NextThink(curTime + 0.1) if self.NextSpawnTime == -1 or self.NextSpawnTime > curTime then + self:NextThink(curTime + 0.1) return true end @@ -389,8 +390,10 @@ function ENT:MakerThink() local spawnFrequency = self:GetNWVar("SpawnFrequency") if spawnFrequency ~= -1 then self.NextSpawnTime = curTime + spawnFrequency + self:NextThink(self.NextSpawnTime) else self.NextSpawnTime = -1 + self:NextThink(curTime + 0.1) end return true