Using Lua to meet other civs

turingmachine

Emperor
Joined
May 4, 2008
Messages
1,438
I've been trying to get something to work but haven't been having any luck. Essentially I want a player to meet all the other civs at a specific turn (and separately meet all the city states at a different turn). Is this possible with Lua? Is there a team meet team function?
 
pTeam:Meet(iTeam, bShowMessages)

see TurnsRemaining.lua in the G&K Medieval Scenario

you may also need to test pTeam:IsHasMet(iTeam) before calling it to avoid meeting teams you have already met again
 
pTeam:Meet(iTeam, bShowMessages)

see TurnsRemaining.lua in the G&K Medieval Scenario

you may also need to test pTeam:IsHasMet(iTeam) before calling it to avoid meeting teams you have already met again

Thank you very much. I assume that would only work on major civs, would I need to use something else to meet city states (do the minor civs even have a team?)?
 
Even the barbarians have a team. Minor civs certainly do and you can use the meet function with them.
 
for i = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS - 2 do
 
That loop will, as whoward wrote it, loop over all the minor civ IDs. The civs (major and minor) are all indexed by ID. Say there are 4 major civs and 10 minor civs. Since arrays are indexed starting at 0, the 4 major civs are entry 0,1,2,3. If you want to go through all of the minor civs, you iterate over 4 to 13. (Whoward subtracts 2 from the maximum, I assume because there's a barbarian civ at the end.) The ID of the first minor civ will always be the total number of major civs in a given game.
 
That loop will, as whoward wrote it, loop over all the minor civ IDs. The civs (major and minor) are all indexed by ID. Say there are 4 major civs and 10 minor civs. Since arrays are indexed starting at 0, the 4 major civs are entry 0,1,2,3. If you want to go through all of the minor civs, you iterate over 4 to 13. (Whoward subtracts 2 from the maximum, I assume because there's a barbarian civ at the end.) The ID of the first minor civ will always be the total number of major civs in a given game.

Ah, that explains a lot actually. I was thinking major and minor civs were treated almost completely separately in a lot of instances.

Thanks for all the help and explanations, everyone.
 
Okay, I'm sorry that I keep on bothering you guys.

So say I use something like this, just to test it out:

Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
  if Game.GetGameTurn() == 1 then
    local pPlayer = Players[iPlayer];
    local pTeam = pPlayer:GetTeam();
    if (pPlayer:IsAlive()) then
      for i = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS - 2 do 
        local tPlayer = Players[i];
        if (tPlayer:IsAlive()) then
          local tTeam = tPlayer:GetTeam();
          if pTeam ~= tTeam then
            pTeam:Meet(tTeam, 1)
	  end
         end
       end
     end
   end
 end
end)

It all goes fine except "pTeam:Meet(tTeam, 1)"
 
pTeam is not an object, but a team id

so you'll need to do Teams[pTeam]:Meet(tTeam, true)
 
Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
  if Game.GetGameTurn() == 1 then
    local pPlayer = Players[iPlayer];
    local pTeam = pPlayer:GetTeam();
    if (pPlayer:IsAlive()) then
      for i = GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS - 2 do 
        local tPlayer = Players[i];
        if (tPlayer:IsAlive()) then
          local tTeam = tPlayer:GetTeam();
          if pTeam ~= tTeam then
            pTeam:Meet(tTeam, 1)
	  end
         end
       end
     end
   end
 end
end)

You have to watch out if you're setting a civ to meet all other city states on the first turn. Remember, there's a gold (and faith) bonus for being the first to meet certain types of city states. As it stands, on average setting, this will also result in the civ starting with about 250 gold and like 10-20 faith (a free pantheon). Actually, I might use part of this code, if you don't mind, but link it to a later tech.
 
Back
Top Bottom