I have been stuck trying to make this work for me. What I want to do is for every kill a civ makes, I want to add 1 food to each of the civ's current cities. Here is my code so far:
What is happening now is that each time any civ makes a kill, it gets the food bonus. I think the problem lies with this code:
I think it keeps returning the human player's civ. I want the player whose turn is active. Please help. Thanks.
Code:
function IfUnitIsDestroyed(playerID, unitID)
--Need to add a condition that checks if the destroyed unit isn't the active player's settler
local currentPlayer = Players[Game.GetActivePlayer()];
local currentCiv = currentPlayer:GetCivilizationType();
local civinfo = GameInfo.Civilizations[currentCiv];
print("Civ: ", civinfo.Type);
if civinfo.Type == GameInfo.Civilizations["CIVILIZATION_STRAWHAT"].Type then
print("The Fierce Strawhats!")
if playerID ~= GameInfo.currentPlayer then
print("Adding Food to Strawhat's cities")
for pCity in Players[aCiv]:Cities() do
local iCurrentFood = pCity:GetFood();
pCity:SetFood(iCurrentFood + 1);
end
end
end
end
Events.SerialEventUnitDestroyed.Add( IfUnitIsDestroyed );
What is happening now is that each time any civ makes a kill, it gets the food bonus. I think the problem lies with this code:
Code:
local currentPlayer = Players[Game.GetActivePlayer()];
local currentCiv = currentPlayer:GetCivilizationType();
local civinfo = GameInfo.Civilizations[currentCiv];