hedgewars/uScript.pas
changeset 14393 c2cd3f64b9f7
parent 14366 2ab312c47dc3
child 14394 d670e4efe1ed
--- a/hedgewars/uScript.pas	Sun Dec 09 04:09:38 2018 +0300
+++ b/hedgewars/uScript.pas	Sun Dec 09 16:54:22 2018 +0100
@@ -686,11 +686,20 @@
 
 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
 var gear: PGear;
-begin
-    if CheckLuaParamCount(L, 4,'SpawnFakeHealthCrate', 'x, y, explode, poison') then
+    explode, poison: boolean;
+    n: LongInt;
+begin
+    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeHealthCrate', 'x, y [, explode [, poison]]', n) then
         begin
+        explode:= false;
+        poison:= false;
+        if (n >= 3) and (not lua_isnil(L, 3)) then
+            explode:= lua_toboolean(L, 3);
+        if (n = 4) and (not lua_isnil(L, 4)) then
+            poison:= lua_toboolean(L, 4);
+
         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
-        HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        HealthCrate, explode, poison);
         if gear <> nil then
              lua_pushnumber(L, gear^.uid)
         else lua_pushnil(L)
@@ -702,11 +711,20 @@
 
 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
-begin
-    if CheckLuaParamCount(L, 4,'SpawnFakeAmmoCrate', 'x, y, explode, poison') then
+    explode, poison: boolean;
+    n: LongInt;
+begin
+    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeAmmoCrate', 'x, y [, explode [, poison]]', n) then
         begin
+        explode:= false;
+        poison:= false;
+        if (n >= 3) and (not lua_isnil(L, 3)) then
+            explode:= lua_toboolean(L, 3);
+        if (n = 4) and (not lua_isnil(L, 4)) then
+            poison:= lua_toboolean(L, 4);
+
         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
-        AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        AmmoCrate, explode, poison);
         if gear <> nil then
              lua_pushnumber(L, gear^.uid)
         else lua_pushnil(L)
@@ -718,11 +736,20 @@
 
 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
-begin
-    if CheckLuaParamCount(L, 4,'SpawnFakeUtilityCrate', 'x, y, explode, poison') then
+    explode, poison: boolean;
+    n: LongInt;
+begin
+    if CheckAndFetchParamCountRange(L, 2, 4, 'SpawnFakeUtilityCrate', 'x, y [, explode [, poison]]', n) then
         begin
+        explode:= false;
+        poison:= false;
+        if (n >= 3) and (not lua_isnil(L, 3)) then
+            explode:= lua_toboolean(L, 3);
+        if (n = 4) and (not lua_isnil(L, 4)) then
+            poison:= lua_toboolean(L, 4);
+
         gear := SpawnFakeCrateAt(Trunc(lua_tonumber(L, 1)), Trunc(lua_tonumber(L, 2)),
-        UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        UtilityCrate, explode, poison);
         if gear <> nil then
              lua_pushnumber(L, gear^.uid)
         else lua_pushnil(L)