C++/Lua Request Thread

Discussion in 'Civ5 - SDK / LUA' started by Nefliqus, Jun 11, 2012.

  1. Klisz

    Klisz King

    Joined:
    Aug 18, 2014
    Messages:
    804
    Oh, to elaborate on what I meant by "binary logic" - you make one dummy with +1 tourism, one with +2, one with +4, and so on up to (in this case) +32 - see this thread for more information. It's perfectly doable, I just wanted to make sure you were aware that you'd need several dummy buildings and not just one. ...and now after writing this, I see that LeeS has already posted a solution. I'll leave this up for posterity, though; that way future archeologists uncovering the ancient Civfanatics culture can record exactly how much better at Lua LeeS was than Klisz. :p

    Spoiler :
    Code:
    local iCultureDummy = GameInfoTypes.BUILDING_SENSHI_NENETS_CULTURE_DUMMY
    local iTourismDummy1 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_1
    local iTourismDummy2 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_2
    local iTourismDummy4 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_4
    local iTourismDummy8 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_8
    local iTourismDummy16 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_16
    local iTourismDummy32 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_32
    local iNenetsCiv = GameInfoTypes.CIVILIZATION_SENSHI_NENETS
    local iDeer = GameInfoTypes.RESOURCE_DEER
    
    function toBits(num)
        -- returns a table of bits, least significant first.
    	t={} -- will contain the bits
        while num>0 do
            local rest=math.fmod(num,2)
            t[#t+1]=rest
            num=(num-rest)/2
        end
        return t
    end
    
    local tGreatWorkBuildings = {} -- Cache all the GWoM buildings ahead of time to avoid resource-intensive database calls every turn
    for tRow in GameInfo.Buildings("GreatWorkCount > 0 AND GreatWorkSlotType = 'GREAT_WORK_SLOT_MUSIC'") do
    	tGreatWorkBuildings[tRow.ID] = tRow.GreatWorkCount
    end
    
    function UpdateDummyBuildings(iPlayer)
    	local pPlayer = Players[iPlayer]
    	if pPlayer:GetCivilizationType() == iNenetsCiv then
    		for pCity in pPlayer:Cities() do
    			local iWorkedDeer = 0
    			local iUnfilledMusic = 0
    			for iBuilding, iGreatWorkCount in pairs(tGreatWorkBuildings) do
    				if pCity:IsHasBuilding(iBuilding) then
    					iUnfilledMusic = iUnfilledMusic + (iGreatWorkCount - pCity:GetNumGreatWorksInBuilding(iBuilding))
    				end
    			end
    			for i = 0, pCity:GetNumCityPlots()-1, 1 do
    				local pPlot = pCity:GetCityIndexPlot(i)
    				if pPlot and pCity:IsWorkingPlot(pPlot) and pPlot:pPlot:GetResourceType() == iDeer then
    					iWorkedDeer = iWorkedDeer + 1
    				end
    			end
    			local iResult = iWorkedDeer
    			if iResult > iUnfilledMusic then iResult = iUnfilledMusic end
    			pCity:SetNumRealBuilding(iCultureDummy, iResult)
    			toBits(iResult*2)
    			pCity:SetNumRealBuilding(iTourismDummy1, t[1])
    			pCity:SetNumRealBuilding(iTourismDummy2, t[2])
    			pCity:SetNumRealBuilding(iTourismDummy4, t[3])
    			pCity:SetNumRealBuilding(iTourismDummy8, t[4])
    			pCity:SetNumRealBuilding(iTourismDummy16, t[5])
    			pCity:SetNumRealBuilding(iTourismDummy32, t[6])
    			pCity:SetNumRealBuilding(iCultureDummy, iResult)
    		end
    	end
    end
    
    function UpdateDummyBuildingsUI()
    	if bPopup then
    		UpdateDummyBuildings(Game:GetActivePlayer())
    	end
    end
    
    GameEvents.PlayerDoTurn.Add(UpdateDummyBuildings)
    Events.SerialEventCityInfoDirty.Add(UpdateDummyBuildingsUI)
    Code:
    local iNenetsCiv = GameInfoTypes.CIVILIZATION_SENSHI_NENETS
    local iDeer = GameInfoTypes.RESOURCE_DEER
    local iSnow = GameInfoTypes.TERRAIN_SNOW
    local iNotification = NotificationTypes.NOTIFICATION_DISCOVERED_BONUS_RESOURCE
    
    function DeerSpawn(iPlayer)
    	local pPlayer = Players[iPlayer]
    	if pPlayer:GetCivilizationType() == iNenetsCiv then
    		local CheckedPlots = {} -- to avoid having higher chances of deer spawning if a plot is within range of multiple cities
    		for pCity in pPlayer:Cities() do
    			for i = 0, pCity:GetNumCityPlots()-1, 1 do
    				local pPlot = pCity:GetCityIndexPlot(i)
    				if pPlot and pPlot:GetTerrainType() == iSnow pPlot:pPlot:GetResourceType() == -1 and (not CheckedPlots[pPlot:GetPlotIndex()]) then
    					CheckedPlots[pPlot:GetPlotIndex()] = 1
    					if Game.Rand(100, "Nenets deer spawn") < 5 then
    						pPlot:SetResourceType(iDeer)
    						pPlot:SetNumResource(1)
    						pPlayer:AddNotification(iNotification, Locale.ConvertTextKey("TXT_KEY_NOTIFICATION_FOUND_RESOURCE","TXT_KEY_RESOURCE_DEER"), Locale.ConvertTextKey("TXT_KEY_NOTIFICATION_SUMMARY_FOUND_RESOURCE","TXT_KEY_RESOURCE_DEER"),pPlot:GetX(),pPlot:GetY(),iDeer)
    					end
    				end
    			end
    		end
    	end
    end
    
    GameEvents.PlayerDoTurn.Add(DeerSpawn)


    In retrospect I now realize that that doesn't matter either way because there's a workaround to get the plot from GreatPersonExpended anyway (well, from UnitPrekill, but since a UnitPrekill always comes after a GreatPersonExpended we can set a boolean variable to detect whether a given UnitPrekill is a GP expending).

    For the Tadibya:

    Code:
    local iTadibya = GameInfoTypes.UNIT_SENSHI_TADIBYA
    local iSpawnDeer = GameInfoTypes.IMPROVEMENT_SENSHI_SPAWNDEER
    local iDeer = GameInfoTypes.RESOURCE_DEER
    local bTadibya = false
    
    GameEvents.GreatPersonExpended.Add(function(iPlayer, iUnitType)
    	if iUnitType == iTadibya then
    		bTadibya = true
    	end
    end)
    
    GameEvents.UnitPrekill.Add(function(iPlayer, iUnitID, iUnitType, iX, iY, bDelay, iByPlayer)
    	if bTadibya then
    		local pPlot = Map.GetPlot(iX, iY)
    		if pPlot:GetImprovementType() == iSpawnDeer then
    			pPlot:SetImprovementType(-1)
    			pPlot:SetResourceType(iDeer)
    			pPlot:SetNumResource(1)
    		end
    		bTadibya = false
    	end
    end)
    And the Samoyed; I've assumed that, if a Samoyed is owned by a non-Nenets civ (via a city-state or something) it should check for that civ's territory, not for Nenets territory. Also, this one will need PlotIterators included in the mod and imported into VFS.

    Code:
    include("PlotIterators.lua")
    local iSamoyed = GameInfoTypes.UNIT_SENSHI_SAMOYED
    local iMoveDeer = GameInfoTypes.IMPROVEMENT_SENSHI_MOVEDEER
    local iDeer = GameInfoTypes.RESOURCE_DEER
    local iSnow = GameInfoTypes.TERRAIN_SNOW
    local bSamoyed = false
    
    GameEvents.GreatPersonExpended.Add(function(iPlayer, iUnitType)
    	if iUnitType == iSamoyed then
    		bSamoyed = true
    	end
    end)
    
    GameEvents.UnitPrekill.Add(function(iPlayer, iUnitID, iUnitType, iX, iY, bDelay, iByPlayer)
    	local pPlayer = Players[iPlayer]
    	if bSamoyed then
    		local pPlot = Map.GetPlot(iX, iY)
    		if pPlot:GetImprovementType() == iMoveDeer then
    			pPlot:SetImprovementType(-1)
    			pPlot:SetResourceType(-1)
    			pPlot:SetNumResource(0)
    
    			local pDeerPlot = nil
    			local iDistance = 99999
    			for pCity in pPlayer:Cities() do
    				for pAreaPlot in PlotAreaSpiralIterator(pCity:GetPlot(), 6, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_EXCLUDE) do -- 5 is the maximum distance a city can expand naturally, but I'm adding 1 to account for potential citadels etc
    					if pAreaPlot and pAreaPlot:GetOwner() == iPlayer and pPlot:GetImprovementType() == -1 and pPlot:GetTerrainType() ~= iSnow then
    						local iNewDistance = Map.PlotDistance(pAreaPlot:GetX(), pAreaPlot:GetY(), iX, iY)
    						if iNewDistance < iDistance then
    							pDeerPlot = pAreaPlot
    							iDistance = iNewDistance
    						end
    					end
    				end
    			end
    			if pDeerPlot then
    				pDeerPlot:SetResourceType(iDeer, 1)
    				pDeerPlot:SetNumResource(1)
    			end
    		end
    		bSamoyed = false
    	end
    end)
     
  2. LeeS

    LeeS Imperator

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

    senshidenshi Switched the Red and Blue channels

    Joined:
    Jan 22, 2014
    Messages:
    1,651
    Gender:
    Male
    Location:
    Brisbane, QLD
    These are fantastic! Many thanks to the pair of you!
     
  4. Scissor_fingers

    Scissor_fingers Chieftain

    Joined:
    Jul 31, 2016
    Messages:
    10
    Location:
    Texas
    Hey I just need to know, what lua function allows you find out the amount of gold you receive when pillaging a trade route?
     
  5. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    I am often wrong but so far as I remember I don't know that there is one.

    Someone may have worked out a detection method such as using the pop-ups but otherwise I can't think where to begin.
     
  6. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,590
    Location:
    Near Portsmouth, UK
    It's hard-coded at 100 for land routes and twice that for sea routes. This is NOT scaled for game speed.

    If you want to know when a trade route is plundered, if you're using my DLL (or one based on it) you can hook the PlayerPlunderedTradeRoute game event, otherwise it will be very hard to detect. You will get a UnitKilled event, but filtering out the plundered units from other possibilities (eg city capture removing routes, player changing routes, etc) will be very difficult.

    PS: The AI doesn't receive popups/notifications, so that approach would only work for human only civs
     
  7. Harkodos

    Harkodos Warlord

    Joined:
    Feb 9, 2016
    Messages:
    180
    I had an idea for a civilization UA, and I was wondering if the following was possible with lua:

    So the idea is a Civilization's units will receive a combat bonus or something via a promotion while fighting on Pillaged Improvements (with some sort of tag to immediately give them the promotion upon pillaging an improvement so they do not have to re-position themselves to get said promotion). And then also the same Civ can get yields from pillaged improvements while working them with their cities (for instance a standard Farm would provide +1 Food, but when pillaged, would instead provide +1 Faith and +1 Culture).

    Are either of those possible?
     
  8. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    • The second half is doable in various different ways.
    • If you are only interested in specified improvements that are pillaged and are being worked by the player's cities, then this handler will perform the busy-work of finding all such tiles worked by city-X. See Post #2 under the function called GetCityImprovementPlots().
    • You would do as this for pillaged farms (as an example) that are being worked by an individual city:
      Code:
      local tNearbyDatas = GetCityMapDatas(pCity)
      local iImprovementID = GameInfoTypes.IMPROVEMENT_FARM
      local tFarmedPlots = GetCityImprovementPlots(tNearbyDatas, iImprovementID, "WorkedPlotsThatArePillaged")
      for Item,pPlot in pairs(tFarmedPlots) do
      	print("We Have a plot with a Farm on it! The plot's location is X" .. pPlot:GetX() .. ", Y" ..  pPlot:GetY())
      	--do your required actions for giving the city the +1 Faith and +1 Culture for this pillaged farm plot
      end
      So for all of a player's cities you would structure as this to run through all the player's cities and make the effects for pillaged farm plots that are being worked.:
      Code:
      for pCity in pPlayer:Cities() do
      	local tNearbyDatas = GetCityMapDatas(pCity)
      	local iImprovementID = GameInfoTypes.IMPROVEMENT_FARM
      	local tFarmedPlots = GetCityImprovementPlots(tNearbyDatas, iImprovementID, "WorkedPlotsThatArePillaged")
      	for Item,pPlot in pairs(tFarmedPlots) do
      		print("We Have a plot with a Farm on it! The plot's location is X" .. pPlot:GetX() .. ", Y" ..  pPlot:GetY())
      		--do your required actions for giving the city the +1 Faith and +1 Culture for this pillaged farm plot
      	end
      end
    • The linked handler can be used to find the information for all worked, pillaged tiles with any improvements, but you have to be comfortable with lua-table-manipulations in order to understand how to so use the utility.

    --------------------------------------------------------

    The first half is more problematical since there is no hook that fires when a plot gets pillaged.
     
  9. Scissor_fingers

    Scissor_fingers Chieftain

    Joined:
    Jul 31, 2016
    Messages:
    10
    Location:
    Texas
    Is there a way to find out if a unit has been built during a golden age?
     
  10. Harkodos

    Harkodos Warlord

    Joined:
    Feb 9, 2016
    Messages:
    180
    Wow, that is alot of stuff to go through. I only used farms as an example; the actual Civ idea would require any and all pillage-able improvements to be considered (so, Forts wouldn'ty count since they get removed when pillaged, but Farms, Mines, Pastures, camps, etc. would be counted).

    I take it that the combat bonus while on pillaged improvements can't work even without the ability to immediately check if the unit with said promotion is on the tile then? That's a pity.

    I do have another idea that I'm interested in:
    Is it possible to enable a unit with a particular promotion to receive 50% (or any percentage really) of an enemy units strength value as either Culture, Faith, Gold, or Science? I know this can be programmed for individual units in XML or given to all units by using Policies or Beliefs, but I'm wondering if this can be done with promotions to limit it to specific unit types.
     
  11. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    Not really in any reliable way I can think of using any Unit:Method() in lua if you do not in some way record this status when the unit is first created. You could create a promotion called something like PROMOTION_G_AGE_MARKER and then give the promotion to units created during a golden age.

    If you want to know whether the unit's owner is in a golden age when the unit is created that can be done simply by monitoring unit creations either by GameEvents.CityTrained() or by Events.SerialEventUnitCreated(). When a unit is created you just check to see whether the unit's owner is in a golden age. For Events.SerialEventUnitCreated() I prefer to use Machiavelli24's SerialEventUnitCreatedGood system because it eliminates all the redundant firing of the event that you get from the regular Events.SerialEventUnitCreated().
     
  12. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    Look more closely at the handler I pointed you to and you will see you can use it to get info on all improvements you are interested in. It just does not have a 'pre-packaged' function to give all pillaged plots of all improvement types in one go. So if you wanted Farms, Mines, Quarries, Plantations, etc., you could do as this:
    Spoiler :
    Code:
    for pCity in pPlayer:Cities() do
    	local tNearbyDatas = GetCityMapDatas(pCity)
    	local tPillagedImprovements = {}
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_FARM, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_MINE, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_QUARRY, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_TRADING_POST, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_LUMBERMILL, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_PASTURE, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_PLANTATION, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_CAMP, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_WELL, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_LANDMARK, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_ACADEMY, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_CUSTOMS_HOUSE, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_MANUFACTORY, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_CITADEL, "WorkedPlotsThatArePillaged")
    	tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    	for Item,pPlot in pairs(tPillagedImprovements) do
    		print("We Have a plot with a Farm on it! The plot's location is X" .. pPlot:GetX() .. ", Y" ..  pPlot:GetY())
    		--do your required actions for giving the city the +1 Faith and +1 Culture for this pillaged plot
    	end
    end
    It's a bit bloaty but it would do what you want after you fill in what the code should do for the line that says:
    You can do so as part of turn processing, for example. There is just no hook for detecting the plot the unit is standing on was just pillaged by the unit itself, as opposed to having been pillaged 100 turns ago.
    Kinda sorta possible but a bit of a pita to program and it will not be reliable in 100% of all conditions, nor will it work really when the unit kills another by defending itself from attack, nor all that well when the unit is a ranged unit that kills off another unit.

    But if you want all UNIT_MYCIVS_WARRIOR to have the effect, then just use table Unit_YieldFromKills as the Pictish Warrior does. In such case there would be no need for a promotion.
     
  13. Harkodos

    Harkodos Warlord

    Joined:
    Feb 9, 2016
    Messages:
    180
    I figured that the Improvements might require something like that, I just wasn't sure. Would the Faith, Culture, etc. from the plots be doable from the link you provided? Not sure where to look to to set that up.

    I'm sorry, I was forgetting my terminology. I did indeed mean Unit_YieldFromKills, but I was hoping to not have to utilize that in this circumstance (hence the promotion). From what I understand that sort of thing didn't take effect from the unit defending itself regardless so that didn't bother me, but the inability of Ranged units to get the effect is sort of a downer. Guess I can scrap that idea then.
     
  14. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    No, you have to write that part yourself and stick it into the place shown. Easiest method would be just to replace
    Code:
    --do your required actions for giving the city the +1 Faith and +1 Culture for this pillaged plot
    in the code with
    Code:
    pPlayer:ChangeFaith(1)
    pPlayer:ChangeJONSCulture(1)
    which would add +1 Faith and +1 Culture directly to the empire score for every pillaged plot found that a city is working.
     
  15. Harkodos

    Harkodos Warlord

    Joined:
    Feb 9, 2016
    Messages:
    180
    Okay, two more questions regarding the same subject:
    1. What's the significance of the "JONS" in ChangeJONSCulture? Is that a typo, something for something else that just got caught in, or is it how the lua code understands Culture? (and for that matter what would be the names of the other yields? Just for clarity.)
    2. And I should assume that this code in its entirety should have no problems triggering for multiple copies of the same civ? Just need to make sure that is a certain before proceeding.
     
  16. Klisz

    Klisz King

    Joined:
    Aug 18, 2014
    Messages:
    804
    That refers to Jon Shafer, lead designer of Civ5, who wrote some of the culture code and marked it for some reason (I guess to distinguish it from the obsolete - and, AFAIK, later deleted - Civ4 culture code, or something). You just need it for culture.
     
  17. Harkodos

    Harkodos Warlord

    Joined:
    Feb 9, 2016
    Messages:
    180
    Alright, I finally got around to trying out that code from the stuff from pillaged improvements, but I don't believe I've set it up right. I tried just recently and got an error message:
    Code:
    [985435.414] Runtime Error: C:\...\Lua/Kefka_Traits.lua:11: attempt to call global 'GetCityMapDatas' (a nil value)
    I've included the full .lua code I have at present. I hope it isn't merely another spelling mistake (I found 4 of those that I made while testing.)
    Spoiler :
    Code:
    local iCultOfKefkaCiv = GameInfoTypes.CIVILIZATION_THE_CULT_OF_KEFKA
    
    function CultOfKefkaTrait(iPlayer)
    	local pPlayer = Players[iPlayer]
    	if pPlayer:GetCivilizationType() == iCultOfKefkaCiv then
    		for pCity in pPlayer:Cities() do
    			local tNearbyDatas = GetCityMapDatas(pCity)
    			local tPillagedImprovements = {}
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_FARM, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_MINE, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_QUARRY, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_TRADING_POST, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_LUMBERMILL, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_PASTURE, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_PLANTATION, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_CAMP, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_WELL, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_LANDMARK, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_ACADEMY, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_CUSTOMS_HOUSE, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_MANUFACTORY, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_CITADEL, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				local tCityPillagedImprovements = GetCityImprovementPlots(tNearbyDatas, GameInfoTypes.IMPROVEMENT_HOLY_SITE, "WorkedPlotsThatArePillaged")
    					tCityPillagedImprovements, tPillagedImprovements = FilterTableContents(tCityPillagedImprovements, tPillagedImprovements)
    				for Item,pPlot in pairs(tPillagedImprovements) do
    					print("We Have a plot with a Pillaged Improvement on it! The plot's location is X" .. pPlot:GetX() .. ", Y" ..  pPlot:GetY())
    			pPlayer:ChangeFaith(2)
    			end
    		end
    	end
    end
    GameEvents.PlayerDoTurn.Add(CultOfKefkaTrait)
     
  18. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,590
    Location:
    Near Portsmouth, UK
    If that's the full Lua code, you're missing an include() statement (see the post LeeS linked to in his initial answer) and, at a guess, also the utility file link from that post (which will need to be VFS=true)
     
  19. Harkodos

    Harkodos Warlord

    Joined:
    Feb 9, 2016
    Messages:
    180
    Alright, thanks that worked!

    However now that the code does work, I have experienced a quirk when working with it. While testing it with the IGE Editor, it appears that I have observed that the effect will opt to either trigger only for the player or the AI, whichever uses it first.

    So, for example: I had 3 AI players in one game and I gave them all pillaged improvements around their cities. Because they had access to the triggering mechanism first, they were the only ones who could receive the benefit, whereas I couldn't, but on a different game 1-on-1 I gave myself pillaged improvements and was thus able to trigger the effect first for myself, and the other player, even when given pillaged improvements could not utilize them for the same benefit as me.

    Any thoughts?
     
  20. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,590
    Location:
    Near Portsmouth, UK
    Don't use IGE in this way - the sequencing will not be the same as when played.

    Give the AI an unpillaged improvement (with IGE or FireTuner), declare war on the AI, plop a unit on the improvement and pillage it. Now check the effects.

    Give yourself an unpillaged improvement, plop (lots of) barbarians around it (one will be bound to pillage it), then check for the effects.
     

Share This Page