hedgewars/uScript.pas
changeset 12952 c8b7bc04eb4c
parent 12944 0112ef349ddc
child 13023 0248cf0da834
--- a/hedgewars/uScript.pas	Fri Feb 09 19:58:55 2018 +0100
+++ b/hedgewars/uScript.pas	Fri Feb 09 21:04:53 2018 +0100
@@ -1689,7 +1689,7 @@
 
 function lc_addammo(L : Plua_State) : LongInt; Cdecl;
 var gear : PGear;
-    at, n: LongInt;
+    at, n, c: LongInt;
 const
     call = 'AddAmmo';
     params = 'gearUid, ammoType [, ammoCount]';
@@ -1697,14 +1697,19 @@
     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
         begin
         at:= LuaToAmmoTypeOrd(L, 2, call, params);
-        if at >= 0 then
+        if (at >= 0) and (TAmmoType(at) <> amNothing) then
             begin
             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
             if (gear <> nil) and (gear^.Hedgehog <> nil) then
                 if n = 2 then
                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
                 else
-                    SetAmmo(gear^.Hedgehog^, TAmmoType(at), Trunc(lua_tonumber(L, 3)))
+                    begin
+                    c:= Trunc(lua_tonumber(L, 3));
+                    if (c = 0) and (CurrentHedgehog = gear^.Hedgehog) and (gear^.Hedgehog^.CurAmmoType = TAmmoType(at)) then
+                        ParseCommand('setweap ' + char(0), true, true);
+                    SetAmmo(gear^.Hedgehog^, TAmmoType(at), c);
+                    end;
             end;
         end;
     lc_addammo:= 0