Selecting certain cities

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
3,019
Location
Operation Padlock ground zero
So I'm trying to add a free dummy building to only the first three cities of a new civ I'm working on. (And actually, this is the last thing that needs to be done for it) But <FreeBuilding> and <Civilization_FreeBuildingClasses> aren't working - <FreeBuilding> gives it to every city, and <Civilization_FreeBuildingClasses> only gives my capital the building, so I guess that means I'll have to resort to lua... :sad:

So the code should be easy enough: use City.SetNumRealBuilding and all that, but I can't find any function that will select only certain cities (besides Player.GetCapitalCity, but that's not really what I'm looking for). Could you maybe use Player.GetNextCity?
Somewhere along the lines of:
"if next city is the third city (which would therefore mean this one is the second), give this city the dummy building"
Would that work?

Except the UI reference doesn't mention the parameters for that function, so... I can only assume it's the city name?

Anyone have any idea how to do this? And thanks in advance! :goodjob:
 
Print the player's (current) 1st, 2nd and 3rd cities (this list will change if any of these are captured)

Code:
> pPlayer = Players[0]
> pCity1 = pPlayer:GetCapitalCity()
> pCity2 = pPlayer:GetNextCity(pCity1)
> pCity3 = pPlayer:GetNextCity(pCity2)
> print(string.format("First: %s, Second: %s, Third: %s", pCity1:GetName(), pCity2:GetName(), pCity3:GetName()))
 WorldView: First: Madrid, Second: Almeria, Third: Vigo
 
Ah. That makes a lot more sense, to find the next city after the capital.
Then this code should work (theoretically)?
Code:
function NewCivFreeDummy(playerID)
	print('Newciv lua loaded.')
	-- For firetuner & lua.log
	local pPlayer = Players[playerID]
	local pBuilding = GameInfoTypes.BUILDING_NEWCIV_DUMMY
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEWCIV) then
		for pCity in pPlayer:Cities() do
			pCity1 = pPlayer:GetCapitalCity()
			pCity2 = pPlayer:GetNextCity(pCity1)
			pCity3 = pPlayer:GetNextCity(pCity2)
			print(string.format("First: %s, Second: %s, Third: %s", pCity1:GetName(), pCity2:GetName(), pCity3:GetName()))
			pCity1:SetNumRealBuilding(pBuilding, 1)
			pCity2:SetNumRealBuilding(pBuilding, 1)
			pCity3:SetNumRealBuilding(pBuilding, 1)
		end
	end
end
GameEvents.DoTurn.Add(NewCivFreeDummy)
 
Okay guys, would really like to know how to do this, as this lua is the only thing standing in the way of finishing my mod. My lua's not working, it's essentially the same as the code above, but just to clarify this is the coding (new civ will be the zapotecs):
Code:
-- Zapotec
-- Author: Me, AW
-- DateCreated: 1/19/2014 5:02:42 PM
--------------------------------------------------------------
function ZapotecDummyBuilding(playerID)
	print('Zapotec dummy building lua loaded.')
	-- For firetuner & lua.log
	local pPlayer = Players[playerID]
	local pBuilding = GameInfoTypes.BUILDING_ZAPOTEC_DUMMY_BONUS
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_ZAPOTEC) then
		for pCity in pPlayer:Cities() do
			pCity1 = pPlayer:GetCapitalCity()
			pCity2 = pPlayer:GetNextCity(pCity1)
			pCity3 = pPlayer:GetNextCity(pCity2)
			print(string.format("First: %s, Second: %s, Third: %s", pCity1:GetName(), pCity2:GetName(), pCity3:GetName()))
			pCity1:SetNumRealBuilding(pBuilding, 1)
			pCity2:SetNumRealBuilding(pBuilding, 1)
			pCity3:SetNumRealBuilding(pBuilding, 1)
		end
	end
end
GameEvents.DoTurn.Add(ZapotecDummyBuilding)
InGameUIAddin and everything, but it's not working. neither of the print statements even show up. :/
 
Okay, so I've changed the hook to GameEvents.PlayerDoTurn.Add, but the lua still isn't working... would it have anything to do with the iterator:
Code:
for pCity in pPlayer:Cities() do
since nowhere in the code is "pCity" ever actually referenced?
 
:( Nope, removing that didn't work either.

You know, I just now realized that I had this error in my lua.log:
Code:
[17369.104] Syntax Error: C:\Users\AW\Documents\My Games\Sid Meier's Civilization 5\MODS\AW's Zapotec Civilization Mod (v 1)\LUA/Zapotec-DummyBuildingAdd.lua:20: '<eof>' expected near 'end'
[17369.104] Runtime Error: Error loading C:\Users\AW\Documents\My Games\Sid Meier's Civilization 5\MODS\AW's Zapotec Civilization Mod (v 1)\LUA/Zapotec-DummyBuildingAdd.lua.
but what the heck is this <eof> it's talking about? :confused:

also, the print statements aren't showing up
 
<eof> is computer geek speak for "end of file", ie it expected the code to stop after an "end" but the file contained more code.
 
so I should add another end? probably after the GameEvents.PlayerDoTurn.Add?

EDIT: Nope, that still gives me a syntax error. I also have one in my other lua too...
 
Okay, so I structured the code a little differently, based on what I saw other modders so in their lua, and put GameEvents.PlayerDoTurn.Add before the function, like so:
Code:
print("Zapotec dummy building lua loaded.")
-- For firetuner & lua.log
GameEvents.PlayerDoTurn.Add(
function(playerID)
	local pPlayer = Players[playerID]
	local pBuilding = GameInfoTypes.BUILDING_ZAPOTEC_DUMMY_BONUS
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_ZAPOTEC) then
			pCity1 = pPlayer:GetCapitalCity()
			pCity2 = pPlayer:GetNextCity(pCity1)
			pCity3 = pPlayer:GetNextCity(pCity2)
			print(string.format("First: %s, Second: %s, Third: %s", pCity1:GetName(), pCity2:GetName(), pCity3:GetName()))
			pCity1:SetNumRealBuilding(pBuilding, 1)
			pCity2:SetNumRealBuilding(pBuilding, 1)
			pCity3:SetNumRealBuilding(pBuilding, 1)
		end
	end
end)
So I'm no longer getting the syntax error about <eof>, but I'm getting a new syntax error about how the parantheses aren't ending correctly, and I'm not understanding how they aren't:
Code:
[21965.814] Syntax Error: C:\Users\AW\Documents\My Games\Sid Meier's Civilization 5\MODS\AW's Zapotec Civilization Mod (v 1)\LUA/Zapotec-DummyBuildingAdd.lua:21: ')' expected (to close '(' at line 5) near 'end'
[21965.814] Runtime Error: Error loading C:\Users\AW\Documents\My Games\Sid Meier's Civilization 5\MODS\AW's Zapotec Civilization Mod (v 1)\LUA/Zapotec-DummyBuildingAdd.lua.
Which doesn't make a lot of sense, since there is an end parenthesis at the end to end the opening parenthesis here:
Code:
GameEvents.PlayerDoTurn.Add[B][COLOR="Red"]([/COLOR][/B]
which I can only assume the log is talking about...

And anyway, the log mentions it being on line 5, but it's actually line 7 (ignoring the first 4 lines of code which all begin with " -- " that modbuddy adds in automatically.

EDIT: Nevermind, it was apparently one too many "end" statements. fixed that by adding "if (pPlayer:IsAlive()) then". All good here! :thumbsup:
 
Back
Top Bottom