Skip to content

Commit c38b3e7

Browse files
committed
Switch "internal" parameter to checking enabled setting directly
1 parent 4b60e3e commit c38b3e7

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

lua/fpp/server/core.lua

+24-21
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ end)
141141
FPP.Protect = {}
142142

143143
--Physgun Pickup
144-
function FPP.Protect.PhysgunPickup(ply, ent, internal)
145-
if not tobool(FPP.Settings.FPP_PHYSGUN1.toggle) then if not internal and FPP.UnGhost then FPP.UnGhost(ply, ent) end return end
144+
function FPP.Protect.PhysgunPickup(ply, ent)
145+
if not tobool(FPP.Settings.FPP_PHYSGUN1.toggle) then if FPP.UnGhost then FPP.UnGhost(ply, ent) end return end
146146
if not ent:IsValid() then return end
147147
local cantouch
148148
local skipReturn = false
149149

150-
if not internal and isfunction(ent.PhysgunPickup) then
150+
if isfunction(ent.PhysgunPickup) then
151151
cantouch = ent:PhysgunPickup(ply, ent)
152152
-- Do not return the value, the gamemode will do this
153153
-- Allows other hooks to run
@@ -159,7 +159,7 @@ function FPP.Protect.PhysgunPickup(ply, ent, internal)
159159
skipReturn = ent:IsPlayer()
160160
end
161161

162-
if cantouch and not internal and FPP.UnGhost then FPP.UnGhost(ply, ent) end
162+
if cantouch and FPP.UnGhost then FPP.UnGhost(ply, ent) end
163163
if not cantouch and not skipReturn then return false end
164164
end
165165
hook.Add("PhysgunPickup", "FPP.Protect.PhysgunPickup", FPP.Protect.PhysgunPickup)
@@ -205,7 +205,7 @@ end
205205
hook.Add("OnPhysgunFreeze", "FPP.Protect.PhysgunFreeze", FPP.PhysgunFreeze)
206206

207207
--Gravgun pickup
208-
function FPP.Protect.GravGunPickup(ply, ent, internal)
208+
function FPP.Protect.GravGunPickup(ply, ent)
209209
if not tobool(FPP.Settings.FPP_GRAVGUN1.toggle) then return end
210210

211211
if not IsValid(ent) then return end -- You don't want a cross when looking at the floor while holding right mouse
@@ -214,23 +214,23 @@ function FPP.Protect.GravGunPickup(ply, ent, internal)
214214

215215
local cantouch
216216

217-
if not internal and isfunction(ent.GravGunPickup) then
217+
if isfunction(ent.GravGunPickup) then
218218
cantouch = ent:GravGunPickup(ply, ent)
219219
elseif ent.GravGunPickup ~= nil then
220220
cantouch = ent.GravGunPickup
221221
else
222222
cantouch = not ent:IsPlayer() and FPP.plyCanTouchEnt(ply, ent, "Gravgun")
223223
end
224224

225-
if cantouch and not internal and FPP.UnGhost then FPP.UnGhost(ply, ent) end
226-
if cantouch == false and not internal then DropEntityIfHeld(ent) end
225+
if cantouch and FPP.UnGhost then FPP.UnGhost(ply, ent) end
226+
if cantouch == false then DropEntityIfHeld(ent) end
227227
end
228228
hook.Add("GravGunOnPickedUp", "FPP.Protect.GravGunPickup", FPP.Protect.GravGunPickup)
229229

230-
function FPP.Protect.CanGravGunPickup(ply, ent, internal)
230+
function FPP.Protect.CanGravGunPickup(ply, ent)
231231
if not tobool(FPP.Settings.FPP_GRAVGUN1.toggle) or not IsValid(ent) then return end
232232

233-
if not internal and isfunction(ent.GravGunPickup) then
233+
if isfunction(ent.GravGunPickup) then
234234
-- Function name different than gamemode's (GravGunPickup vs GravGunPickupAllowed)
235235
-- Override FPP's behavior when implemented
236236
local val = ent:GravGunPickup(ply, ent)
@@ -250,17 +250,17 @@ end
250250
hook.Add("GravGunPickupAllowed", "FPP.Protect.CanGravGunPickup", FPP.Protect.CanGravGunPickup)
251251

252252
--Gravgun punting
253-
function FPP.Protect.GravGunPunt(ply, ent, internal)
254-
if tobool(FPP.Settings.FPP_GRAVGUN1.noshooting) then if not internal then DropEntityIfHeld(ent) end return false end
253+
function FPP.Protect.GravGunPunt(ply, ent)
254+
if tobool(FPP.Settings.FPP_GRAVGUN1.noshooting) then DropEntityIfHeld(ent) return false end
255255
-- Do not reason further if gravgun protection is disabled.
256256
if not tobool(FPP.Settings.FPP_GRAVGUN1.toggle) then return end
257257

258-
if not IsValid(ent) then if not internal then DropEntityIfHeld(ent) end return end
258+
if not IsValid(ent) then DropEntityIfHeld(ent) return end
259259

260260
local cantouch
261261
local skipReturn = false
262262

263-
if not internal and isfunction(ent.GravGunPunt) then
263+
if isfunction(ent.GravGunPunt) then
264264
cantouch = ent:GravGunPunt(ply, ent)
265265
-- Do not return the value, the gamemode will do this
266266
-- Allows other hooks to run
@@ -271,22 +271,22 @@ function FPP.Protect.GravGunPunt(ply, ent, internal)
271271
cantouch = not ent:IsPlayer() and FPP.plyCanTouchEnt(ply, ent, "Gravgun")
272272
end
273273

274-
if cantouch and not internal and FPP.UnGhost then FPP.UnGhost(ply, ent) end
275-
if not cantouch and not internal then DropEntityIfHeld(ent) end
274+
if cantouch and FPP.UnGhost then FPP.UnGhost(ply, ent) end
275+
if not cantouch then DropEntityIfHeld(ent) end
276276
if not cantouch and not skipReturn then return false end
277277
end
278278
hook.Add("GravGunPunt", "FPP.Protect.GravGunPunt", FPP.Protect.GravGunPunt)
279279

280280
--PlayerUse
281-
function FPP.Protect.PlayerUse(ply, ent, internal)
281+
function FPP.Protect.PlayerUse(ply, ent)
282282
if not tobool(FPP.Settings.FPP_PLAYERUSE1.toggle) then return end
283283

284284
if not IsValid(ent) then return end
285285

286286
local cantouch
287287
local skipReturn = false
288288

289-
if not internal and isfunction(ent.PlayerUse) then
289+
if isfunction(ent.PlayerUse) then
290290
cantouch = ent:PlayerUse(ply, ent)
291291
-- Do not return the value, the gamemode will do this
292292
-- Allows other hooks to run
@@ -297,20 +297,20 @@ function FPP.Protect.PlayerUse(ply, ent, internal)
297297
cantouch = not ent:IsPlayer() and FPP.plyCanTouchEnt(ply, ent, "PlayerUse")
298298
end
299299

300-
if cantouch and not internal and FPP.UnGhost then FPP.UnGhost(ply, ent) end
300+
if cantouch and FPP.UnGhost then FPP.UnGhost(ply, ent) end
301301
if not cantouch and not skipReturn then return false end
302302
end
303303
hook.Add("PlayerUse", "FPP.Protect.PlayerUse", FPP.Protect.PlayerUse)
304304

305305
--EntityDamage
306-
function FPP.Protect.EntityDamage(ent, dmginfo, internal)
306+
function FPP.Protect.EntityDamage(ent, dmginfo)
307307
if not IsValid(ent) then return end
308308

309309
local inflictor = dmginfo:GetInflictor()
310310
local attacker = dmginfo:GetAttacker()
311311
local amount = dmginfo:GetDamage()
312312

313-
if not internal and isfunction(ent.EntityDamage) then
313+
if isfunction(ent.EntityDamage) then
314314
local val = ent:EntityDamage(ent, inflictor, attacker, amount, dmginfo)
315315
-- Do not return the value, the gamemode will do this
316316
if val ~= nil then return end
@@ -549,13 +549,15 @@ end
549549
hook.Add("CanTool", "FPP.Protect.CanTool", FPP.Protect.CanTool)
550550

551551
function FPP.Protect.CanEditVariable(ent, ply, key, varVal, editTbl)
552+
if not tobool(FPP.Settings.FPP_TOOLGUN1.toggle) then return true end
552553
local val = FPP.Protect.CanProperty(ply, "editentity", ent)
553554
if val ~= nil then return val end
554555
end
555556
hook.Add("CanEditVariable", "FPP.Protect.CanEditVariable", FPP.Protect.CanEditVariable)
556557

557558
function FPP.Protect.CanProperty(ply, property, ent)
558559
-- Use Toolgun because I'm way too lazy to make a new type
560+
if not tobool(FPP.Settings.FPP_TOOLGUN1.toggle) then return true end
559561
local cantouch = FPP.plyCanTouchEnt(ply, ent, "Toolgun")
560562

561563
if not cantouch then return false end
@@ -564,6 +566,7 @@ hook.Add("CanProperty", "FPP.Protect.CanProperty", FPP.Protect.CanProperty)
564566

565567
function FPP.Protect.CanDrive(ply, ent)
566568
-- Use Toolgun because I'm way too lazy to make a new type
569+
if not tobool(FPP.Settings.FPP_TOOLGUN1.toggle) then return true end
567570
local cantouch = FPP.plyCanTouchEnt(ply, ent, "Toolgun")
568571

569572
if not cantouch then return false end

lua/fpp/sh_cppi.lua

+10-14
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,28 @@ if SERVER then
7272
end
7373

7474
function ENTITY:CPPICanPhysgun(ply)
75-
local canphysgun = FPP.Protect.PhysgunPickup(ply, self, true)
76-
return canphysgun == nil and true or canphysgun
75+
if not tobool(FPP.Settings.FPP_PHYSGUN1.toggle) then return true end
76+
return FPP.plyCanTouchEnt(ply, self, "Physgun")
7777
end
7878

7979
function ENTITY:CPPICanPickup(ply)
80-
local canpickup = FPP.Protect.CanGravGunPickup(ply, self)
81-
return canpickup == nil and true or canpickup
80+
if not tobool(FPP.Settings.FPP_PHYSGUN1.toggle) then return true end
81+
return FPP.plyCanTouchEnt(ply, self, "Gravgun")
8282
end
8383

8484
function ENTITY:CPPICanPunt(ply)
85-
local canpunt = FPP.Protect.GravGunPunt(ply, self, true)
86-
return canpunt == nil and true or canpunt
85+
if not tobool(FPP.Settings.FPP_GRAVGUN1.toggle) then return true end
86+
return FPP.plyCanTouchEnt(ply, self, "Gravgun")
8787
end
8888

8989
function ENTITY:CPPICanUse(ply)
90-
local canuse = FPP.Protect.PlayerUse(ply, self, true)
91-
return canuse == nil and true or canuse
90+
if not tobool(FPP.Settings.FPP_PLAYERUSE1.toggle) then return true end
91+
return FPP.plyCanTouchEnt(ply, self, "PlayerUse")
9292
end
9393

9494
function ENTITY:CPPICanDamage(ply)
95-
local dmginfo = DamageInfo()
96-
dmginfo:SetAttacker(ply)
97-
dmginfo:SetDamage(-1)
98-
99-
FPP.Protect.EntityDamage(self, dmginfo, true)
100-
return dmginfo:GetDamage() == -1
95+
if not tobool(FPP.Settings.FPP_ENTITYDAMAGE1.toggle) then return true end
96+
return FPP.plyCanTouchEnt(ply, self, "EntityDamage")
10197
end
10298

10399
function ENTITY:CPPIDrive(ply)

0 commit comments

Comments
 (0)