Lua API: GetAmmoTimer, to get the player-set timer for an ammo
authorWuzzy <Wuzzy2@mail.ru>
Thu, 03 May 2018 22:05:25 +0200
changeset 13376 da913fc1d350
parent 13375 e202d58236b1
child 13377 57e15407804d
Lua API: GetAmmoTimer, to get the player-set timer for an ammo
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Thu May 03 21:40:13 2018 +0200
+++ b/ChangeLog.txt	Thu May 03 22:05:25 2018 +0200
@@ -23,6 +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 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 21:40:13 2018 +0200
+++ b/hedgewars/uScript.pas	Thu May 03 22:05:25 2018 +0200
@@ -2976,6 +2976,26 @@
     lc_getammoname:= 1;
 end;
 
+function lc_getammotimer(L : Plua_state) : LongInt; Cdecl;
+var at: LongInt;
+    weapon: PAmmo;
+const call = 'GetAmmoTimer';
+      params = 'ammoType, gearUid';
+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)
+        else
+            lua_pushnil(L);
+        end
+    else
+        lua_pushnil(L);
+    lc_getammotimer:= 1;
+end;
+
 function lc_setvampiric(L : Plua_state) : LongInt; Cdecl;
 begin
     if CheckLuaParamCount(L, 1, 'SetVampiric', 'bool') then
@@ -3971,6 +3991,7 @@
 lua_register(luaState, _P'SetCinematicMode', @lc_setcinematicmode);
 lua_register(luaState, _P'SetMaxBuildDistance', @lc_setmaxbuilddistance);
 lua_register(luaState, _P'GetAmmoName', @lc_getammoname);
+lua_register(luaState, _P'GetAmmoTimer', @lc_getammotimer);
 lua_register(luaState, _P'SetVampiric', @lc_setvampiric);
 lua_register(luaState, _P'SetLaserSight', @lc_setlasersight);
 lua_register(luaState, _P'Explode', @lc_explode);