Allow greater than 1 spawnrate

This commit is contained in:
Garrett 2018-10-27 13:19:19 -04:00
parent 1a96ff48e8
commit 53c3a0c644
2 changed files with 66 additions and 71 deletions

View File

@ -1053,17 +1053,8 @@ function AdvDupe2.duplicator.Paste( Player, EntityList, ConstraintList, Position
return CreatedEntities, CreatedConstraints
end
local ticktotal = 0
local function AdvDupe2_Spawn()
ticktotal = ticktotal + AdvDupe2.SpawnRate
if(ticktotal<1)then
return
end
ticktotal = ticktotal - 1
local Queue = AdvDupe2.JobManager.Queue[AdvDupe2.JobManager.CurrentPlayer]
if(not Queue or not IsValid(Queue.Player))then
@ -1312,64 +1303,69 @@ local function AdvDupe2_Spawn()
end
end
local ticktotal = 0
local function ErrorCatchSpawning()
local status, error = pcall(AdvDupe2_Spawn)
ticktotal = ticktotal + AdvDupe2.SpawnRate
while ticktotal >= 1 do
ticktotal = ticktotal - 1
local status, error = pcall(AdvDupe2_Spawn)
if(not status)then
//PUT ERROR LOGGING HERE
if(not AdvDupe2.JobManager.Queue)then
print("[AdvDupe2Notify]\t"..error)
AdvDupe2.JobManager.Queue = {}
return
end
local Queue = AdvDupe2.JobManager.Queue[AdvDupe2.JobManager.CurrentPlayer]
if(not Queue)then
print("[AdvDupe2Notify]\t"..error)
return
end
if(IsValid(Queue.Player))then
AdvDupe2.Notify(Queue.Player, error)
if(not status)then
//PUT ERROR LOGGING HERE
local undos = undo.GetTable()[Queue.Player:UniqueID()]
local str = "AdvDupe2_"..Queue.Player:UniqueID()
for i=#undos, 1, -1 do
if(undos[i] and undos[i].Name == str)then
undos[i] = nil
-- Undo module netmessage
net.Start( "Undo_Undone" )
net.WriteInt( i, 16 )
net.Send( Queue.Player )
break
if(not AdvDupe2.JobManager.Queue)then
print("[AdvDupe2Notify]\t"..error)
AdvDupe2.JobManager.Queue = {}
return
end
local Queue = AdvDupe2.JobManager.Queue[AdvDupe2.JobManager.CurrentPlayer]
if(not Queue)then
print("[AdvDupe2Notify]\t"..error)
return
end
if(IsValid(Queue.Player))then
AdvDupe2.Notify(Queue.Player, error)
local undos = undo.GetTable()[Queue.Player:UniqueID()]
local str = "AdvDupe2_"..Queue.Player:UniqueID()
for i=#undos, 1, -1 do
if(undos[i] and undos[i].Name == str)then
undos[i] = nil
-- Undo module netmessage
net.Start( "Undo_Undone" )
net.WriteInt( i, 16 )
net.Send( Queue.Player )
break
end
end
else
print("[AdvDupe2Notify]\t"..error)
end
for k,v in pairs(Queue.CreatedEntities)do
if(IsValid(v))then v:Remove() end
end
if(IsValid(Queue.Player))then
AdvDupe2.FinishPasting(Queue.Player, true)
end
table.remove(AdvDupe2.JobManager.Queue, AdvDupe2.JobManager.CurrentPlayer)
if(#AdvDupe2.JobManager.Queue==0)then
hook.Remove("Tick", "AdvDupe2_Spawning")
DisablePropCreateEffect = nil
AdvDupe2.JobManager.PastingHook = false
else
if(#Queue<AdvDupe2.JobManager.CurrentPlayer)then
AdvDupe2.JobManager.CurrentPlayer = 1
end
end
else
print("[AdvDupe2Notify]\t"..error)
end
for k,v in pairs(Queue.CreatedEntities)do
if(IsValid(v))then v:Remove() end
end
if(IsValid(Queue.Player))then
AdvDupe2.FinishPasting(Queue.Player, true)
end
table.remove(AdvDupe2.JobManager.Queue, AdvDupe2.JobManager.CurrentPlayer)
if(#AdvDupe2.JobManager.Queue==0)then
hook.Remove("Tick", "AdvDupe2_Spawning")
DisablePropCreateEffect = nil
AdvDupe2.JobManager.PastingHook = false
else
if(#Queue<AdvDupe2.JobManager.CurrentPlayer)then
AdvDupe2.JobManager.CurrentPlayer = 1
end
end
end
end

View File

@ -63,7 +63,7 @@ CreateConVar("AdvDupe2_MapFileName", "", {FCVAR_ARCHIVE})
cvars.AddChangeCallback("AdvDupe2_SpawnRate",
function(cvar, preval, newval)
newval = tonumber(newval)
if(newval~=nil and newval<=1 and newval>0)then
if(newval~=nil and newval>0)then
AdvDupe2.SpawnRate = newval
else
print("[AdvDupe2Notify]\tINVALID SPAWN RATE")
@ -148,12 +148,11 @@ util.AddNetworkString("AdvDupe2_SendContraptionGhost")
hook.Add("InitPostEntity", "AdvDupe2_PasteMap", PasteMap)
hook.Add("PostCleanupMap", "AdvDupe2_PasteMap", PasteMap)
hook.Add("Initialize", "AdvDupe2_CheckServerSettings",
function()
AdvDupe2.SpawnRate = tonumber(GetConVarString("AdvDupe2_SpawnRate"))
if(not AdvDupe2.SpawnRate or AdvDupe2.SpawnRate<=0 or AdvDupe2.SpawnRate>1)then
AdvDupe2.SpawnRate = 1
print("[AdvDupe2Notify]\tINVALID SPAWN RATE DEFAULTING VALUE")
end
end)
hook.Add("Initialize", "AdvDupe2_CheckServerSettings",function()
AdvDupe2.SpawnRate = tonumber(GetConVarString("AdvDupe2_SpawnRate"))
if not AdvDupe2.SpawnRate or AdvDupe2.SpawnRate <= 0 then
AdvDupe2.SpawnRate = 1
print("[AdvDupe2Notify]\tINVALID SPAWN RATE DEFAULTING VALUE")
end
end)