Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions lua/entities/gmod_wire_expression2/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ e2_hardquota = nil
e2_tickquota = nil
e2_timequota = nil
e2_timeaverage = nil
e2_globalmax = nil

do
local wire_expression2_unlimited = GetConVar("wire_expression2_unlimited")
Expand All @@ -17,6 +18,7 @@ do
local wire_expression2_quotatick = GetConVar("wire_expression2_quotatick")
local wire_expression2_quotatime = GetConVar("wire_expression2_quotatime")
local wire_expression2_quota_average = GetConVar("wire_expression2_quota_average")
local wire_expression2_quota_globalmax = GetConVar("wire_expression2_quota_globalmax")

local function updateQuotas()
if wire_expression2_unlimited:GetBool() then
Expand All @@ -32,13 +34,15 @@ do
end

e2_timeaverage = 1 / wire_expression2_quota_average:GetFloat()
e2_globalmax = wire_expression2_quota_globalmax:GetFloat()
end
cvars.AddChangeCallback("wire_expression2_unlimited", updateQuotas)
cvars.AddChangeCallback("wire_expression2_quotasoft", updateQuotas)
cvars.AddChangeCallback("wire_expression2_quotahard", updateQuotas)
cvars.AddChangeCallback("wire_expression2_quotatick", updateQuotas)
cvars.AddChangeCallback("wire_expression2_quotatime", updateQuotas)
cvars.AddChangeCallback("wire_expression2_quota_average", updateQuotas)
cvars.AddChangeCallback("wire_expression2_quota_globalmax", updateQuotas)
updateQuotas()
end

Expand Down Expand Up @@ -852,6 +856,32 @@ hook.Add("PlayerAuthed", "Wire_Expression2_Player_Authed", function(ply, sid, ui
end
end)

-- Terminates the highest usage e2 if the global limit is hit defined by the cvar wire_expression2_quota_globalmax
hook.Add( "Tick", "Wire_Expression2_Global_Limit", function()
local totalChipTime = 0
local highestChipTime = 0
local highestChip = nil
for _, ply in player.Iterator() do
local chips = E2Lib.PlayerChips[ply]
if not chips then continue end
local playerChipTime = chips:getTotalTime()
local playerHighChip, playerHighChipTime = chips:findMaxTimeChip()

if playerHighChipTime > highestChipTime then
highestChipTime = playerHighChipTime
highestChip = playerHighChip
end

totalChipTime = totalChipTime + playerChipTime * 1000
end

-- Terminate highest usage e2
if highestChip and e2_globalmax > -1 and totalChipTime > e2_globalmax * 0.001 then
highestChip:Error("Expression 2 (" .. highestChip.name .. "): global time quota exceeded", "global time quota exceeded")
highestChip:Destruct()
end
end )

function MakeWireExpression2(player, Pos, Ang, model, buffer, name, inputs, outputs, vars, inc_files, filepath, codeAuthor)
if not player then player = game.GetWorld() end -- For Garry's Map Saver
if IsValid(player) and not player:CheckLimit("wire_expressions") then return false end
Expand Down
1 change: 1 addition & 0 deletions lua/entities/gmod_wire_expression2/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function ENT:SetupDataTables()
end

CreateConVar("wire_expression2_unlimited", "0", {FCVAR_REPLICATED})
CreateConVar("wire_expression2_quota_globalmax", "-1", {FCVAR_REPLICATED}, "The maximum amount of time all E2s can consume before killing the highest one (-1 is infinite)")
CreateConVar("wire_expression2_quotasoft", "10000", {FCVAR_REPLICATED})
CreateConVar("wire_expression2_quotahard", "100000", {FCVAR_REPLICATED})
CreateConVar("wire_expression2_quotatick", "25000", {FCVAR_REPLICATED})
Expand Down
Loading