Lua API: Add SetAmmoSlot
authorWuzzy <Wuzzy2@mail.ru>
Sat, 08 Jun 2019 11:25:39 +0200
changeset 15131 a77b0e339929
parent 15130 13e7d4eccb67
child 15132 378efa87f558
Lua API: Add SetAmmoSlot
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Fri Jun 07 15:09:42 2019 +0200
+++ b/ChangeLog.txt	Sat Jun 08 11:25:39 2019 +0200
@@ -164,6 +164,7 @@
  + New call: AddMissionHog(health): Add a hedgehog for the mission team
  + New call: SetTeamPassive(teamname, isPassive): Mark a team as passive. Passive teams do not play and are treated like frozen teams.
  + New call: IsHogAlive(gear): Returns true if gear is a hegehog which is alive, not about to die and not hidden
+ + New call: SetAmmoSlot(ammoType, slot): Overwrite ammo slot of ammo type (use with care!)
  + New return value: AddTeam/AddMissionTeam return <real team name>, <team index>
  + SetClanColor: Now accepts negative color argument for user clan color, like in AddTeam
  + AddTeam: Append “_qau” to voicepack name to enable automatic selection of voicepack language
--- a/hedgewars/uScript.pas	Fri Jun 07 15:09:42 2019 +0200
+++ b/hedgewars/uScript.pas	Sat Jun 08 11:25:39 2019 +0200
@@ -2931,6 +2931,19 @@
     lc_setammodelay:= 0
 end;
 
+function lc_setammoslot(L : Plua_State) : LongInt; Cdecl;
+var at, slot: LongInt;
+begin
+    if CheckLuaParamCount(L, 2, 'SetAmmoSlot', 'ammoType, slot') then
+        begin
+        at:= Trunc(lua_tonumber(L, 1));
+        slot:= Trunc(lua_tonumber(L, 2));
+        Ammoz[TAmmoType(at)].Slot:= slot - 1;
+        AmmoMenuInvalidated:= true;
+        end;
+    lc_setammoslot:= 0;
+end;
+
 function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
 var m : LongInt;
 begin
@@ -4472,6 +4485,7 @@
 lua_register(luaState, _P'SetAmmo', @lc_setammo);
 lua_register(luaState, _P'GetAmmo', @lc_getammo);
 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
+lua_register(luaState, _P'SetAmmoSlot', @lc_setammoslot);
 lua_register(luaState, _P'PlaySound', @lc_playsound);
 lua_register(luaState, _P'PlayMusicSound', @lc_playmusicsound);
 lua_register(luaState, _P'StopMusicSound', @lc_stopmusicsound);