Tomatekh
Emperor
- Joined
- Aug 6, 2012
- Messages
- 1,434
Hi, so I want a building to require the city to be adjacent to a feature (Jungle) in order to be built. In this case, the building is also tied to a civ trait.
I was trying this:
But it's not working. Am I missing something obvious or is my code just completely wrong?
I was trying this:
Spoiler :
Code:
local RAFFIA = GameInfoTypes.BUILDING_MOD_RAFFIA
local JUNGLE = GameInfoTypes.FEATURE_JUNGLE
directions = {DirectionTypes.DIRECTION_NORTHEAST, DirectionTypes.DIRECTION_EAST, DirectionTypes.DIRECTION_SOUTHEAST,
DirectionTypes.DIRECTION_SOUTHWEST, DirectionTypes.DIRECTION_WEST, DirectionTypes.DIRECTION_NORTHWEST}
GameEvents.CityCanConstruct.Add(function(iPlayer, iCity, iBuilding)
local pPlayer = Players[iPlayer];
if (pPlayer:IsAlive()) then
iLeader = pPlayer:GetLeaderType();
condition = "LeaderType = '" .. GameInfo.Leaders[iLeader].Type .. "'";
for row in GameInfo.Leader_Traits(condition) do
iTrait = row.TraitType;
end
if (iBuilding == RAFFIA) then
if iTrait == "TRAIT_RAFFIA_RIVER_MOD" then
local pCityPlot = Players[iPlayer]:GetCityByID(iCity):Plot();
for loop, direction in ipairs(directions) do
local pPlot = Map.PlotDirection(pCityPlot:GetX(), pCityPlot:GetY(), direction);
if pPlot:GetFeatureType() == JUNGLE then
return true
else
return false
end
end
else
return false
end
end
end
return true
end)
But it's not working. Am I missing something obvious or is my code just completely wrong?