Skip to content

Commit 463f626

Browse files
Bonyozetextstack
andauthored
ACF damage permission changes (#12)
* Add ACF squishy damage override * Remove ACF damage gravgun check * update warden's ui for new ACF config * always call the old ACF.Check * update help text * remove commented code --------- Co-authored-by: textstack <[email protected]>
1 parent 5acdcfc commit 463f626

File tree

5 files changed

+50
-41
lines changed

5 files changed

+50
-41
lines changed

lua/warden/gui/cl_menu.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ local function setPerms(panel)
1313
panel:CheckBox(Warden.L("Let me touch my own entities"), "warden_touch_self")
1414
panel:CheckBox(Warden.L("Save my perms across sessions"), "warden_perm_persist")
1515

16+
hook.Run("WardenPermsHeader", panel)
17+
1618
setPermPnl = vgui.Create("WardenSetPerms")
1719
panel:AddItem(setPermPnl)
1820

lua/warden/intercompat/cl_acf.lua

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,14 @@
1+
CreateClientConVar("warden_acf_squishy_damage", "1", true, true, "Whether ACF should treat all your entities as squishy when inflicting damage", 0, 1)
2+
13
hook.Add("WardenSettingsExtra", "WardenACF", function(panel)
24
if not GetGlobalBool("WardenACF", false) then return end
35

46
Warden.AddSpacer(panel)
57
Warden.SetUpCheck(panel, "Override ACF's perms", "override_acf")
68
end)
79

8-
local function paintOverACF(item)
9-
item.OldCPanelFunction = item.OldCPanelFunction or item.CPanelFunction
10-
if not item.OldCPanelFunction then return end
11-
12-
function item.CPanelFunction(panel)
13-
item.OldCPanelFunction(panel)
14-
15-
function panel:PaintOver(w, h)
16-
local headerHeight = self:GetHeaderHeight()
17-
18-
if headerHeight >= h then return end
19-
if not Warden.GetServerBool("override_acf", false) then return end
20-
21-
surface.SetDrawColor(255, 0, 0)
22-
surface.DrawOutlinedRect(0, headerHeight, w, h - headerHeight, 2)
23-
end
24-
end
25-
end
26-
27-
local function acfOverride()
28-
local toolMenu = spawnmenu.GetToolMenu("Utilities")
29-
for _, v in ipairs(toolMenu) do
30-
if v.ItemName ~= "ACF" then continue end
31-
32-
for _, v1 in ipairs(v) do
33-
paintOverACF(v1)
34-
end
35-
end
36-
end
10+
hook.Add("WardenPermsHeader", "WardenACF", function(panel)
11+
if not GetGlobalBool("WardenACF", false) then return end
3712

38-
hook.Add("PopulateToolMenu", "WardenACF", function()
39-
timer.Simple(0, function()
40-
if GetGlobalBool("WardenACF", false) then
41-
acfOverride()
42-
end
43-
end)
44-
end)
13+
panel:CheckBox(Warden.L("Make my entities ACF-squishy"), "warden_acf_squishy_damage")
14+
end)

lua/warden/intercompat/sv_acf.lua

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
hook.Add("PostGamemodeLoaded", "WardenACFCompat", function()
2-
if not ACF or not ACF.Permissions then return end
2+
if not ACF or not ACF.Permissions or not ACF.Damage then return end
33

44
local oldCanDamage = ACF.Permissions.CanDamage
55
function ACF.Permissions.CanDamage(ent, _, dmgInfo)
@@ -12,12 +12,47 @@ hook.Add("PostGamemodeLoaded", "WardenACFCompat", function()
1212

1313
local attacker = dmgInfo:GetAttacker()
1414
if not Warden.CheckPermission(attacker, ent, Warden.PERMISSION_DAMAGE) then return false end
15-
if not Warden.CheckPermission(attacker, ent, Warden.PERMISSION_GRAVGUN) then return false end
1615

17-
return true
16+
return oldCanDamage(ent, nil, dmgInfo)
1817
end
1918

2019
hook.Add("ACF_PreDamageEntity", "ACF_DamagePermissionCore", ACF.Permissions.CanDamage)
2120

21+
local doSquishyDamage = ACF.Damage.doSquishyDamage
22+
23+
local function isForcedSquishy(ent)
24+
local owner = ent:WardenGetOwner()
25+
return IsValid(owner) and owner:IsPlayer() and owner:GetInfoNum("warden_acf_squishy_damage", 1) ~= 0
26+
end
27+
28+
local function overrideOnDamage(self, ...)
29+
-- use the squishy damage handler instead of the entity's custom method
30+
if isForcedSquishy(self) then
31+
return doSquishyDamage(self, ...)
32+
end
33+
return self:ACF_OldOnDamage(...)
34+
end
35+
36+
local oldCheck = ACF.Check
37+
function ACF.Check(ent, forceUpdate)
38+
local value = oldCheck(ent, forceUpdate)
39+
if value ~= false then
40+
if isForcedSquishy(ent) then
41+
if ent.ACF_OnDamage and not ent.ACF_OldOnDamage then
42+
ent.ACF_OldOnDamage = ent.ACF_OnDamage
43+
ent.ACF_OnDamage = overrideOnDamage
44+
end
45+
-- tell ACF to treat this entity as squishy
46+
return "Squishy"
47+
else
48+
if ent.ACF_OldOnDamage then
49+
ent.ACF_OnDamage = ent.ACF_OldOnDamage
50+
ent.ACF_OldOnDamage = nil
51+
end
52+
end
53+
end
54+
return value
55+
end
56+
2257
SetGlobalBool("WardenACF", true)
2358
end)

resource/localization/en-PT/warden.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@ warden.notify_the_server_on_cleanup=Tell the whole ship when swabbing
109109
warden.allow_physgun_reload=Allow physgun reload
110110
warden.notify_when_perms_are_granted-revoked=Say when perms are given/stolen
111111
warden.-s_has_granted_you_-s_access=%s has given you %s access
112-
warden.-s_has_revoked_-s_access_from_you=%s has stolen %s access from you
112+
warden.-s_has_revoked_-s_access_from_you=%s has stolen %s access from you
113+
warden.make_my_entities_acf-squishy=Make my things ACF-squishy

resource/localization/en/warden.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@ warden.notify_the_server_on_cleanup=Notify the server on cleanup
109109
warden.allow_physgun_reload=Allow physgun reload
110110
warden.notify_when_perms_are_granted-revoked=Notify when perms are granted/revoked
111111
warden.-s_has_granted_you_-s_access=%s has granted you %s access
112-
warden.-s_has_revoked_-s_access_from_you=%s has revoked %s access from you
112+
warden.-s_has_revoked_-s_access_from_you=%s has revoked %s access from you
113+
warden.make_my_entities_acf-squishy=Make my entities ACF-squishy

0 commit comments

Comments
 (0)