Lua: AddTeam / AddMissionTeam now return team index
authorWuzzy <Wuzzy2@mail.ru>
Wed, 19 Dec 2018 20:34:07 +0100
changeset 14484 4e5280a9e782
parent 14483 35724823b0d3
child 14485 208359558642
Lua: AddTeam / AddMissionTeam now return team index
ChangeLog.txt
hedgewars/uScript.pas
--- 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
--- 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;