SetAmmoDelay: Unselect weapon if neccessary
authorWuzzy <Wuzzy2@mail.ru>
Mon, 21 Jan 2019 02:52:09 +0100
changeset 14661 e6363b84b3fe
parent 14660 3e15412536c8
child 14662 7de65fa1f686
SetAmmoDelay: Unselect weapon if neccessary
hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Mon Jan 21 02:09:30 2019 +0100
+++ b/hedgewars/uScript.pas	Mon Jan 21 02:52:09 2019 +0100
@@ -2859,7 +2859,7 @@
 
 
 function lc_setammodelay(L : Plua_State) : LongInt; Cdecl;
-var at: LongInt;
+var at, delay: LongInt;
 const
     call = 'SetAmmoDelay';
     params = 'ammoType, delay';
@@ -2867,8 +2867,14 @@
     if CheckLuaParamCount(L, 2, call, params) then
         begin
         at:= LuaToAmmoTypeOrd(L, 1, call, params);
-        if at >= 0 then
-            ScriptSetAmmoDelay(TAmmoType(at), Trunc(lua_tonumber(L, 2)));
+        delay:= Trunc(lua_tonumber(L, 2));
+        if (at >= 0) and (TAmmoType(at) <> amNothing) then
+            begin
+            ScriptSetAmmoDelay(TAmmoType(at), delay);
+            // Unselect weapon if neccessary
+            if (delay > 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.CurAmmoType = TAmmoType(at)) then
+                ParseCommand('setweap ' + char(0), true, true);
+            end;
         end;
     lc_setammodelay:= 0
 end;