Lua trait issues

Discussion in 'Civ5 - Creation & Customization' started by :thinking emoji:, Apr 11, 2018.

  1. :thinking emoji:

    :thinking emoji: Chieftain

    Joined:
    Apr 4, 2018
    Messages:
    4
    Gender:
    Male
    I've been trying to give my custom civilization (the Selk'nam) a simple trait: Aesthetics is available from the Ancient era. To do this, I edited the trait from HoopThrower's Chile-Allende civilization (which makes all policy branches available from the ancient era) to just make Aesthetics available. However, despite fixing all the syntax errors, adding the file as a UIGameAddin and checking both the database.log and the lua.log, I can't seem to make it have any effect. Am I missing something, or is there something I need to fix?

    Here's the code:

    Code:
    include("Strict.lua")
    local iSelknamCiv = GameInfoTypes.CIVILIZATION_SELKNAM
    local tPolicyBranchEraConditions = {
        [GameInfoTypes.POLICY_BRANCH_AESTHETICS] = { DefaultRequirement=GameInfoTypes.ERA_CLASSICAL, SelknamRequirement=GameInfoTypes.ERA_ANCIENT }
    }
    function SelknamPolicyBranchAffects(iPlayer, iPolicyBranch)
        if tPolicyBranchEraConditions[iPolicyBranch] then
            --print("SelknamPolicyBranchAffects fired for values iPlayer " .. iPlayer .. ", iPolicyBranch " .. iPolicyBranch)
            local pPlayer = Players[iPlayer]
            local iCurrentEra = pPlayer:GetCurrentEra()
            if pPlayer:GetCivilizationType() == iSelknamCiv then
                return (iCurrentEra >= tPolicyBranchEraConditions[iPolicyBranch]["SelknamRequirement"])
            else
               
                return (iCurrentEra >= tPolicyBranchEraConditions[iPolicyBranch]["DefaultRequirement"])
            end
        end
        return true
    end
    GameEvents.PlayerCanAdoptPolicyBranch.Add(SelknamPolicyBranchAffects)
    print(" lua loaded to the end")
    Build [/BUILD]

    Any help would be much appreciated.
     
  2. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    If you haven't altered the game rules in the database to allow selection of the policy branch during the ancient era, nothing you do in lua will have any effect.

    This is what makes the lua code have an effect in the Allende mod:
    Code:
    	<PolicyBranchTypes>
    		<Update>
    			<Where PurchaseByLevel="false" />
    			<Set EraPrereq="NULL"/>
    		</Update>
    	</PolicyBranchTypes>
    It sets all policy branches that are not ideology branches to not have any era requirement in the database. Only then can the lua code have any effect.

    And if you have the Allende mod running at the same time as your mod, the two will conflict with one another and your lua will likely have no effect because the Allende mod will tell the game "false" for your civ, which will override your code telling the game "true". Ie, one answer of "false" from any lua file in any mod will have the effect of over-riding 90000000000000 answers of "true". Your mod will also interfere with the Allende mod for the Aesthetics policy branch.
     
  3. :thinking emoji:

    :thinking emoji: Chieftain

    Joined:
    Apr 4, 2018
    Messages:
    4
    Gender:
    Male
    Thanks, but how would you set only Aesthetics to not have an era requirement in the database?
     
  4. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    By updating
    Code:
    <Where Type="POLICY_BRANCH_AESTHETICS"/>
    instead of
    Code:
    <Where PurchaseByLevel="false" />
    as shown in the code upthread.
     
    Last edited: Apr 12, 2018
  5. :thinking emoji:

    :thinking emoji: Chieftain

    Joined:
    Apr 4, 2018
    Messages:
    4
    Gender:
    Male
  6. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA

Share This Page