| General | Hosted Sites | Civ5 | CivRev | Civ4Col | Civ4 | Civ3 | Civ2 | Civ1 | Misc | Marketplace |
![]() |
|
|
Welcome to Civilization Fanatics' Center. You are currently viewing our site as a guest which gives you limited access to our site features. By joining our free community, you will be able to participate in the discussions, search the forum, send private messages, vote in polls, upload your own screenshots to the gallery, and access many other special features. Registration is fast, simple and absolutely free, so sign up today! If you have any problems with the registration process or your account login, please contact support. |
|
|||||||
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Emperor
Join Date: Aug 2002
Location: Seoul, South Korea
Posts: 1,277
|
[LUA] Working as intended?
In my mod, several civilizations start with no cities.
When playtesting, I found that they were puppeting their newly acquired capital cities and well as others. I have added a courthouse effect to the palace, and so, I don't want the capitals to be puppets. I used the following code to do so: Code:
function UnPuppetTurnStart () for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do local player=Players [iPlayer]; if (player:IsAlive () and not player:IsHuman()) then local pCity = player:GetCapitalCity() for pCity in player:Cities () do if (pCity:IsPuppet ()) then pCity:SetPuppet (false); end end end end end Events.ActivePlayerTurnStart.Add (UnPuppetTurnStart); Could someone who is familiar with lua look at my code and verify if it is acting as I wish? Or have some unintentional results occured?
__________________
Visit my Viking Age scenario at: http://forums.civfanatics.com/showthread.php?t=228787 And my Europe map for European Medieval Mod at: http://forums.civfanatics.com/showthread.php?t=229384 |
|
|
|
|
|
#2 |
|
Moderator
![]() Join Date: Oct 2004
Location: France
Posts: 3,668
|
the "for pCity in player:Cities () do..." is not needed, if you do that, you'll loop all the player cities at each turn.
|
|
|
|
|
|
#3 |
|
Emperor
Join Date: Aug 2002
Location: Seoul, South Korea
Posts: 1,277
|
I got rid of the city loop, but then I run into the problem that pCity becomes a "nil" value, and I get an error. I was not skilled enough to fix it though I tried a number of solutions.
In any case, I've found an alternative solution that works (although it is somewhat clunky): Code:
function UnPuppetYork()
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
local pNorthumbria = Players[iPlayer]
if (GameInfo.Civilizations.CIVILIZATION_RUSSIA.ID == pNorthumbria:GetCivilizationType()) then
if(pNorthumbria:IsAlive() and not pNorthumbria:IsHuman()) then
-- Enumerate cities
for cityIndex = 0, pNorthumbria:GetNumCities() - 1, 1 do
local pCity = pNorthumbria:GetCityByID(cityIndex)
-- City exists and has the proper name?
if pCity ~= nil and pCity:GetName() == "York" then
pCity:SetPuppet (false);
end
end
end
end
end
end
Events.ActivePlayerTurnStart.Add (UnPuppetYork);
(although I would still like to get the previous code working properly, as it would be a more elegant solution).
__________________
Visit my Viking Age scenario at: http://forums.civfanatics.com/showthread.php?t=228787 And my Europe map for European Medieval Mod at: http://forums.civfanatics.com/showthread.php?t=229384 |
|
|
|
|
|
#4 |
|
Moderator
![]() Join Date: Oct 2004
Location: France
Posts: 3,668
|
try:
Code:
function UnPuppetTurnStart () for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do local player=Players [iPlayer]; if (player:IsAlive () and not player:IsHuman()) then local pCity = player:GetCapitalCity() if pCity and pCity:IsPuppet () then pCity:SetPuppet (false); end end end end Events.ActivePlayerTurnStart.Add (UnPuppetTurnStart); |
|
|
|
|
|
#5 |
|
Emperor
Join Date: Aug 2002
Location: Seoul, South Korea
Posts: 1,277
|
Thank-you... that worked perfectly.
__________________
Visit my Viking Age scenario at: http://forums.civfanatics.com/showthread.php?t=228787 And my Europe map for European Medieval Mod at: http://forums.civfanatics.com/showthread.php?t=229384 |
|
|
|
![]() |
| Bookmarks |
|
| Thread Tools | |
|
|