Centralize pac_onuse_only

This commit is contained in:
Redox 2022-11-20 02:29:50 +01:00
parent f05e8fea0c
commit 2bb09cde8a
No known key found for this signature in database
GPG Key ID: C10A433A95068388
3 changed files with 15 additions and 10 deletions

View File

@ -573,3 +573,11 @@ end
function pac.FlashlightDisable(b)
pac.flashlight_disabled = b
end
local pacOnUseConvar = CreateClientConVar('pac_onuse_only', '0', true, false, 'Enable "on +use only" mode. Within this mode, outfits are not being actually "loaded" until you hover over player and press your use button')
function pac.IsPacOnUseOnly()
local clientConvarBool = pacOnUseConvar:GetBool()
return clientConvarBool
end

View File

@ -1,12 +1,11 @@
local pac_onuse_only = CreateClientConVar('pac_onuse_only', '0', true, false, 'Enable "on +use only" mode. Within this mode, outfits are not being actually "loaded" until you hover over player and press your use button')
local L = pace.LanguageString
local MAX_DIST = 270
local pac_IsPacOnUseOnly = pac.IsPacOnUseOnly
hook.Add("PlayerBindPress", "pac_onuse_only", function(ply, bind, isPressed)
if bind ~= "use" and bind ~= "+use" then return end
if bind ~= "+use" and isPressed then return end
if not pac_onuse_only:GetBool() then return end
if not pac_IsPacOnUseOnly() then return end
local eyes, aim = ply:EyePos(), ply:GetAimVector()
local tr = util.TraceLine({
@ -34,7 +33,7 @@ do
})
hook.Add("HUDPaint", "pac_onuse_only", function(ply, bind, isPressed)
if not pac_onuse_only:GetBool() then return end
if not pac_IsPacOnUseOnly() then return end
local ply = pac.LocalPlayer
local eyes, aim = ply:EyePos(), ply:GetAimVector()
@ -55,8 +54,6 @@ do
end)
end
local pac_onuse_only = CreateClientConVar('pac_onuse_only', '0', true, false, 'Enable "on +use only" mode. Within this mode, outfits are not being actually "loaded" until you hover over player and press your use button')
function pace.OnUseOnlyUpdates(cvar, ...)
hook.Call('pace_OnUseOnlyUpdates', nil, ...)
end
@ -68,7 +65,7 @@ concommand.Add("pac_onuse_reset", function()
if ent.pac_onuse_only then
ent.pac_onuse_only_check = true
if pac_onuse_only:GetBool() then
if pac_IsPacOnUseOnly() then
pac.ToggleIgnoreEntity(ent, ent.pac_onuse_only_check, 'pac_onuse_only')
else
pac.ToggleIgnoreEntity(ent, false, 'pac_onuse_only')
@ -99,7 +96,7 @@ function pace.HandleOnUseReceivedData(data)
-- if TRUE - hide outfit
data.owner.pac_onuse_only_check = true
if pac_onuse_only:GetBool() then
if pac_IsPacOnUseOnly() then
pac.ToggleIgnoreEntity(data.owner, data.owner.pac_onuse_only_check, 'pac_onuse_only')
else
pac.ToggleIgnoreEntity(data.owner, false, 'pac_onuse_only')
@ -109,7 +106,7 @@ function pace.HandleOnUseReceivedData(data)
-- behaviour of this (if one of entities on this hook becomes invalid)
-- is undefined if DLib is not installed, but anyway
hook.Add('pace_OnUseOnlyUpdates', data.owner, function()
if pac_onuse_only:GetBool() then
if pac_IsPacOnUseOnly() then
pac.ToggleIgnoreEntity(data.owner, data.owner.pac_onuse_only_check, 'pac_onuse_only')
else
pac.ToggleIgnoreEntity(data.owner, false, 'pac_onuse_only')

View File

@ -229,7 +229,7 @@ net.Receive("pac_submit", function()
return
end
if GetConVar("pac_onuse_only") and GetConVar("pac_onuse_only"):GetBool() and data.owner ~= pac.LocalPlayer then
if pac.IsPacOnUseOnly() and data.owner ~= pac.LocalPlayer then
pace.HandleOnUseReceivedData(data)
else
pace.HandleReceiveData(data, true)