General Tso
Panzer General
This code is supposed to provide bonuses to a player one time when they acquire their first city. It works fine for me when I test it using my Gods & Kings version of the game. I have even tried disabling the Gods & Kings part of the code and it still works for me. A user that is using the vanilla version of the game says that it gives then the bonuses every turn. I can't see how that is happening. Does anybody have any idea what could be causing the problem for the vanilla user?
I assume the important parts are the GetHasCityItems and SetHasCityItems functions since they deal with determining if the bonuses have already been given.
I've also attached the original file in case you would rather look at that instead of the scrunched up on screen code box.
I assume the important parts are the GetHasCityItems and SetHasCityItems functions since they deal with determining if the bonuses have already been given.
Code:
-- ModData access -----------------------------------------------------------------------------------------------------
SaveData = Modding.OpenSaveData();
HasCityItems = {};
-- Place city items if necessary (for Gods & Kings users) ---------------------------------------------------------------------------------------
function OnPlayerCityFounded(playerID, cityX, cityY)
PlaceCityItems(playerID, cityX, cityY);
end
GameEvents.PlayerCityFounded.Add(OnPlayerCityFounded);
-- Place city items if necessary (for all users) ------------------------------------------------------------------------------------------------
function OnCityCaptured(playerID, bCapital, cityX, cityY, newPlayerID)
PlaceCityItems(newPlayerID, cityX, cityY);
end
GameEvents.CityCaptureComplete.Add(OnCityCaptured);
-- Place city items if necessary (for users that do not have Gods & Kings) ----------------------------------------------------------------------
function OnPlayerDoCityTurn(playerID)
player = Players[playerID];
city = player:GetCapitalCity();
if city ~= nil then
PlaceCityItems(playerID, city:GetX(), city:GetY());
end
end
GameEvents.PlayerDoTurn.Add(OnPlayerDoCityTurn);
-- Internal Functions ----------------------------------------------------------------------------------------------------------------
function GetHasCityItems(playerID)
local name = "GTAS_HasCityItems:" .. tostring(playerID);
if HasCityItems[name] == nil then
HasCityItems[name] = SaveData.GetValue(name);
end
return HasCityItems[name];
end
function SetHasCityItems(playerID, hasItems)
local name = "GTAS_HasCityItems:" .. tostring(playerID);
if HasCityItems[name] ~= hasItems then
HasCityItems[name] = hasItems;
SaveData.SetValue(name, hasItems);
end
end
-- If player hasn't been given city items yet in this game then give them and update status.
function PlaceCityItems(playerID, cityX, cityY)
local player = Players[playerID];
if not player:IsMinorCiv() then
if GetHasCityItems(playerID) ~= 1 then
local slot = SlotData:GetSlot(playerID);
if slot ~= nil then
player:SetGold(player:GetGold() + slot.startGold);
player:SetJONSCulture(player:GetJONSCulture() + slot.startCulture);
player:SetNumFreeTechs(player:GetNumFreeTechs() + slot.freeTechs);
player:SetFaith(player:GetFaith() + slot.startFaith);
end
SetHasCityItems(playerID, 1);
end
end
end
I've also attached the original file in case you would rather look at that instead of the scrunched up on screen code box.