Fix error if passing bad number script param to Battallion/Space Invasion
authorWuzzy <Wuzzy@disroot.org>
Wed, 28 Jun 2023 12:46:04 +0200
changeset 15965 634d017650dc
parent 15964 d18261ddac4a
child 15966 605697b8947a
Fix error if passing bad number script param to Battallion/Space Invasion
share/hedgewars/Data/Scripts/Multiplayer/Battalion.lua
share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua
--- a/share/hedgewars/Data/Scripts/Multiplayer/Battalion.lua	Wed Jun 28 12:01:43 2023 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Battalion.lua	Wed Jun 28 12:46:04 2023 +0200
@@ -1532,7 +1532,7 @@
     useVariantHats = params['mutate']
   end
 
-  if params['strength'] ~= nil and tonumber(params['strength']) > 0 then
+  if params['strength'] ~= nil and tonumber(params['strength']) ~= nil and tonumber(params['strength']) > 0 then
     strength = tonumber(params['strength'])
     -- Highland
     if mode == 'highland' then
@@ -1561,7 +1561,7 @@
     end
   end
 
-  if params['luck'] ~= nil and tonumber(params['luck']) > 0 then
+  if params['luck'] ~= nil and tonumber(params['luck']) and tonumber(params['luck']) > 0 then
     luck = tonumber(params['luck'])
 
     healthCrateChance = div(healthCrateChance * luck, 100)
--- a/share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua	Wed Jun 28 12:01:43 2023 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua	Wed Jun 28 12:46:04 2023 +0200
@@ -1040,26 +1040,26 @@
 
 function onParameters()
 	parseParams()
-	if params["rounds"] ~= nil then
+	if params["rounds"] ~= nil and tonumber(params["rounds"]) then
 		SI.roundLimit = math.floor(tonumber(params["rounds"]))
 	end
-	if params["barrels"] ~= nil then
+	if params["barrels"] ~= nil and tonumber(params["barrels"]) then
 		SI.startBarrels = math.floor(tonumber(params["barrels"]))
 	end
-	if params["pings"] ~= nil then
+	if params["pings"] ~= nil and tonumber(params["pings"]) then
 		SI.startRadShots = math.floor(tonumber(params["pings"]))
 	end
-	if params["shield"] ~= nil then
+	if params["shield"] ~= nil and tonumber(params["shield"]) then
 		SI.startShield = math.min(250-80, math.floor(tonumber(params["shield"])))
 	end
 
-	if params["barrelbonus"] ~= nil then
+	if params["barrelbonus"] ~= nil and tonumber(params["barrelbonus"]) then
 		SI.barrelBonus = math.floor(tonumber(params["barrelbonus"]))
 	end
-	if params["shieldbonus"] ~= nil then
+	if params["shieldbonus"] ~= nil and tonumber(params["shieldbonus"]) then
 		SI.shieldBonus = math.floor(tonumber(params["shieldbonus"]))
 	end
-	if params["timebonus"] ~= nil then
+	if params["timebonus"] ~= nil and tonumber(params["timebonus"]) then
 		SI.timeBonus = math.floor(tonumber(params["timebonus"]))
 	end
 	if params["forcetheme"] == "false" then