1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[BNW] 2 Questions about great generals for custom mod

Discussion in 'Civ5 - SDK / LUA' started by De Bliksem, Mar 26, 2019.

  1. De Bliksem

    De Bliksem Chieftain

    Joined:
    Oct 5, 2018
    Messages:
    8
    Hi all!

    2 questions for my first custom civilization .My civilization cant build settlers, but uses generals to settle. These generals also grant a bonus when stationed in a city.

    1. Is there a way to passively generate great generals? Currently generals can only be obtained through policies, a free one at a certain tech (as optics with venice) and through battle. Besides speeding up the generation of generals through battle, are there other methods of generating generals, like specialists for example?

    2. Right now, ive got a piece of code in lua that makes it so that when a general is stationed in a city, the city enables a dummy building which gives it happiness. However, I want the bonus the city gets to be a variety of choices, not just happiness. I want to link the building the city gets to the focus the city is on, so for example give it 15% growth on food focus, 15% production when on production focus, etc. Is it possible to link the focus of the city to what specific dummy building spawns?

    Other relevant suggestions are also very much appreciated
     
  2. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,365
    Location:
    Near Portsmouth, UK
    2 - yes. Look in the CityView.lua file and find the method that enables the button next to the focus the city is on, and use that in a condition to spawn the relevant free building

    PS - The AI will not be able to understand the inability to build settlers, so you'll probably want to set your civ not to be selectable as an AI civ
     
  3. De Bliksem

    De Bliksem Chieftain

    Joined:
    Oct 5, 2018
    Messages:
    8
    So i tried to make some code based on cityview and what I had before, but it doesn't work.
    Spoiler :

    include("PlotIterators")

    for pAreaPlot in PlotAreaSweepIterator(pPlot, r) do
    print(pEdgePlot:GetX(), pEdgePlot:GetY())
    end

    local unitPromotionChiefID = GameInfoTypes["PROMOTION_CHIEF"]
    local buildingChiefDummyID = GameInfoTypes["BUILDING_CHIEF_DUMMY"]
    local buildingChiefDummyIDf = GameInfoTypes["BUILDING_CHIEF_DUMMY_F"]
    local buildingChiefDummyIDp = GameInfoTypes["BUILDING_CHIEF_DUMMY_P"]
    local buildingChiefDummyIDs = GameInfoTypes["BUILDING_CHIEF_DUMMY_S"]
    local buildingChiefDummyIDg = GameInfoTypes["BUILDING_CHIEF_DUMMY_G"]
    local buildingChiefDummyIDc = GameInfoTypes["BUILDING_CHIEF_DUMMY_C"]
    local buildingChiefDummyIDfa = GameInfoTypes["BUILDING_CHIEF_DUMMY_FA"]
    local buildingChiefDummyIDt = GameInfoTypes["BUILDING_CHIEF_DUMMY_T"]
    local focusType = pCity:GetFocusType();

    function Chief_Garrison(playerID)
    local player = Players[playerID]
    if player:IsAlive() then
    for city in player:Cities() do
    local ChiefIsHere = false
    local plot = city:plot()
    for i = 0, plot:GetNumUnits() - 1, 1 do
    if plot then
    if plot:GetUnit(i):IsHasPromotion(unitPromotionChiefID) then
    ChiefIsHere = true
    end
    end
    end

    if ChiefIsHere then

    if focusType == CityAIFocusTypes.NO_CITY_AI_FOCUS_TYPE then

    if (not city:IsHasBuilding(buildingChiefDummyID)) then
    city:SetNumRealBuilding(buildingChiefDummyID, 1)
    end

    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FOOD then

    if (not city:IsHasBuilding(buildingChiefDummyIDf)) then
    city:SetNumRealBuilding(buildingChiefDummyIDf, 1)
    end

    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_PRODUCTION then

    if (not city:IsHasBuilding(buildingChiefDummyIDp)) then
    city:SetNumRealBuilding(buildingChiefDummyIDp, 1)
    end

    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GOLD then

    if (not city:IsHasBuilding(buildingChiefDummyIDg)) then
    city:SetNumRealBuilding(buildingChiefDummyIDg, 1)
    end

    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_SCIENCE then

    if (not city:IsHasBuilding(buildingChiefDummyIDs)) then
    city:SetNumRealBuilding(buildingChiefDummyIDs, 1)
    end

    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_CULTURE then

    if (not city:IsHasBuilding(buildingChiefDummyIDc)) then
    city:SetNumRealBuilding(buildingChiefDummyIDc, 1)
    end

    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FAITH then

    if (not city:IsHasBuilding(buildingChiefDummyIDfa)) then
    city:SetNumRealBuilding(buildingChiefDummyIDfa, 1)
    end

    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GREAT_PEOPLE then

    if (not city:IsHasBuilding(buildingChiefDummyIDt)) then
    city:SetNumRealBuilding(buildingChiefDummyIDt, 1)
    end
    else
    if city:IsHasBuilding(buildingChiefDummyID) then
    city:SetNumRealBuilding(buildingChiefDummyID, 0)
    end
    if city:IsHasBuilding(buildingChiefDummyIDf) then
    city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
    end
    if city:IsHasBuilding(buildingChiefDummyIDp) then
    city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
    end
    if city:IsHasBuilding(buildingChiefDummyIDg) then
    city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
    end
    if city:IsHasBuilding(buildingChiefDummyIDs) then
    city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
    end
    if city:IsHasBuilding(buildingChiefDummyIDc) then
    city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
    end
    if city:IsHasBuilding(buildingChiefDummyIDfa) then
    city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)
    end
    if city:IsHasBuilding(buildingChiefDummyIDt) then
    city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    end
    end
    end
    end
    end
    GameEvents.UnitSetXY.Add(Chief_Garrison)
    GameEvents.PlayerDoTurn.Add(Chief_Garrison)


    I'm not good at LUA or coding for that matter :)
     
  4. ThanOscar

    ThanOscar Chieftain

    Joined:
    Feb 13, 2019
    Messages:
    41
    1- Community Patch has a YIELD_GREAT_GENERAL pointst that could be used i believe, but it also ships with a lot of fixes and tweaks that may or may not be wanted.

    2- I can't quite understand the lua code as it appears theres no whitespace; have you clicked on the insert code button when posting? Additionally, Correct me if im wrong but i would declare focustype inside the function, as it has to look at the city object. Enable logging as well and check your lua log to troubleshoot
     
  5. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,517
    Location:
    Illinois, USA
    You don't have enough end commands.

    Adding Chief_Garrison to GameEvents.UnitSetXY is going to make the function execute every time any unit belonging to any player makes any move whatsoever, incluing additions of new units to the game. The sum total of this will be observable if not unacceptable lagginess, especially as the game progresses and more units are added into the game.

    An "else" clause only executes if every other "if" and "elseif" clause within a conditional chunk fails to be evaluated as being a "true" condition. So when a city focus changes from one type of focus to another, the code will never cancel out any other dummy building which might have been added to a city.

    You don't need to do as this
    Code:
    if city:IsHasBuilding(buildingChiefDummyID) then
    	city:SetNumRealBuilding(buildingChiefDummyID, 0)
    end
    You can just directly do as
    Code:
    city:SetNumRealBuilding(buildingChiefDummyID, 0)
    When adding a dummy building to a city, it all depends on what the effects of the dummy building are as to whether you can skip the more complex method of this
    Code:
    if (not city:IsHasBuilding(buildingChiefDummyID)) then
    	city:SetNumRealBuilding(buildingChiefDummyID, 1)
    end
    And just directly do as
    Code:
    city:SetNumRealBuilding(buildingChiefDummyID, 1)
    Dummy Buildings that would add free units, free policies, free techs, etc., would need the more complex code.

    And as mentioned already, you would need to code as
    Code:
    function Chief_Garrison(playerID)
    	local player = Players[playerID]
    	if player:IsAlive() then
    		for city in player:Cities() do
    			local focusType = city:GetFocusType();
    			local ChiefIsHere = false
    			local plot = city:Plot()
    			....etc.....
    In this chunk of your code
    Code:
    if plot then
    	if plot:GetUnit(i):IsHasPromotion(unitPromotionChiefID) then
    		ChiefIsHere = true
    	end
    end
    All you need is this
    Code:
    if plot:GetUnit(i):IsHasPromotion(unitPromotionChiefID) then
    	ChiefIsHere = true
    end
    This line and it's associated "end" are not needed
    Code:
    if plot then
    You canno get to that line if "plot" is a nil value, which is what you are checking against. A city cannot exist without being on a valid plot, and since you've acquired the "plot" value from grabbing the data for the plot the city is on, there's really no need to check for the validity of the plot. Besides which, your code has already executed methods on the "plot" variable previous to the line where you are checking whether the plot is valid.
     
  6. De Bliksem

    De Bliksem Chieftain

    Joined:
    Oct 5, 2018
    Messages:
    8
    Thanks for your replies!
    I think I went through everything, but it still doesn't work in game.

    I now got this in the lua file:

    Spoiler :

    Code:
    include("PlotIterators")
    
    for pAreaPlot in PlotAreaSweepIterator(pPlot, r) do
      print(pEdgePlot:GetX(), pEdgePlot:GetY())
    end
    
    local unitPromotionChiefID = GameInfoTypes["PROMOTION_CHIEF"]
    local buildingChiefDummyID = GameInfoTypes["BUILDING_CHIEF_DUMMY"]
    local buildingChiefDummyIDf = GameInfoTypes["BUILDING_CHIEF_DUMMY_F"]
    local buildingChiefDummyIDp = GameInfoTypes["BUILDING_CHIEF_DUMMY_P"]
    local buildingChiefDummyIDs = GameInfoTypes["BUILDING_CHIEF_DUMMY_S"]
    local buildingChiefDummyIDg = GameInfoTypes["BUILDING_CHIEF_DUMMY_G"]
    local buildingChiefDummyIDc = GameInfoTypes["BUILDING_CHIEF_DUMMY_C"]
    local buildingChiefDummyIDfa = GameInfoTypes["BUILDING_CHIEF_DUMMY_FA"]
    local buildingChiefDummyIDt = GameInfoTypes["BUILDING_CHIEF_DUMMY_T"]
    local focusType = pCity:GetFocusType();
    
    function Chief_Garrison(playerID)
        local player = Players[playerID]
        if player:IsAlive() then
            for city in player:Cities() do
                local focusType = city:GetFocusType();
                local ChiefIsHere = false
                local plot = city:Plot()
    
                for i = 0, plot:GetNumUnits() - 1, 1 do
                    if plot:GetUnit(i):IsHasPromotion(unitPromotionChiefID) then
                        ChiefIsHere = true
                    end
                end
                       
                if ChiefIsHere then
    
                    if focusType == CityAIFocusTypes.NO_CITY_AI_FOCUS_TYPE then
    
                            city:SetNumRealBuilding(buildingChiefDummyID, 1)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FOOD then
    
                            city:SetNumRealBuilding(buildingChiefDummyIDf, 1)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_PRODUCTION then
    
                            city:SetNumRealBuilding(buildingChiefDummyIDp, 1)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GOLD then
    
                            city:SetNumRealBuilding(buildingChiefDummyIDg, 1)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_SCIENCE then
    
                            city:SetNumRealBuilding(buildingChiefDummyIDs, 1)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_CULTURE then
       
                            city:SetNumRealBuilding(buildingChiefDummyIDc, 1)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FAITH then
    
                            city:SetNumRealBuilding(buildingChiefDummyIDfa, 1)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GREAT_PEOPLE then
    
                            city:SetNumRealBuilding(buildingChiefDummyIDt, 1)
                else
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)      
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
                end
            end
        end
    end
    end
    GameEvents.UnitSetXY.Add(Chief_Garrison)
    GameEvents.PlayerDoTurn.Add(Chief_Garrison)


    And this in the dummybuildings.xml, pretty straightforward i think:

    Spoiler :

    Code:
    <GameData>
        <BuildingClasses>
            <Row>
                <Type>BUILDINGCLASS_CHIEF_DUMMY</Type>
                <DefaultBuilding>BUILDING_CHIEF_DUMMY</DefaultBuilding>
            </Row>
            <Row>
                <Type>BUILDINGCLASS_CHIEF_DUMMY_F</Type>
                <DefaultBuilding>BUILDING_CHIEF_DUMMY_F</DefaultBuilding>
            </Row>
            <Row>
                <Type>BUILDINGCLASS_CHIEF_DUMMY_P</Type>
                <DefaultBuilding>BUILDING_CHIEF_DUMMY_P</DefaultBuilding>
            </Row>
            <Row>
                <Type>BUILDINGCLASS_CHIEF_DUMMY_G</Type>
                <DefaultBuilding>BUILDING_CHIEF_DUMMY_G</DefaultBuilding>
            </Row>
            <Row>
                <Type>BUILDINGCLASS_CHIEF_DUMMY_S</Type>
                <DefaultBuilding>BUILDING_CHIEF_DUMMY_S</DefaultBuilding>
            </Row>
            <Row>
                <Type>BUILDINGCLASS_CHIEF_DUMMY_C</Type>
                <DefaultBuilding>BUILDING_CHIEF_DUMMY_C</DefaultBuilding>
            </Row>
            <Row>
                <Type>BUILDINGCLASS_CHIEF_DUMMY_FA</Type>
                <DefaultBuilding>BUILDING_CHIEF_DUMMY_FA</DefaultBuilding>
            </Row>
            <Row>
                <Type>BUILDINGCLASS_CHIEF_DUMMY_T</Type>
                <DefaultBuilding>BUILDING_CHIEF_DUMMY_T</DefaultBuilding>
            </Row>
        </BuildingClasses>
        <Buildings>
            <Row>
                <Type>BUILDING_CHIEF_DUMMY</Type>
                <BuildingClass>BUILDINGCLASS_CHIEF_DUMMY</BuildingClass>
                <Cost>-1</Cost>
                <FaithCost>-1</FaithCost>
                <PrereqTech>NULL</PrereqTech>
                <GreatWorkCount>-1</GreatWorkCount>
                <MinAreaSize>-1</MinAreaSize>
                <HurryCostModifier>-1</HurryCostModifier>
                <NukeImmune>true</NukeImmune>
                <NeverCapture>true</NeverCapture>
                <Happiness>1</Happiness>
                <Defense>300</Defense>
                <ExtraCityHitPoints>15</ExtraCityHitPoints>
            </Row>
            <Row>
                <Type>BUILDING_CHIEF_DUMMY_F</Type>
                <BuildingClass>BUILDINGCLASS_CHIEF_DUMMY_F</BuildingClass>
                <Cost>-1</Cost>
                <FaithCost>-1</FaithCost>
                <PrereqTech>NULL</PrereqTech>
                <GreatWorkCount>-1</GreatWorkCount>
                <MinAreaSize>-1</MinAreaSize>
                <HurryCostModifier>-1</HurryCostModifier>
                <NukeImmune>true</NukeImmune>
                <NeverCapture>true</NeverCapture>
            </Row>
            <Row>
                <Type>BUILDING_CHIEF_DUMMY_P</Type>
                <BuildingClass>BUILDINGCLASS_CHIEF_DUMMY_P</BuildingClass>
                <Cost>-1</Cost>
                <FaithCost>-1</FaithCost>
                <PrereqTech>NULL</PrereqTech>
                <GreatWorkCount>-1</GreatWorkCount>
                <MinAreaSize>-1</MinAreaSize>
                <HurryCostModifier>-1</HurryCostModifier>
                <NukeImmune>true</NukeImmune>
                <NeverCapture>true</NeverCapture>
            </Row>
            <Row>
                <Type>BUILDING_CHIEF_DUMMY_G</Type>
                <BuildingClass>BUILDINGCLASS_CHIEF_DUMMY_G</BuildingClass>
                <Cost>-1</Cost>
                <FaithCost>-1</FaithCost>
                <PrereqTech>NULL</PrereqTech>
                <GreatWorkCount>-1</GreatWorkCount>
                <MinAreaSize>-1</MinAreaSize>
                <HurryCostModifier>-1</HurryCostModifier>
                <NukeImmune>true</NukeImmune>
                <NeverCapture>true</NeverCapture>
            </Row>
            <Row>
                <Type>BUILDING_CHIEF_DUMMY_S</Type>
                <BuildingClass>BUILDINGCLASS_CHIEF_DUMMY_S</BuildingClass>
                <Cost>-1</Cost>
                <FaithCost>-1</FaithCost>
                <PrereqTech>NULL</PrereqTech>
                <GreatWorkCount>-1</GreatWorkCount>
                <MinAreaSize>-1</MinAreaSize>
                <HurryCostModifier>-1</HurryCostModifier>
                <NukeImmune>true</NukeImmune>
                <NeverCapture>true</NeverCapture>
            </Row>
            <Row>
                <Type>BUILDING_CHIEF_DUMMY_C</Type>
                <BuildingClass>BUILDINGCLASS_CHIEF_DUMMY_C</BuildingClass>
                <Cost>-1</Cost>
                <FaithCost>-1</FaithCost>
                <PrereqTech>NULL</PrereqTech>
                <GreatWorkCount>-1</GreatWorkCount>
                <MinAreaSize>-1</MinAreaSize>
                <HurryCostModifier>-1</HurryCostModifier>
                <NukeImmune>true</NukeImmune>
                <NeverCapture>true</NeverCapture>
            </Row>
            <Row>
                <Type>BUILDING_CHIEF_DUMMY_FA</Type>
                <BuildingClass>BUILDINGCLASS_CHIEF_DUMMY_FA</BuildingClass>
                <Cost>-1</Cost>
                <FaithCost>-1</FaithCost>
                <PrereqTech>NULL</PrereqTech>
                <GreatWorkCount>-1</GreatWorkCount>
                <MinAreaSize>-1</MinAreaSize>
                <HurryCostModifier>-1</HurryCostModifier>
                <NukeImmune>true</NukeImmune>
                <NeverCapture>true</NeverCapture>
            </Row>
            <Row>
                <Type>BUILDING_CHIEF_DUMMY_T</Type>
                <BuildingClass>BUILDINGCLASS_CHIEF_DUMMY_T</BuildingClass>
                <Cost>-1</Cost>
                <FaithCost>-1</FaithCost>
                <PrereqTech>NULL</PrereqTech>
                <GreatWorkCount>-1</GreatWorkCount>
                <MinAreaSize>-1</MinAreaSize>
                <HurryCostModifier>-1</HurryCostModifier>
                <NukeImmune>true</NukeImmune>
                <NeverCapture>true</NeverCapture>
                <GreatPeopleRateModifier>25</GreatPeopleRateModifier>
            </Row>
        </Buildings>
        <Building_YieldChanges>
            <Row>
                <BuildingType>BUILDING_CHIEF_DUMMY_FA</BuildingType>
                <YieldType>YIELD_FAITH</YieldType>
                <Yield>2</Yield>
            </Row>
        </Building_YieldChanges>
        <Building_YieldModifiers>
            <Row>
                <BuildingType>BUILDING_CHIEF_DUMMY_G</BuildingType>
                <YieldType>YIELD_GOLD</YieldType>
                <Yield>25</Yield>
            </Row>
            <Row>
                <BuildingType>BUILDING_CHIEF_DUMMY_S</BuildingType>
                <YieldType>YIELD_SCIENCE</YieldType>
                <Yield>25</Yield>
            </Row>
            <Row>
                <BuildingType>BUILDING_CHIEF_DUMMY_C</BuildingType>
                <YieldType>YIELD_CULTURE</YieldType>
                <Yield>25</Yield>
            </Row>
            <Row>
                <BuildingType>BUILDING_CHIEF_DUMMY_P</BuildingType>
                <YieldType>YIELD_PRODUCTION</YieldType>
                <Yield>25</Yield>
            </Row>
            <Row>
                <BuildingType>BUILDING_CHIEF_DUMMY_F</BuildingType>
                <YieldType>YIELD_FOOD</YieldType>
                <Yield>25</Yield>
            </Row>
        </Building_YieldModifiers>
    </GameData>
     
  7. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,517
    Location:
    Illinois, USA
    Do you have logging enabled ? whoward69's enable error logging tutorial
    What if anything is showing in lua.log in relation to your lua file?
    Have you set up the lua file as an "EntryPoints" > "InGameUIAddin" in your modinfo file ?
    Code:
    <EntryPoints>
        <EntryPoint type="InGameUIAddin" file="Something.lua">
    whoward69's what ModBuddy setting for what file types tutorial
    Do you have Eilliam Howard's PlotIterators lua file in your mod and set as ImportIntoVFS = true ? If not, the code is going to puke on the very first line since it won't be able to find the file listed in the "include" command.
     
  8. De Bliksem

    De Bliksem Chieftain

    Joined:
    Oct 5, 2018
    Messages:
    8
    ImportIntoVFS is on true, it is in entrypoints correctly (did it again just to make sure). The important lines in the logs seem to be these: (changed username into [USER])

    Spoiler :

    [522376.328] Runtime Error: C:\Users\[USER]\Documents\My Games\Sid Meier's Civilization 5\MODS\The Sioux 3 (v 1)\Lua\Sioux_Functions.lua:20: attempt to index global 'pCity' (a nil value)
    [522376.328] Runtime Error: Error loading C:\Users\[USER]\Documents\My Games\Sid Meier's Civilization 5\MODS\The Sioux 3 (v 1)\Lua\Sioux_Functions.lua.


    What do these lines mean?
     
  9. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,517
    Location:
    Illinois, USA
    This line is breaking your code
    Code:
    local focusType = pCity:GetFocusType();
    The bad line is in this part of your code
    Code:
    local buildingChiefDummyIDt = GameInfoTypes["BUILDING_CHIEF_DUMMY_T"]
    local focusType = pCity:GetFocusType();
    
    function Chief_Garrison(playerID)
    
    You don't need this line anyway, so you can safely delete it. Since "pCity" is undefined it is a "nil" value, which is what the first error line is reporting. Since you are getting a runtime error while attempting to load the file, the game is not using the file. The second error message is telling you the lua system encountered the error while attempting to load the lua file into the game's systems, and so did not load the file.
     
  10. De Bliksem

    De Bliksem Chieftain

    Joined:
    Oct 5, 2018
    Messages:
    8
    Removing the line did make the spawning of the dummybuildings work, but the buildings dont despawn when the chief leaves the city or when de city is put on another focus. So as soon as the city has this unit and the city has had every focus for 1 turn, the city permanently has all the bonusses of all buildings. This part probably doesn't work, but i dont know why:
    Spoiler :

    Code:
                else
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)       
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
     
  11. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,517
    Location:
    Illinois, USA
    3rd paragraph of post # 5. Your "else" clause is not part of
    Code:
    if ChiefIsHere then
    It is part of
    Code:
    if focusType == CityAIFocusTypes.NO_CITY_AI_FOCUS_TYPE then
    lua does not care about leading or trailing spaces nor leading or trailing tabs, so align your code using spaces or tabs so that you can more easily see what is part of what "if" conditional chunk and what "for" looping chunk
    Code:
    function Chief_Garrison(playerID)
    	local player = Players[playerID]
    	if player:IsAlive() then
    		for city in player:Cities() do
    			local focusType = city:GetFocusType();
    			local ChiefIsHere = false
    			local plot = city:Plot()
    			for i = 0, plot:GetNumUnits() - 1, 1 do
    				if plot:GetUnit(i):IsHasPromotion(unitPromotionChiefID) then
          					ChiefIsHere = true
    				end
    			end
    			if ChiefIsHere then
    				if focusType == CityAIFocusTypes.NO_CITY_AI_FOCUS_TYPE then
    					city:SetNumRealBuilding(buildingChiefDummyID, 1)
    				elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FOOD then
    					city:SetNumRealBuilding(buildingChiefDummyIDf, 1)
    				elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_PRODUCTION then
    					city:SetNumRealBuilding(buildingChiefDummyIDp, 1)
    				elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GOLD then
    					city:SetNumRealBuilding(buildingChiefDummyIDg, 1)
    				elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_SCIENCE then
    					city:SetNumRealBuilding(buildingChiefDummyIDs, 1)
    				elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_CULTURE then
    					city:SetNumRealBuilding(buildingChiefDummyIDc, 1)
    				elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FAITH then
    					city:SetNumRealBuilding(buildingChiefDummyIDfa, 1)
    				elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GREAT_PEOPLE then
    					city:SetNumRealBuilding(buildingChiefDummyIDt, 1)
    				else
    					city:SetNumRealBuilding(buildingChiefDummyID, 0)
    					city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
    					city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
    					city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
    					city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
    					city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
    					city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)      
    					city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    				end
    			end
    		end
    	end
    end
    Since there's no "end" command between the final "elseif focusType == ...." clause and the "else" clause, the "else" clause is part of the original "if focusType == CityAIFocusTypes" code-chunk. Even if that was not your intention, that is the way lua will evaluate it.

    So long as a city has any focus selected your code will never get to the "else" clause.

    If a city changes focus your code only adds the proper dummy for that focus, and never removes incorrect ones.
     
    Last edited: Mar 31, 2019
  12. De Bliksem

    De Bliksem Chieftain

    Joined:
    Oct 5, 2018
    Messages:
    8
    I made the mod work:

    Code:
    include("PlotIterators")
    
    for pAreaPlot in PlotAreaSweepIterator(pPlot, r) do
      print(pEdgePlot:GetX(), pEdgePlot:GetY())
    end
    
    local unitPromotionChiefID = GameInfoTypes["PROMOTION_CHIEF"]
    local buildingChiefDummyID = GameInfoTypes["BUILDING_CHIEF_DUMMY"]
    local buildingChiefDummyIDf = GameInfoTypes["BUILDING_CHIEF_DUMMY_F"]
    local buildingChiefDummyIDp = GameInfoTypes["BUILDING_CHIEF_DUMMY_P"]
    local buildingChiefDummyIDs = GameInfoTypes["BUILDING_CHIEF_DUMMY_S"]
    local buildingChiefDummyIDg = GameInfoTypes["BUILDING_CHIEF_DUMMY_G"]
    local buildingChiefDummyIDc = GameInfoTypes["BUILDING_CHIEF_DUMMY_C"]
    local buildingChiefDummyIDfa = GameInfoTypes["BUILDING_CHIEF_DUMMY_FA"]
    local buildingChiefDummyIDt = GameInfoTypes["BUILDING_CHIEF_DUMMY_T"]
    
    function Chief_Garrison(playerID)
        local player = Players[playerID]
        if player:IsAlive() then
            for city in player:Cities() do
                local focusType = city:GetFocusType();
                local ChiefIsHere = false
                local plot = city:Plot()
    
                for i = 0, plot:GetNumUnits() - 1, 1 do
                    if plot:GetUnit(i):IsHasPromotion(unitPromotionChiefID) then
                        ChiefIsHere = true
                    end
                end
                      
                if ChiefIsHere then
    
                    if focusType == CityAIFocusTypes.NO_CITY_AI_FOCUS_TYPE then
    
                        city:SetNumRealBuilding(buildingChiefDummyID, 1)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FOOD then
    
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 1)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_PRODUCTION then
    
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 1)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GOLD then
    
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 1)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_SCIENCE then
    
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 1)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_CULTURE then
      
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 1)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_FAITH then
    
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 1)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
    
                    elseif focusType == CityAIFocusTypes.CITY_AI_FOCUS_TYPE_GREAT_PEOPLE then
    
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 1)
                    end       
                else
                        city:SetNumRealBuilding(buildingChiefDummyID, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDf, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDp, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDg, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDs, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDc, 0)
                        city:SetNumRealBuilding(buildingChiefDummyIDfa, 0)     
                        city:SetNumRealBuilding(buildingChiefDummyIDt, 0)
                end
            end
        end
    end
    
    GameEvents.UnitSetXY.Add(Chief_Garrison)
    GameEvents.PlayerDoTurn.Add(Chief_Garrison)
    Thanks a lot for all the tips LeeS :D

    I got one more question: In a mod of JFD i saw he used the YIELD_GREAT_GENERAL_POINTS in building_yieldchanges. When i tried to copy this, the yield doesn't work. I've never seen this specific yield before, does it need another mod? Does this yield actually exist? (mod in question for reference: https://steamcommunity.com/sharedfiles/filedetails/?id=666637469)
     
  13. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,365
    Location:
    Near Portsmouth, UK
     

Share This Page