Karatekid5
Warlord
I am currently working on finishing the Lua portion of my newest custom civilization's unique ability, and I've run into a bit of an issue. The code is intended to grant an amount of copies of a dummy building based on the player's Declaration of Friendship count, and then swap out those buildings for the same amount of a different dummy building while at war. I was able to use some code from Calcul8or's Connecticut mod as a base, and modify it to fit the parameters of the Unique Ability I chose. It works for the most part, showing no errors in the LUA log and granting the player the correct dummy building count for peacetime. However, the check I added for the player's war status isn't working, even though I set it all up in a similar fashion to the check in the Pleco unit's ability. Here is the current code:
And for a side question, is it possible to use Lua to assign an icon to a specific UniqueName of a unit? For example, this civ's unique unit is the Great Hero (Great General replacement), and for flavor it'd be cool to have Lua that checks the UniqueName of the unit and sets an icon from an atlas that matches the character name chosen instead of the default. I know it likely isn't possible but I just wanted to know if it's worth looking into.
Thanks in advance!
Code:
print("PLUS ULTRA!!!!!");
local civID = GameInfoTypes["CIVILIZATION_UA_HIGH"]
local bldgID = GameInfoTypes["BUILDING_NEZU_CULTURE"];
local bldgID2 = GameInfoTypes["BUILDING_NEZU_GREAT_PEOPLE"];
function NezuCheck(player)
for playerID, player in pairs(Players) do
local player = Players[playerID];
if player:GetCivilizationType() == civID then
GameEvents.PlayerDoTurn.Add(NezuFriendshipRoutine)
end
end
end
Events.SequenceGameInitComplete.Add(NezuCheck)
function NezuFriendshipRoutine(playerID)
local pPlayer = Players[playerID]
local pPlayerTeam = Teams[pPlayer:GetTeam()]
if (pPlayer:IsAlive() and pPlayer:GetCivilizationType() == civID) then
local DOF = DOFcount(playerID)
print("Final DOF count = " .. DOF);
if (pPlayerTeam:IsAtWar()) then
for city in pPlayer:Cities() do
city:SetNumRealBuilding(bldgID2, DOF)
city:SetNumRealBuilding(bldgID, 0)
end
else
for city in pPlayer:Cities() do
city:SetNumRealBuilding(bldgID, DOF)
city:SetNumRealBuilding(bldgID2, 0)
end
end
end
end
function DOFcount(iPlayer)
local player = Players[iPlayer]
local iCounter = 0
for i = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
local pOtherPlayer = Players[i]
--print("Checking for DoF with " .. pOtherPlayer:GetName());
if (pOtherPlayer:IsAlive()) then
if (i ~= iPlayer and player:IsDoF(i)) then
iCounter = iCounter + 1
end
end
end
return iCounter
end
And for a side question, is it possible to use Lua to assign an icon to a specific UniqueName of a unit? For example, this civ's unique unit is the Great Hero (Great General replacement), and for flavor it'd be cool to have Lua that checks the UniqueName of the unit and sets an icon from an atlas that matches the character name chosen instead of the default. I know it likely isn't possible but I just wanted to know if it's worth looking into.
Thanks in advance!