What does this lua do wrong?

Firebug

Not-so Great Engineer
Joined
Sep 25, 2014
Messages
1,271
Location
Clevedon, England
Code:
-- ThebesFunctions
-- Author: DJSHenninger/Firebug
-- DateCreated: 3/22/2015 11:55:52 AM
--------------------------------------------------------------
 
-------------------------------------------------------------------------------------------------
--ThebesTrait
-------------------------------------------------------------------------------------------------
 
function CountNumAlliedCSThebes(playerID)
        local numCS = 0
        local player = Players[playerID]
        for iPlayer = 0, GameDefines.MAX_MINOR_CIVS - 1 do
                local minor = Players[iPlayer]
                if (minor:GetMinorCivFriendshipWithMajor(playerID) >= GameDefines["FRIENDSHIP_THRESHOLD_ALLIES"]) then
                        numCS = numCS + 1
                end
        end
 
        return numCS
end
 
function ThebesTrait(playerID)
        local player = Players[playerID]
        if player:GetCapitalCity() then
                if (player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_THEBES"] and player:IsEverAlive()) then
                        if Teams[player:GetTeam()]:GetAtWarCount(true) == 0 then
		for city in player:Cities() do
			if (city:GetNumBuilding(GameInfoTypes["BUILDING_THEBES_PEACE_CULTURE"]) > 5) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_THEBES_PEACE_CULTURE"], 5);
                                                                end
															end
                        elseif Teams[player:GetTeam()]:GetAtWarCount(true) == 1 then
		for city in player:Cities() do
			if (city:GetNumBuilding(GameInfoTypes["BUILDING_THEBES_WAR_MILITARY"]) > 5) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_THEBES_WAR_MILITARY"], 5);
                                                                end
                                end
                        end
                end
        end
end
GameEvents.PlayerDoTurn.Add(ThebesTrait)
 
-------------------------------------------------------------------------------------------------
--CadmeaCulture
-------------------------------------------------------------------------------------------------
 
function CadmeaExtraCulture(playerID)
        local player = Players[playerID]
        if player:GetCapitalCity() then
                if (player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_THEBES"] and player:IsEverAlive()) then
                                player:GetCapitalCity():SetNumRealBuilding(GameInfoTypes["BUILDING_CADMEA_EXTRA_CULTURE"], CountNumAlliedCSThebes(playerID))
                        end
                end
        end
GameEvents.PlayerDoTurn.Add(CadmeaExtraCulture)

What have i done wrong?

the trait is this

Boeotian League: During War, each city state ally increases Military production by 5% (25% max) in the Capital, During Peace each city state ally increases culture by 5% (25% max) in the Capital. (Can't build Settlers or Annex Cities)

and the Cadmea thing is this
Cadmea (Castle): Only gives +5 combat strength and +20 HP. It yields +1 culture and an additional +1 culture for each city state that is your ally. Must be built in Capital. (Available at Masonry instead)
 
Players[0] will be the human player (in a single-player game)
Players[1] will be the 1st AI Major Civ
Players[2] will be the 2nd AI Major Civ
etc until all Major Civs are accounted for.

You have nothing in your code to distinguish between minor and major players, and nothing to weed out playerID when its number == iPlayer in that scan-loop.

Compare to my code-sample from this thread

Also IsEverAlive() returns "true" if specified player was ever part of the current game. IsAlive() is a better usage.

Your function function ThebesTrait(playerID) is coming across as such a jumble on the forum I haven't been able to completely figure it out, but I will say that if you need to do this
Code:
for city in player:Cities() do
twice and right after each other or as one loop contained within another loop, then you are pretty much by definition doing it wrong.
 
Shouldn't of posted sooner saying JFD fixed this on my civilizations thread.
 
Back
Top Bottom