Lua API: Add GetTeamName
authorWuzzy <Wuzzy2@mail.ru>
Fri, 09 Feb 2018 04:37:27 +0100
changeset 12931 c27dd59a3ffe
parent 12930 330b6c353093
child 12932 e0da398805b6
Lua API: Add GetTeamName
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Thu Feb 08 19:02:51 2018 +0100
+++ b/ChangeLog.txt	Fri Feb 09 04:37:27 2018 +0100
@@ -32,6 +32,7 @@
  + New call: SetVampiric(bool): Toggle vampirism
  + New call: SetLaserSight(bool): Toggle laser sight
  + New call: GetWind(): Returns current wind (approximation) from -100 to 100
+ + New call: GetTeamName(teamIdx): Returns name of team with given index (starts at 0)
  + New callback: onEndTurn(): Called at the end of a turn (when gears have settled)
  * Fix call: SetWeapon(amNothing) now unselects weapon
  * Fix global: TotalRounds was stuck at -1 for several turns
--- a/hedgewars/uScript.pas	Thu Feb 08 19:02:51 2018 +0100
+++ b/hedgewars/uScript.pas	Fri Feb 09 04:37:27 2018 +0100
@@ -2051,6 +2051,22 @@
     lc_addteam:= 0;//1;
 end;
 
+function lc_getteamname(L : Plua_State) : LongInt; Cdecl;
+var t: LongInt;
+begin
+    if CheckLuaParamCount(L, 1, 'GetTeamName', 'teamIdx') then
+        begin
+        t:= Trunc(lua_tonumber(L, 1));
+        if (t < 0) or (t >= TeamsCount) then
+            lua_pushnil(L)
+        else
+            lua_pushstring(L, str2pchar(TeamsArray[t]^.TeamName));
+        end
+    else
+        lua_pushnil(L);
+    lc_getteamname:= 1;
+end;
+
 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl;
 var HHGear: PGear;
     i, h  : LongInt;
@@ -3636,6 +3652,7 @@
 lua_register(luaState, _P'SetAmmo', @lc_setammo);
 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
 lua_register(luaState, _P'PlaySound', @lc_playsound);
+lua_register(luaState, _P'GetTeamName', @lc_getteamname);
 lua_register(luaState, _P'AddTeam', @lc_addteam);
 lua_register(luaState, _P'AddHog', @lc_addhog);
 lua_register(luaState, _P'AddAmmo', @lc_addammo);