hedgewars/uScript.pas
changeset 5703 637fb1e6487b
parent 5678 35aa435d19f9
child 5725 e27100a0e2d0
child 5825 a6eab1b7c00d
--- a/hedgewars/uScript.pas	Mon Aug 29 23:56:38 2011 +0200
+++ b/hedgewars/uScript.pas	Mon Aug 29 19:28:45 2011 -0400
@@ -279,9 +279,9 @@
     else begin
         if lua_gettop(L) = 3 then health:= lua_tointeger(L, 3)
         else health:= cHealthCaseAmount;
-        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            HealthCrate, health);
-        lua_pushinteger(L, gear^.uid);
+        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health);
+        if gear <> nil then lua_pushinteger(L, gear^.uid)
+        else lua_pushnil(L);
     end;
     lc_spawnhealthcrate := 1;        
 end;
@@ -294,9 +294,9 @@
         lua_pushnil(L);
     end
     else begin
-        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            AmmoCrate, lua_tointeger(L, 3));
-        lua_pushinteger(L, gear^.uid);
+        gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3));
+        if gear <> nil then lua_pushinteger(L, gear^.uid)
+        else lua_pushnil(L);
     end;
     lc_spawnammocrate := 1;
 end;
@@ -311,7 +311,8 @@
     else begin  
         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
             UtilityCrate, lua_tointeger(L, 3));
-        lua_pushinteger(L, gear^.uid);
+        if gear <> nil then lua_pushinteger(L, gear^.uid)
+        else lua_pushnil(L);
     end;
     lc_spawnutilitycrate := 1;
 end;