1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

[Lua] Having trouble with code making buildings exclusive from one another.

Discussion in 'CivBE - Modding Help & Mod Creation' started by Galgus, Oct 11, 2017.

  1. Galgus

    Galgus Chieftain

    Joined:
    Aug 22, 2012
    Messages:
    1,670
    Edit: The issue was a conflict with a mod I did not think would be problematic.
    ______________________________

    I've been using code that Valessa generously put together in this thread which worked at a time if memory serves, but seems to be conflicting with something now.

    That or I messed something up, which could be quite likely.

    I haven't seen any kind of error about the changes in logs, so I don't know what to look at to troubleshoot.

    If you have any ideas on what the problem may be, I'd be grateful to hear them.

    Is it problematic that there are two SQL files updating the database?
    _______________

    This is is the ModInfo folder.

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <Mod id="6ea9bfd1-9019-4708-8302-6f77a98afec0" version="1">
      <Properties>
        <Name>Distinction - Affinity Buildings Overhaul</Name>
        <Stability>Alpha</Stability>
        <Teaser>Overhauls the Afffinity building system to assign each Core and Hybrid Affinity a set of buildings that are exclusive to those</Teaser>
        <Description>Overhauls the Afffinity building system to assign each Core and Hybrid Affinity a set of buildings that are exclusive to those of other affinities, requiring only affinity level to unlock.</Description>
        <Authors>Galgus</Authors>
        <SpecialThanks>Ryika, lilgamefreek</SpecialThanks>
        <HideSetupGame>0</HideSetupGame>
        <AffectsSavedGames>1</AffectsSavedGames>
        <MinCompatibleSaveVersion>0</MinCompatibleSaveVersion>
        <SupportsSinglePlayer>1</SupportsSinglePlayer>
        <SupportsMultiplayer>1</SupportsMultiplayer>
        <SupportsHotSeat>1</SupportsHotSeat>
        <SupportsMac>1</SupportsMac>
        <ReloadLandmarkSystem>0</ReloadLandmarkSystem>
        <ReloadStrategicViewSystem>0</ReloadStrategicViewSystem>
        <ReloadUnitSystem>0</ReloadUnitSystem>
      </Properties>
      <Dependencies />
      <References />
      <Blocks />
      <Files>
        <File md5="1E6478DB43B39D62D2FA7E08B1785920" import="0">Affinity Buildings/Harmony Build.xml</File>
        <File md5="62D49A915DEDFC15622E04FDD325573B" import="0">Affinity Buildings/HP Build.xml</File>
        <File md5="4F4FAD1FDF2721952E0675FBC4CF0292" import="0">Affinity Buildings/PS Build.xml</File>
        <File md5="ECB4C1AFB9707B5E680E64BA4A13F09C" import="0">Affinity Buildings/Purity Build.xml</File>
        <File md5="9D9BB0FAF9F9BD0E9DAFF847A3C1B884" import="0">Affinity Buildings/SH Build.xml</File>
        <File md5="EF1456E405098D5010661F69C3F49F12" import="0">Affinity Buildings/Supremacy Build.xml</File>
        <File md5="BD7071AE8107AC4430D056AC772F3BE0" import="0">Exclusivity Code/Lua/AffinityAffiliationTestScript.lua</File>
        <File md5="15F9FFE5CF3091839BC57020AFE96B30" import="0">Exclusivity Code/SQL/UpdateBuildingTable.sql</File>
        <File md5="A2D220B934880F68F5C6D7129CF80309" import="0">Modular Building Quests Resource/BuildingChoiceTemplateQuest.lua</File>
        <File md5="456CA3F098A6E5FACC45B594997402B3" import="0">Modular Building Quests Resource/BuildingQuestTable.sql</File>
      </Files>
      <Actions>
        <OnModActivated>
          <UpdateDatabase>Modular Building Quests Resource/BuildingQuestTable.sql</UpdateDatabase>
          <UpdateDatabase>Exclusivity Code/SQL/UpdateBuildingTable.sql</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/Harmony Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/HP Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/PS Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/Purity Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/SH Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/Supremacy Build.xml</UpdateDatabase>
        </OnModActivated>
      </Actions>
      <EntryPoints>
        <EntryPoint type="InGameUIAddin" file="Exclusivity Code/Lua/AffinityAffiliationTestScript.lua">
          <Name>Exclusivity Code/Lua/AffinityAffiliationTestScript</Name>
          <Description>
          </Description>
        </EntryPoint>
        <EntryPoint type="Quest" file="Modular Building Quests Resource/BuildingChoiceTemplateQuest.lua">
          <Name>Modular Building Quests resource/BuildingChoiceTemplateQuest</Name>
          <Description>
          </Description>
        </EntryPoint>
      </EntryPoints>
    </Mod>
    ______

    This is the UpdateBuildingTable.sql file creating a new table for buildings.

    Code:
    ALTER TABLE Buildings ADD AffinityAffiliation text; 
    ____

    This is the file that checks said tables.

    Code:
    GameEvents.CityCanConstruct.Add(function(iPlayer, iCity, iBuildingType)
    
        -- Need to convert iCity to a usable format
        local pCity = Players[iPlayer]:GetCityByID(iCity)
    
        -- If the Building has an Entry to the AffinityAffiliation Table then...
        if GameInfo.Buildings[iBuildingType].AffinityAffiliation ~= nil then
            -- ...go through ALL buildings that exist...
            for pBuilding in GameInfo.Buildings() do
                -- ...and check if it exists in the city.
                if pCity:IsHasBuilding(pBuilding.ID) then
                    -- If it exists, then check if it has an AffinityAffiliation entry.
                    if GameInfo.Buildings[pBuilding.ID].AffinityAffiliation ~= nil then
                        -- If it has one, then check if it's different from the building that is being checked!
                        if GameInfo.Buildings[iBuildingType].AffinityAffiliation ~= GameInfo.Buildings[pBuilding.ID].AffinityAffiliation then
                            -- If it is different finally return false!
                            return false
                        end
                    end
                end
            end
        end
      
        -- Return true if the code above has not returned false (aka if
        -- the building has no AffinityAffiliation-entry or no building
        -- of a different group exists).
        return true
    end)
    ________

    And this is an example of the relevant sections of the affinity "Build" XML files assigning buildings the SQL's categories.

    Code:
    <Buildings>
    
            <Update>
                <Where Type="BUILDING_XENOFUEL_PLANT"/>
                <Set AffinityAffiliation="AFFINITY_HARMONY"/>
            </Update>
    
           <Update>
                <Where Type="BUILDING_GENE_GARDEN"/>
                <Set AffinityAffiliation="AFFINITY_PURITY_HARMONY"/>
            </Update>
    
    </Buildings>
    ______

    This is a link to the problematic mod, if that makes this easier.

    It is supposed to make the buildings with affinity symbols in front of them exclusive to one another with one vanishing when a conflicting one is built.

    They have no tech requirement, so setting two affinities to level 4 to unlock the first building of three sets of affinities is a quick way to test it.
     
    Last edited: Oct 12, 2017
  2. Galgus

    Galgus Chieftain

    Joined:
    Aug 22, 2012
    Messages:
    1,670
    The issue was a conflict with a mod I did not think would be problematic.
     

Share This Page