From 9b32920913790ce917abfc11368e736f5773e2cd Mon Sep 17 00:00:00 2001 From: Melow Date: Sun, 20 Mar 2022 20:20:01 +0200 Subject: [PATCH 1/4] Fixed entering sights when weapon isn't deployed --- lua/weapons/arc9_base/sh_scope.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/weapons/arc9_base/sh_scope.lua b/lua/weapons/arc9_base/sh_scope.lua index 290c961d..e8e29184 100644 --- a/lua/weapons/arc9_base/sh_scope.lua +++ b/lua/weapons/arc9_base/sh_scope.lua @@ -7,6 +7,7 @@ function SWEP:EnterSights() if !self:GetProcessedValue("HasSights") then return end if self:GetCustomize() then return end if !self:GetProcessedValue("ReloadInSights") and self:GetReloading() then return end + if self:GetHolster_Time() > 0 then return end self:ToggleBlindFire(false) self:SetInSights(true) From 1dead3a3e0c70ed5297ce6f34d37321a6e11781e Mon Sep 17 00:00:00 2001 From: Melow Date: Fri, 28 Feb 2025 00:11:09 +0200 Subject: [PATCH 2/4] fix(hooks): correct logic causing incorrect behavior in return value Fixed an issue where returning the 'false' value resulted in no output due to the 'or' operator always selecting the second argument. This was due to the way the 'or' operator works, where it prioritizes the first truthy value. The fix ensures the correct value is returned in cases where the 'false' value should be considered. --- lua/weapons/arc9_base/sh_0_stats.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/weapons/arc9_base/sh_0_stats.lua b/lua/weapons/arc9_base/sh_0_stats.lua index 373f93e9..8cf9414b 100644 --- a/lua/weapons/arc9_base/sh_0_stats.lua +++ b/lua/weapons/arc9_base/sh_0_stats.lua @@ -192,7 +192,10 @@ do any = true end - data = hook.Run("ARC9_" .. val, self, data) or data + data2 = hook.Run("ARC9_" .. val, self, data) + if data2 ~= nil then + data = data2 + end return data, any end @@ -229,7 +232,10 @@ do end self.HookCache[val] = newCache - data = hook.Run("ARC9_" .. val, self, data) or data + data2 = hook.Run("ARC9_" .. val, self, data) + if data2 ~= nil then + data = data2 + end return data, any end From 1c081c343740506997f5e0e11142e8cbc5921009 Mon Sep 17 00:00:00 2001 From: Melow Date: Fri, 28 Feb 2025 00:22:35 +0200 Subject: [PATCH 3/4] feat(hooks): add 'Hook_CanDetachAttachment' to prevent attachment detaching --- lua/weapons/arc9_base/sh_attach.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/weapons/arc9_base/sh_attach.lua b/lua/weapons/arc9_base/sh_attach.lua index cf967d9f..a1ab4a80 100644 --- a/lua/weapons/arc9_base/sh_attach.lua +++ b/lua/weapons/arc9_base/sh_attach.lua @@ -602,6 +602,8 @@ function SWEP:CanDetach(addr) if slottbl and slottbl.Integral then return false end + if self:RunHook("Hook_CanDetachAttachment", {addr = addr, slottbl = slottbl}) == false then return false end + return true end From d18acfd3753dba0d1b7b1276a8751feaae89972c Mon Sep 17 00:00:00 2001 From: Darsu <95997959+dar-su@users.noreply.github.com> Date: Fri, 28 Feb 2025 12:53:53 +0700 Subject: [PATCH 4/4] random 3yr old file lol --- lua/weapons/arc9_base/sh_scope.lua | 203 ----------------------------- 1 file changed, 203 deletions(-) delete mode 100644 lua/weapons/arc9_base/sh_scope.lua diff --git a/lua/weapons/arc9_base/sh_scope.lua b/lua/weapons/arc9_base/sh_scope.lua deleted file mode 100644 index e8e29184..00000000 --- a/lua/weapons/arc9_base/sh_scope.lua +++ /dev/null @@ -1,203 +0,0 @@ -function SWEP:GetSightDelta() - return self:GetSightAmount() -end - -function SWEP:EnterSights() - if self:GetSprintAmount() > 0 then return end - if !self:GetProcessedValue("HasSights") then return end - if self:GetCustomize() then return end - if !self:GetProcessedValue("ReloadInSights") and self:GetReloading() then return end - if self:GetHolster_Time() > 0 then return end - - self:ToggleBlindFire(false) - self:SetInSights(true) - self:EmitSound(self:RandomChoice(self:GetProcessedValue("EnterSightsSound")), 100, 75) - - self:PlayAnimation("enter_sights", self:GetProcessedValue("AimDownSightsTime")) - - self:SetShouldHoldType() - - self:BuildMultiSight() -end - -function SWEP:ExitSights() - self:SetInSights(false) - self:EmitSound(self:RandomChoice(self:GetProcessedValue("ExitSightsSound")), 100, 75) - - self:PlayAnimation("exit_sights", self:GetProcessedValue("AimDownSightsTime")) - - self:SetShouldHoldType() -end - -function SWEP:ThinkSights() - if self:GetSafe() then return end - - local sighted = self:GetInSights() - - local amt = self:GetSightAmount() - - if sighted then - amt = math.Approach(amt, 1, FrameTime() / self:GetProcessedValue("AimDownSightsTime")) - else - amt = math.Approach(amt, 0, FrameTime() / self:GetProcessedValue("AimDownSightsTime")) - end - - if CLIENT then - self:GetVM():SetPoseParameter("sights", amt) - end - - self:SetSightAmount(amt) - - if sighted and !self:GetOwner():KeyDown(IN_ATTACK2) then - self:ExitSights() - elseif !sighted and self:GetOwner():KeyDown(IN_ATTACK2) then - if self:GetOwner():KeyDown(IN_USE) then - return - end - - self:EnterSights() - end - - if sighted then - if self:GetOwner():KeyPressed(IN_USE) and self:GetOwner():KeyDown(IN_WALK) and IsFirstTimePredicted() then - -- if CurTime() - self:GetLastPressedETime() < 0.33 then - if self:GetOwner():KeyDown(IN_SPEED) then - self:SwitchMultiSight(-1) - else - self:SwitchMultiSight() - end - -- self:SetLastPressedETime(0) - -- else - -- self:SetLastPressedETime(CurTime()) - -- end - end - end -end - -SWEP.MultiSightTable = { - -- { - -- Pos = Vector(0, 0, 0), - -- Ang = Angle(0, 0, 0) - -- } -} - -function SWEP:BuildMultiSight() - self.MultiSightTable = {} - - local keepbaseirons = true - - for i, slottbl in ipairs(self:GetSubSlotList()) do - if !slottbl.Installed then continue end - if slottbl.BlockSights then continue end - local atttbl = self:GetFinalAttTable(slottbl) - - if atttbl.Sights then - for _, sight in pairs(atttbl.Sights) do - local s = {} - - if CLIENT then - s = self:GenerateAutoSight(sight, slottbl) - end - - if sight.Disassociate then - s.Disassociate = true - end - - s.atttbl = atttbl - s.OriginalSightTable = sight - s.slottbl = slottbl - - table.insert(self.MultiSightTable, s) - - if self.ScrollLevels[#self.MultiSightTable] then - s.ScrollLevel = self.ScrollLevels[#self.MultiSightTable] - end - end - - if !slottbl.KeepBaseIrons and !atttbl.KeepBaseIrons then - keepbaseirons = false - end - end - end - - if keepbaseirons then - local tbl = {} - table.insert(tbl, self:GetProcessedValue("IronSights")) - table.Add(tbl, self.MultiSightTable) - self.MultiSightTable = tbl - end - - if self:GetMultiSight() > #self.MultiSightTable then - self:SetMultiSight(1) - end -end - -function SWEP:SwitchMultiSight(amt) - amt = amt or 1 - local old_msi = self:GetMultiSight() - msi = old_msi - msi = msi + amt - - if msi > #self.MultiSightTable then - msi = 1 - elseif msi <= 0 then - msi = #self.MultiSightTable - end - - self:SetMultiSight(msi) - - self:InvalidateCache() - - if msi != old_msi then - // eh put some code in here - end -end - -function SWEP:GetSight() - if GetConVar("developer"):GetBool() then - self:BuildMultiSight() - end - return self.MultiSightTable[self:GetMultiSight()] or self:GetValue("IronSights") -end - -function SWEP:GetRTScopeFOV() - local sights = self:GetSight() - - if !sights then return self:GetOwner():GetFOV() end - - local atttbl = sights.atttbl - - local scrolllevel = sights.ScrollLevel or 0 - - if atttbl.RTScopeAdjustable then - return Lerp(scrolllevel / atttbl.RTScopeAdjustmentLevels, atttbl.RTScopeFOVMax, atttbl.RTScopeFOVMin) - else - return atttbl.RTScopeFOV - end -end - -SWEP.ScrollLevels = {} - -function SWEP:Scroll(amt) - local sights = self:GetSight() or {} - - local atttbl = sights.atttbl - - if !atttbl then return end - if !atttbl.RTScopeAdjustable then return end - if !atttbl.RTScopeFOVMax then return end - if !atttbl.RTScopeFOVMin then return end - - local scrolllevel = sights.ScrollLevel or 0 - local old = scrolllevel - - sights.ScrollLevel = scrolllevel + amt - - sights.ScrollLevel = math.Clamp(sights.ScrollLevel, 0, atttbl.RTScopeAdjustmentLevels) - - self.ScrollLevels[self:GetMultiSight()] = sights.ScrollLevel - - if old != sights.ScrollLevel then - self:EmitSound(atttbl.ZoomSound or "arc9/useatt.wav", 75, math.Rand(95, 105), 1, CHAN_ITEM) - end -end \ No newline at end of file