Starrynite120
Prince
- Joined
- Jul 15, 2015
- Messages
- 472
I have several scripts I'm running that I thought should be working for every city, but is only applying to the capital. For example, this script is supposed to give food in every city equal to half the number of policies you own, but instead it's applying to only the capital, and to the capital multiple times, equal to the number of cities you have. I'm assuming its a problem with how I'm acquiring the cityID, but I'm not sure what the problem is.
Edit: Of course, just figured it out. It should be for City, not for cityID.
Code:
function FoodPerVirtue(playerID, cityID)
local player = Players[playerID];
local perk = GameInfo.PlayerPerks["PLAYERPERK_AFFINITY_BETTER_TERRASCAPES"].ID;
local City = player:GetCityByID(cityID)
if(player:HasPerk(perk)) then
local bonus = (player:GetNumPolicies() / 2);
if(bonus > 0) then
for cityID in player:Cities() do
City:ChangeFood(bonus);
-- Send a notification to the player
local text = Locale.ConvertTextKey("TXT_KEY_STARRYNITE_PURITY_8_NOTIFICATION", tostring(bonus));
player:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, text, text);
end
end
end
end
GameEvents.PlayerDoTurn.Add(FoodPerVirtue);
Edit: Of course, just figured it out. It should be for City, not for cityID.