Fix errors if passing bad script param to [Tech]Racer
authorWuzzy <Wuzzy@disroot.org>
Wed, 28 Jun 2023 12:01:43 +0200
changeset 15994 d18261ddac4a
parent 15993 cf5c7fa71134
child 15995 634d017650dc
Fix errors if passing bad script param to [Tech]Racer
share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Wed Jun 28 07:28:52 2023 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Wed Jun 28 12:01:43 2023 +0200
@@ -191,22 +191,25 @@
         TeamRope = true
     end
     if params["rounds"] ~= nil then
-        roundLimit = math.max(1, math.floor(tonumber(params["rounds"])))
+        roundLimit = tonumber(params["rounds"])
         if type(roundLimit) ~= "number" then
              roundLimit = 3
         end
+        roundLimit = math.max(1, math.floor(roundLimit))
     end
     if params["waypointradius"] ~= nil then
-        wpRad = math.max(WAYPOINT_RADIUS_MIN, math.floor(tonumber(params["waypointradius"])))
+        wpRad = tonumber(params["waypointradius"])
         if type(wpRad) ~= "number" then
              wpRad = 450
         end
+        wpRad = math.max(WAYPOINT_RADIUS_MIN, math.floor(wpRad))
     end
     if params["maxwaypoints"] ~= nil then
-        wpLimit = math.max(2, math.floor(tonumber(params["maxwaypoints"])))
+        wpLimit = tonumber(params["maxwaypoints"])
         if type(wpLimit) ~= "number" then
              wpLimit = 8
         end
+        wpLimit = math.max(2, math.floor(wpLimit))
     end
 end
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Wed Jun 28 07:28:52 2023 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Wed Jun 28 12:01:43 2023 +0200
@@ -682,9 +682,10 @@
 
 	roundLimit = tonumber(params["rounds"])
 
-	if (roundLimit == 0) or (roundLimit == nil) then
+	if roundLimit == nil then
 		roundLimit = 3
 	end
+	roundLimit = math.max(1, math.floor(roundLimit))
 
 	if mapID == nil then
 		mapID = 2 + GetRandom(7)