LeeS
Imperator
See up-page @ #352. The CityCanConstruct lua is irrelevant because it will only fire if something is possible by the settings of all code within the SQL database. Two mutually-exclusive buildings are also mutually exclusive to themselves and once one copy of any of these mutually-exclusive buildings is present within a city, no more may be constructed within that same city regardless of the Building-Class "NoLimit" settings.
--------------------------------------------------------------
You would have to remove the <MutuallyExclusiveGroup> settings from the definitions of the buildings in order for the lua script to be used, but you still won't be able to construct multiple copies of the same building within the same city. Placing them there directly by lua is another animal entirely.
---------------------------------------------------------------
As far as the lua itself goes, you missed an ending ")" here:
Or you chopped it off when you copy/pastad to the forum.
I would probably have written the code a little differently in order to make it easier to follow what I am trying to do, as in:
Or I would have set-up a table of correspondances if everything is direct 1-to-1 relationships between two types of buildings and thrown these correspondances into an lua-table:
I color-coded to show which part of the code is pulling data from which side of the 'Key,Value' pairs from the table I called tMutuallyExclusiveBuildings. With the code constructed in such a way you can place 1 or 10000 pairs of such corresondances within the lua-table, and the rest of the code does not need to change.
--------------------------------------------------------------
You would have to remove the <MutuallyExclusiveGroup> settings from the definitions of the buildings in order for the lua script to be used, but you still won't be able to construct multiple copies of the same building within the same city. Placing them there directly by lua is another animal entirely.
---------------------------------------------------------------
As far as the lua itself goes, you missed an ending ")" here:
Code:
GameEvents.CityCanConstruct.Add(
function(iPlayer, iCity, iBuilding)
local pPlayer = Players[iPlayer]
local pCity = pPlayer:GetCityByID(iCity)
if ((iBuilding == 1) or (iBuilding = 2)) then
-- obviously we would change those values :P
if ((iBuilding == 1) and (pCity:IsHasBuilding(2))
or ((iBuilding == 2) and (pCity:IsHasBuilding(1))
then return false end
end
return true
end[color="red"])[/color]
I would probably have written the code a little differently in order to make it easier to follow what I am trying to do, as in:
Code:
GameEvents.CityCanConstruct.Add(
function(iPlayer, iCity, iBuilding)
local pPlayer = Players[iPlayer]
local pCity = pPlayer:GetCityByID(iCity)
if (iBuilding == 1) then
return (not pCity:IsHasBuilding(2))
elseif (iBuilding = 2)) then
return (not pCity:IsHasBuilding(1))
end
return true
end)
Code:
local [COLOR="green"]tMutuallyExclusiveBuildings[/COLOR] = { [COLOR="Red"][1][/COLOR] = [COLOR="Blue"]2[/COLOR], [COLOR="red"][2][/COLOR] = [COLOR="blue"]1[/COLOR] }
GameEvents.CityCanConstruct.Add(
function(iPlayer, iCity, iBuilding)
if [COLOR="red"]tMutuallyExclusiveBuildings[iBuilding][/COLOR] then
local pPlayer = Players[iPlayer]
local pCity = pPlayer:GetCityByID(iCity)
return (not pCity:IsHasBuilding([COLOR="blue"]tMutuallyExclusiveBuildings[iBuilding][/COLOR]))
end
return true
end)