ArbogLi
Chieftain
- Joined
- Apr 25, 2010
- Messages
- 64
Hi everybody, I have a little problem and I need help to solve it because I really tryed but I missed.
I'm working on my random events mod and looking for bugs I found one: when a city expand the territory getting a free tile this is assigned to the player, nor to the city, and it doesn't change when the city is conquered.
The code is the next:
This is the original code, but looking for the bug I found what I said: plot:SetOwner(City:GetOwner()); The I tried to fix it giving the plot ownership to the city instead of the player and it works, replacing this line by:
The problem is that the ID is always the same (in this case the human player first city's ID), but it should be the ID of the other player cities. It tryed to find if the choosen city was wrong but asking for the name instead of the ID it is ok, gives me the correct city name but the ID don't change.
Any ideas? I don't know what the hell I must do to change the ID (and belive me, I tryed
)
I'm working on my random events mod and looking for bugs I found one: when a city expand the territory getting a free tile this is assigned to the player, nor to the city, and it doesn't change when the city is conquered.
The code is the next:
Code:
function addPlot(pCurrentPlayer)
--player should be alive and own cities
if (pCurrentPlayer ~= nil and pCurrentPlayer:IsAlive() and pCurrentPlayer:GetNumCities() > 0) then
local CityNum = Map.Rand(pCurrentPlayer:GetNumCities(), "Random city - Lua");
local City = GetCityByNum(pCurrentPlayer, CityNum);
local plot = City:GetNextBuyablePlot();
plot:SetOwner(City:GetOwner());
if (pCurrentPlayer:IsHuman() == true) then
LuaEvents.CustomNotification(City:GetX(), City:GetY(), "Citizens from " .. City:GetName() .. " have been wonking a tile near to their city and they claimed it for their empire", "Expansion");
end
end
end -- addPlot
function GetCityByNum(player, N)
local n = 0;
for city in player:Cities() do
if (n == N) then
return city;
end
n = n + 1;
end
end
This is the original code, but looking for the bug I found what I said: plot:SetOwner(City:GetOwner()); The I tried to fix it giving the plot ownership to the city instead of the player and it works, replacing this line by:
Code:
plot:SetOwner(City:GetID());
The problem is that the ID is always the same (in this case the human player first city's ID), but it should be the ID of the other player cities. It tryed to find if the choosen city was wrong but asking for the name instead of the ID it is ok, gives me the correct city name but the ID don't change.
Any ideas? I don't know what the hell I must do to change the ID (and belive me, I tryed
