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

How to change improvement yield with Lua?

Discussion in 'Civ5 - Creation & Customization' started by identity0, Aug 3, 2017.

  1. identity0

    identity0 Chieftain

    Aug 3, 2017
    I'm making a new improvement, but I want it's behaviour to be a little more complex than the improvements in the game right now. Specifically, I want to make a town whose yield is based off of it's neighbouring tiles' yields. I've done all the XML, but how would I do it in Lua?
  2. Enginseer

    Enginseer Salientia of the Community Patch Supporter

    Nov 7, 2012
    Somewhere in California
    Why don't you just use the CP DLL where the XML already exist for the effect you look for?
  3. Chrisy15

    Chrisy15 Flower, Beautiful

    Jul 9, 2015
    Because DLL dependency where not necessary is rood :tibs1:

    Assuming that you just want a single yield to be increased, you'll need six improvements; if you're wanting something more complex, then you'll need more improvements but you'll follow the same idea.

    You'll want to iterate through all the plots adjacent to your improvement. WHoward's PlotIterators will work, although is unnecessary. Instead:

    for direction = 0, DirectionTypes.NUM_DIRECTION_TYPES -1, 1 do
    local pAdjPlot = Map.PlotDirection(pPlot:GetX(), pPlot:GetY(), direction)
    -- yada yara
    where pPlot is the improvement's plot.
    You'll want to collect information from each plot and save it outside the iterator, and then based off of this data you can then choose which improvement to place using pPlot:SetImprovementType(IMPROVEMENT ID, true). You'll want to hook this onto GameEvents.BuildFinished, which iirc has the arguments playerID, UnitID, ImprovementID, iX, iY. Choosing the improvement can be done either through a series of if - elseif statements, or by storing the improvements in a table.

Share This Page