Making a Building Require a Feature (Help with my Code)

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:

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?
 
Does GameInfoTypes.BUILDING_MOD_RAFFIA work? I usually do it the long way:

GameInfo.Buildings["BUILDING_MOD_RAFFIA"].ID or something like that...I have to see how I do it at home.
 
Does GameInfoTypes.BUILDING_MOD_RAFFIA work? I usually do it the long way:

GameInfo.Buildings["BUILDING_MOD_RAFFIA"].ID or something like that...I have to see how I do it at home.

That wasn't the problem. It was something with my loop as it worked fine once I defined/checked each plot individually.
 
Your loop is only testing the first (NE) plot

Code:
            if pPlot:GetFeatureType() == JUNGLE then
              return true
            [COLOR="Red"]else
              return false[/COLOR]
            end

due to the bit in red

Delete the "else" and move the "return false" after the end that closes the for
 
Back
Top Bottom