# HG changeset patch
# User Wuzzy <Wuzzy2@mail.ru>
# Date 1545248047 -3600
# Node ID 4e5280a9e782c546a10b68a65d5acc9c5a0cfe6e
# Parent  35724823b0d3d4af0c278a934b117995c6226e23
Lua: AddTeam / AddMissionTeam now return team index

diff -r 35724823b0d3 -r 4e5280a9e782 ChangeLog.txt
--- a/ChangeLog.txt	Wed Dec 19 20:27:35 2018 +0100
+++ b/ChangeLog.txt	Wed Dec 19 20:34:07 2018 +0100
@@ -25,6 +25,7 @@
  + New call: GetTurnTimePaused(): Returns true if turn time is paused due to Lua
  + New call: AddMissionTeam(color): Add mission team, i.e. the team selected by player in campaign/mission page
  + New call: AddMissionHog(health): Add a hedgehog for the mission team
+ + New return value: AddTeam and AddMissionTeam return team index of new team
  + Utils library: New calls: getReadableChallengeRecord, updateChallengeRecord
  + New callback: onGameResult(winningClan): Called when the game ends normally. winningClan = index of winning clan or -1 on draw
  + Params explode, poison in the SpawnFake*Crate functions now optional and default to false
diff -r 35724823b0d3 -r 4e5280a9e782 hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Wed Dec 19 20:27:35 2018 +0100
+++ b/hedgewars/uScript.pas	Wed Dec 19 20:34:07 2018 +0100
@@ -2298,13 +2298,13 @@
         ParseCommand('fort ' + lua_tostring(L, 4), true, true);
         ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
         if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
-        CurrentTeam^.Binds:= DefaultBinds
-        // fails on x64
-        //lua_pushnumber(L, LongInt(CurrentTeam));
-        end;
-    //else
-        //lua_pushnil(L)
-    lc_addteam:= 0;//1;
+        CurrentTeam^.Binds:= DefaultBinds;
+        // push team index
+        lua_pushnumber(L, TeamsCount - 1);
+        end
+    else
+        lua_pushnil(L);
+    lc_addteam:= 1;
 end;
 
 function lc_addmissionteam(L : Plua_State) : LongInt; Cdecl;
@@ -2339,9 +2339,13 @@
         ParseCommand('fort ' + MissionTeam^.FortName, true, true);
         ParseCommand('voicepack ' + MissionTeam^.Voicepack^.name, true, true);
         ParseCommand('flag ' + MissionTeam^.Flag, true, true);
-        CurrentTeam^.Binds:= DefaultBinds
-        end;
-    lc_addmissionteam:= 0;
+        CurrentTeam^.Binds:= DefaultBinds;
+        // push team index
+        lua_pushnumber(L, TeamsCount - 1);
+        end
+    else
+        lua_pushnil(L);
+    lc_addmissionteam:= 1;
 end;
 
 function lc_setteamlabel(L : Plua_State) : LongInt; Cdecl;