From 13e9cb018ef9dfdcd28fa8f880bbf686b8676a32 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Tue, 5 Nov 2024 00:05:59 +0800 Subject: [PATCH 1/3] Fix table used as int --- items/active/weapons/ranged/gunfire.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/items/active/weapons/ranged/gunfire.lua b/items/active/weapons/ranged/gunfire.lua index 8f72c51993b..b93bed96880 100644 --- a/items/active/weapons/ranged/gunfire.lua +++ b/items/active/weapons/ranged/gunfire.lua @@ -35,7 +35,8 @@ function GunFire:init() --self.magazineAmount = math.min(config.getParameter("magazineAmount",defaultMag),self.magazineSize) -- current number of bullets in the magazine --self.magazineAmount=config.getParameter("magazineAmount",defaultMag) self.magazineAmount=config.getParameter("magazineAmount"..self.abilitySlot,defaultMag) - self.reloadTime = math.max(0,config.getParameter("reloadTime",1) + status.stat("reloadTime")) -- how long does reloading mag take? + -- how long does reloading mag take? Ensure reloadTime config value is a number with tonumber fallback + self.reloadTime = math.max(0, (tonumber(config.getParameter("reloadTime", 1)) or 1) + (tonumber(status.stat("reloadTime")) or 0)) if (self.isAmmoBased==1) then self.timerRemoveAmmoBar = 0 @@ -78,10 +79,14 @@ function GunFire:init() end function GunFire:calcAmmo() - local oldSize=self.magazineSize - local magazineTemp=(self.ammoInheritanceMult or 1.0)*config.getParameter("magazineSize",1) - self.magazineSize = magazineTemp*(1+status.stat("magazineMultiplier")) + math.max(0,status.stat("magazineSize")) -- total count of the magazine - if (oldSize and oldSize~= self.magazineSize) then return true,oldSize end + local oldSize = self.magazineSize + -- Ensure config value is a number with tonumber fallback + local magazineTemp = (self.ammoInheritanceMult or 1.0) * (tonumber(config.getParameter("magazineSize", 1)) or 1) + self.magazineSize = magazineTemp * (1 + (tonumber(status.stat("magazineMultiplier")) or 0)) + math.max(0, (tonumber(status.stat("magazineSize")) or 0)) + + if oldSize and oldSize ~= self.magazineSize then + return true, oldSize + end end -- *********************************************************************************************************** From b6e0098570615de70e3dfde2242b690d47a24268 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Tue, 5 Nov 2024 19:40:43 +0800 Subject: [PATCH 2/3] Update gunfire.lua --- items/active/weapons/ranged/gunfire.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/items/active/weapons/ranged/gunfire.lua b/items/active/weapons/ranged/gunfire.lua index b93bed96880..a06427375c1 100644 --- a/items/active/weapons/ranged/gunfire.lua +++ b/items/active/weapons/ranged/gunfire.lua @@ -35,8 +35,13 @@ function GunFire:init() --self.magazineAmount = math.min(config.getParameter("magazineAmount",defaultMag),self.magazineSize) -- current number of bullets in the magazine --self.magazineAmount=config.getParameter("magazineAmount",defaultMag) self.magazineAmount=config.getParameter("magazineAmount"..self.abilitySlot,defaultMag) - -- how long does reloading mag take? Ensure reloadTime config value is a number with tonumber fallback - self.reloadTime = math.max(0, (tonumber(config.getParameter("reloadTime", 1)) or 1) + (tonumber(status.stat("reloadTime")) or 0)) + -- how long does reloading mag take? + local reloadTimeConfig = config.getParameter("reloadTime", 1) + if type(reloadTimeConfig) == "table" then + reloadTimeConfig = math.random(reloadTimeConfig[1], reloadTimeConfig[2]) - Ensure reloadTime config value is a number + end + self.reloadTime = math.max(0, (tonumber(reloadTimeConfig) or 1) + (tonumber(status.stat("reloadTime")) or 0)) + if (self.isAmmoBased==1) then self.timerRemoveAmmoBar = 0 @@ -80,8 +85,11 @@ end function GunFire:calcAmmo() local oldSize = self.magazineSize - -- Ensure config value is a number with tonumber fallback - local magazineTemp = (self.ammoInheritanceMult or 1.0) * (tonumber(config.getParameter("magazineSize", 1)) or 1) + local magazineSizeConfig = config.getParameter("magazineSize", 1) + if type(magazineSizeConfig) == "table" then + magazineSizeConfig = math.random(magazineSizeConfig[1], magazineSizeConfig[2]) -- Should done this when creating weapon, check it here if it doesn't + end + local magazineTemp = (self.ammoInheritanceMult or 1.0) * (tonumber(magazineSizeConfig) or 1) self.magazineSize = magazineTemp * (1 + (tonumber(status.stat("magazineMultiplier")) or 0)) + math.max(0, (tonumber(status.stat("magazineSize")) or 0)) if oldSize and oldSize ~= self.magazineSize then @@ -89,6 +97,7 @@ function GunFire:calcAmmo() end end + -- *********************************************************************************************************** -- *********************************************************************************************************** From c93e74f40d467d0a2937fa4d7f06b067de8fb504 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Tue, 5 Nov 2024 21:23:52 +0800 Subject: [PATCH 3/3] Update gunfire.lua --- items/active/weapons/ranged/gunfire.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/items/active/weapons/ranged/gunfire.lua b/items/active/weapons/ranged/gunfire.lua index a06427375c1..acd7a4621cb 100644 --- a/items/active/weapons/ranged/gunfire.lua +++ b/items/active/weapons/ranged/gunfire.lua @@ -38,7 +38,7 @@ function GunFire:init() -- how long does reloading mag take? local reloadTimeConfig = config.getParameter("reloadTime", 1) if type(reloadTimeConfig) == "table" then - reloadTimeConfig = math.random(reloadTimeConfig[1], reloadTimeConfig[2]) - Ensure reloadTime config value is a number + reloadTimeConfig = math.random(reloadTimeConfig[1], reloadTimeConfig[2]) -- Ensure reloadTime config value is a number end self.reloadTime = math.max(0, (tonumber(reloadTimeConfig) or 1) + (tonumber(status.stat("reloadTime")) or 0))