Add adjustable ghost rate (#493)

This commit is contained in:
Brandon Sturgeon 2025-01-03 00:59:01 -05:00 committed by GitHub
parent 722c560515
commit 8d6ad3b8f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 16 deletions

View File

@ -180,26 +180,33 @@ local function MakeGhostsFromTable(EntTable)
return GhostEntity return GhostEntity
end end
local function StopGhosting()
AdvDupe2.Ghosting = false
hook.Remove( "Tick", "AdvDupe2_SpawnGhosts" )
if not BusyBar then AdvDupe2.RemoveProgressBar() end
end
local function SpawnGhosts() local function SpawnGhosts()
local ghostsPerTick = GetConVar( "advdupe2_ghost_rate" ):GetInt()
local ghostPercentLimit = GetConVar( "advdupe2_limit_ghost" ):GetFloat()
if AdvDupe2.CurrentGhost == AdvDupe2.HeadEnt then AdvDupe2.CurrentGhost = AdvDupe2.CurrentGhost + 1 end local finalGhost = math.min( AdvDupe2.TotalGhosts, math.max( math.Round( (ghostPercentLimit / 100) * AdvDupe2.TotalGhosts ), 0 ) )
local finalGhostInFrame = math.min( AdvDupe2.CurrentGhost + ghostsPerTick - 1, finalGhost )
local g = AdvDupe2.GhostToSpawn[AdvDupe2.CurrentGhost] for i = AdvDupe2.CurrentGhost, finalGhostInFrame do
if g and AdvDupe2.CurrentGhost / AdvDupe2.TotalGhosts * 100 <= GetConVar("advdupe2_limit_ghost"):GetFloat() then local g = AdvDupe2.GhostToSpawn[i]
AdvDupe2.GhostEntities[AdvDupe2.CurrentGhost] = MakeGhostsFromTable(g) if g and i ~= AdvDupe2.HeadEnt then AdvDupe2.GhostEntities[i] = MakeGhostsFromTable( g ) end
if(not AdvDupe2.BusyBar) then end
AdvDupe2.ProgressBar.Percent = AdvDupe2.CurrentGhost / AdvDupe2.TotalGhosts * 100 AdvDupe2.CurrentGhost = finalGhostInFrame + 1
end
AdvDupe2.CurrentGhost = AdvDupe2.CurrentGhost + 1 AdvDupe2.UpdateGhosts( true )
AdvDupe2.UpdateGhosts(true) if not AdvDupe2.BusyBar then
else AdvDupe2.ProgressBar.Percent = (AdvDupe2.CurrentGhost / AdvDupe2.TotalGhosts) * 100
AdvDupe2.Ghosting = false end
hook.Remove("Tick", "AdvDupe2_SpawnGhosts")
if(not AdvDupe2.BusyBar) then if AdvDupe2.CurrentGhost > finalGhost then
AdvDupe2.RemoveProgressBar() StopGhosting()
end
end end
end end

View File

@ -1038,7 +1038,8 @@ if(CLIENT) then
CreateClientConVar("advdupe2_preserve_freeze", 0, false, true) CreateClientConVar("advdupe2_preserve_freeze", 0, false, true)
CreateClientConVar("advdupe2_copy_outside", 0, false, true) CreateClientConVar("advdupe2_copy_outside", 0, false, true)
CreateClientConVar("advdupe2_copy_only_mine", 1, false, true) CreateClientConVar("advdupe2_copy_only_mine", 1, false, true)
CreateClientConVar("advdupe2_limit_ghost", 100, false, true) CreateClientConVar("advdupe2_limit_ghost", 100, false, true, nil, 0, 100)
CreateClientConVar("advdupe2_ghost_rate", 5, true, true, nil, 1, 50)
CreateClientConVar("advdupe2_area_copy_size", 300, false, true) CreateClientConVar("advdupe2_area_copy_size", 300, false, true)
CreateClientConVar("advdupe2_auto_save_contraption", 0, false, true) CreateClientConVar("advdupe2_auto_save_contraption", 0, false, true)
CreateClientConVar("advdupe2_auto_save_overwrite", 1, false, true) CreateClientConVar("advdupe2_auto_save_overwrite", 1, false, true)
@ -1143,6 +1144,7 @@ if(CLIENT) then
Check:SetToolTip( "Orders constraints so that they build a rigid constraint system." ) Check:SetToolTip( "Orders constraints so that they build a rigid constraint system." )
CPanel:AddItem(Check) CPanel:AddItem(Check)
-- Ghost Percentage
local NumSlider = vgui.Create( "DNumSlider" ) local NumSlider = vgui.Create( "DNumSlider" )
NumSlider:SetText( "Ghost Percentage:" ) NumSlider:SetText( "Ghost Percentage:" )
NumSlider.Label:SetDark(true) NumSlider.Label:SetDark(true)
@ -1160,6 +1162,18 @@ if(CLIENT) then
NumSlider.Wang.Panel.OnLoseFocus = function(txtBox) func3(txtBox) AdvDupe2.StartGhosting() end NumSlider.Wang.Panel.OnLoseFocus = function(txtBox) func3(txtBox) AdvDupe2.StartGhosting() end
CPanel:AddItem(NumSlider) CPanel:AddItem(NumSlider)
-- Ghost Rate
NumSlider = vgui.Create( "DNumSlider" )
NumSlider:SetText( "Ghost speed:" )
NumSlider.Label:SetDark(true)
NumSlider:SetMin( 1 )
NumSlider:SetMax( 50 )
NumSlider:SetDecimals( 0 )
NumSlider:SetConVar( "advdupe2_ghost_rate" )
NumSlider:SetToolTip("Change how quickly the ghosts are generated")
CPanel:AddItem(NumSlider)
-- Area Copy Size
NumSlider = vgui.Create( "DNumSlider" ) NumSlider = vgui.Create( "DNumSlider" )
NumSlider:SetText( "Area Copy Size:" ) NumSlider:SetText( "Area Copy Size:" )
NumSlider.Label:SetDark(true) NumSlider.Label:SetDark(true)