Fix GetAmmoTimer implementation, swap arguments
authorWuzzy <Wuzzy2@mail.ru>
Thu, 03 May 2018 22:42:29 +0200
changeset 13378 0a93948e8ec7
parent 13377 57e15407804d
child 13379 e1aa72e0872e
Fix GetAmmoTimer implementation, swap arguments
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Thu May 03 22:12:13 2018 +0200
+++ b/ChangeLog.txt	Thu May 03 22:42:29 2018 +0200
@@ -23,7 +23,7 @@
 
 Lua API:
  + New call: Retreat(time [, respectGetAwayTimeFactor): Force current turn into retreating mode
- + New call: GetAmmoTimer(ammoType, gearUid): Returns current set timer for given ammoType and hog gear in ms. Returns nil for non-timerable ammo
+ + New call: GetAmmoTimer(gearUid, ammoType): Returns current set timer for given ammoType and hog gear in ms. Returns nil for non-timerable ammo
  + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available”
  * Fix hog being unable to walk after using sniper rifle without firing both shots
 
--- a/hedgewars/uScript.pas	Thu May 03 22:12:13 2018 +0200
+++ b/hedgewars/uScript.pas	Thu May 03 22:42:29 2018 +0200
@@ -2979,15 +2979,22 @@
 function lc_getammotimer(L : Plua_state) : LongInt; Cdecl;
 var at: LongInt;
     weapon: PAmmo;
+    gear: PGear;
 const call = 'GetAmmoTimer';
-      params = 'ammoType, gearUid';
+      params = 'gearUid, ammoType';
 begin
     if CheckLuaParamCount(L, 2, call, params) then
         begin
-        at:= LuaToAmmoTypeOrd(L, 1, call, params);
-        weapon:= GetAmmoEntry(CurrentHedgehog^, TAmmoType(at));
-        if (Ammoz[TAmmoType(at)].Ammo.Propz and ammoprop_Timerable) <> 0 then
-            lua_pushnumber(L, weapon^.Timer)
+        gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
+        if (gear <> nil) and (gear^.Hedgehog <> nil) then
+            begin
+            at:= LuaToAmmoTypeOrd(L, 2, call, params);
+            weapon:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(at));
+            if (Ammoz[TAmmoType(at)].Ammo.Propz and ammoprop_Timerable) <> 0 then
+                lua_pushnumber(L, weapon^.Timer)
+            else
+                lua_pushnil(L);
+            end
         else
             lua_pushnil(L);
         end