C++/Lua Request Thread

Is there a way to issue out a Lua function once the game is created?

I'm not looking for someone to make it, but rather a hook because I want the game to create a one-time effect of spawning the map with ancient ruins in water.
 
@Enginseer - See "Maps - Random Goody Huts" for one way (there are others). It runs the goody hut spawning part of the map scripts if you pick a (saved) .civ5map to play on
 
I have a few questions that I hope that I can get answered:

1.) I'm trying to have a UA where there's a 10% that Bananas will turn into a custom resource, called Golden Bananas, in Golden Ages.
I'm trying to figure out on how to do that and it looks like I would need to alter the percentage from the map size and the game speed as well.
I borrowed his code here from Colonial Legacies' Inuit Civ:
Code:
local iBananas = GameInfoTypes.RESOURCE_BANANA

-- This checks if a plot has a Golden Banana resource in it.
local function CheckForGoldeBananas(plot)
	for i = 0, 5 do
		local NeiraiHP = Map.PlotDirection(plot:GetX(), plot:GetY(), i);
		print(NeiraiHP)
		if NeiraiHP ~= nil then
			print("Checking for Golden Bananas")
			if NeiraiHP:GetTerrainType() == TerrainTypes.TERRAIN_JUNGLE then
				print("This should return true")
				return true
			end
		end
	end	
	return false
end

-- And this turns Banana into Golden Bananas during a Golden Age.
-- To do: Make it that there's a small chance of Golden Bananas being created.
function TurnBananasToGoldenBananas(player)
	local pPlayer = Players[player]
	if pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_DK_ISLES then
		for pCity in pPlayer:Cities() do
			for pCityPlot = 0, pCity:GetNumCityPlots() - 1, 1 do
				local pSpecificPlot = pCity:GetCityIndexPlot(pCityPlot)
				if pPlayer:IsGoldenAge() then
					if pSpecificPlot ~= nil then
						if pSpecificPlot:GetOwner() == pCity:GetOwner() then
							if pSpecificPlot:GetResourceType(-1) == GameInfoTypes.RESOURCE_BANANA then
								print("Bananas found")
								if CheckForGoldeBananas(pSpecificPlot) then
									print("Turn this to a Golden Banana!")
									local pTitle = ("Golden Bananas near " .. pCity:GetName() .. "!")
									local pDesc = ("Oh Banana! A bunch of bananas has turned into a bunch of Golden Bananas near " .. pCity:GetName() .. "!")
									pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, pDesc, pTitle, pCity:GetX(), pCity:GetY())
								end
							end
						end
					end
				end
			end
		end
	end
GameEvents.PlayerDoTurn.Add(TurnBananasToGoldenBananas)

2.) The second part of the UA would be starting next to a source of bananas. I'm still debating on if I should add this code or not, since you don't actually start next to a resource, but it "creates" them instead, and it's possible you won't start next to the resource. However, my Civ starts in jungles and avoids desert and tundras, and bananas are a common resource, it's possible that I might not need this code. Anyways, here it is and I'm wondering if there's any errors on it:
Code:
local DKCiv = GameInfoTypes.CIVILIZATION_DK_ISLES--Civ ID;
local Bananas = GameInfoTypes.RESOURCE_BANANA

GameEvents.PlayerCityFounded.Add(function(iPlayer, iCityX, iCityY)
        if Players[iPlayer]:GetCivilizationType() == LionCiv then
                local kplot = Map.GetPlot(iCityX, iCityY);
                local kCity = kplot:GetPlotCity();
                if kCity:IsOriginalMajorCapital() then
                        AddBananas(kCity)
                end
        end
end)

function AddBananas(kCity)
        PlotCount = 0;
        PlotVT = {}
        for i = 1, kCity:GetNumCityPlots() -1 do
                if kCity:GetCityIndexPlot(i) ~= nil then
                        local iPlot = kCity:GetCityIndexPlot(i);
                        if iPlot:GetResourceType(-1) == -1 then
                                if ResourceValid(iPlot) then
                                        PlotCount = PlotCount + 1;
                                        PlotVT[PlotCount] = iPlot;
                                end
                        end
                end
        end
        RandomPlot = nil;
        for i = 1, math.min(PlotCount, 2) do
                OldRandom = RandomPlot;
                RandomPlot = Game.Rand(1, PlotCount);
                while OldRandom == RandomPlot do
                        RandomPlot = Game.Rand(1, PlotCount);
                end
                PlotVT[RandomPlot]:SetResourceType(GetResource(PlotVT[RandomPlot]), 1);
        end
        PlotVT = nil;
end

function GetResource(iPlot)
        ResCount = 0;
        ResVT = {}
        for iRes, bool in pairs(Bananas) do
                if iPlot:CanHaveResource(iRes) then
                        ResCount = ResCount + 1;
                        ResVT[ResCount] = iRes;
                end
        end
        if ResCount > 0 then
                return ResVT[Game.Rand(1, ResCount)];
        else
                print("It cannot be! It's impossibru!")
                return -1;
        end
end

function ResourceValid(iPlot)
        for iRes, bool in pairs(Bananas) do
                if iPlot:CanHaveResource(iRes) then
                        return true;
                end
        end
        return false;
end

3.) And finally, is it possible to make a Lua code where 20% of Faith generated contributes to Science generated per turn?
 
  1. This part of your code does not check whether a specified plot has bananas, nor if adjacent plots have bananas. It checks whether any plot adjacent to the specified plot is a jungle tile
    Code:
    local function CheckForGoldeBananas(plot)
    	for i = 0, 5 do
    		local NeiraiHP = Map.PlotDirection(plot:GetX(), plot:GetY(), i);
    		print(NeiraiHP)
    		if NeiraiHP ~= nil then
    			print("Checking for Golden Bananas")
    			if [color="blue"]NeiraiHP:GetTerrainType() == TerrainTypes.TERRAIN_JUNGLE[/color] then
    				print("This should return true")
    				return true
    			end
    		end
    	end	
    	return false
    end
  2. You make the check for an adjacent jungle plot to an existing banana plot, but then the rest of the code does nothing except spit out a Notification that a human playing as some other civ will be able to see (and be confused by).
  3. The TurnBananasToGoldenBananas part of your code was missing a needed "end". I've also re-arranged a little to make it more efficient. No need to look through a player's cities or those city plots when the player is not in a golden age. However, the issue of never actually creating any Golden Bananas still remains, as does the issue that function CheckForGoldeBananas is still just checking for an adjacent jungle tile:
    Code:
    local iBananas = GameInfoTypes.RESOURCE_BANANA
    local iRequiredCivilization = GameInfoTypes.CIVILIZATION_DK_ISLES
    local iJungle = GameInfoTypes.FEATURE_JUNGLE
    
    -- This checks if a plot has a Golden Banana resource in it.
    local function CheckForGoldeBananas(pPlot)
    	for direction = 0, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
    		local pAdjacentPlot = Map.PlotDirection(pPlot:GetX(), pPlot:GetY(), direction)
    		if pAdjacentPlot ~= nil then
    			print("Checking for Golden Bananas")
    			if pAdjacentPlot:GetFeatureType() == iJungle then
    				print("This should return true")
    				return true
    			end
    		end
    	end	
    	return false
    end
    
    -- And this turns Banana into Golden Bananas during a Golden Age.
    -- To do: Make it that there's a small chance of Golden Bananas being created.
    function TurnBananasToGoldenBananas(iPlayer)
    	local pPlayer = Players[iPlayer]
    	if (pPlayer:GetCivilizationType() == iRequiredCivilization) and pPlayer:IsGoldenAge() then
    		for pCity in pPlayer:Cities() do
    			for iCityPlot = 0, pCity:GetNumCityPlots() - 1, 1 do
    				local pSpecificPlot = pCity:GetCityIndexPlot(iCityPlot)
    				if pSpecificPlot ~= nil then
    					if pSpecificPlot:GetOwner() == iPlayer then
    						if pSpecificPlot:GetResourceType(-1) == iBananas then
    							print("Bananas found")
    							if CheckForGoldeBananas(pSpecificPlot) then
    								print("Turn this to a Golden Banana!")
    								local pTitle = ("Golden Bananas near " .. pCity:GetName() .. "!")
    								local pDesc = ("Oh Banana! A bunch of bananas has turned into a bunch of Golden Bananas near " .. pCity:GetName() .. "!")
    								pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, pDesc, pTitle, pCity:GetX(), pCity:GetY())
    							end
    						end
    					end
    				end
    			end
    		end
    	end
    end
    GameEvents.PlayerDoTurn.Add(TurnBananasToGoldenBananas)
    • I also edited to fix the whoops that William pointed out wrt Jungles are a Feature and not a Terrain, and to use the system I use more commonly for plot variable 'naming' because I think it is easier to follow what the code is doing, and it is more directly obvious what the code is doing when you use a variable called pAdjacentPlot instead of something like Georgeness.
  4. Under your #2, this
    Code:
    local [color="red"]DKCiv[/color] = GameInfoTypes.CIVILIZATION_DK_ISLES--Civ ID;
    does not match to this
    Code:
    if Players[iPlayer]:GetCivilizationType() == [color="red"]LionCiv[/color] then
    so there would never be a case where the conditional check ever is evaluated as "true"
    • I didn't look any farther into the rest of the #2 code because lunch
  5. Your number 3 is quite possible but there are a couple of idiosyncracies with adding research points to a player's "score". I'll try to check back later and answer in more detail if no one else already has Ninja-William has not already done so.
 
1) Jungle is a feature, not a terrain (and bananas are a resource)

2) for iRes, bool in pairs(Bananas) do
Bananas is an int, not an array (so pairs(Bananas) will throw a run-time error)

I didn't look any farther into the rest of the #2 code because dinner ;)
 
OTiger, try this:
Spoiler :
Code:
local iFaithPercentageForScience = .2
local iChanceGoldenBanana1inX = 10
local iBananas = GameInfoTypes.RESOURCE_BANANA
local iGoldenBananas = GameInfoTypes.RESOURCE_BANANA_GOLDEN
local iRequiredCivilization = GameInfoTypes.CIVILIZATION_DK_ISLES
local tValidResources = {[GameInfoTypes.RESOURCE_BANANA] = "true"}

-- And this turns Banana into Golden Bananas during a Golden Age.
	-- percentage chance is configurable within variable iChanceGoldenBanana1inX where "10" is 1 chance in 10 for each banana found
	-- this percentage is probably too high as it quickly reaches statistical certainty that all bananas will be converted during a golden age
-- converts 20% of FaithPerTurn to Science against current research project
	-- percentage is configurable within variable iFaithPercentageForScience
function DK_Isles_PlayerDoTurn(iPlayer)
	local pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == iRequiredCivilization) then
		if pPlayer:IsGoldenAge() then
			for pCity in pPlayer:Cities() do
				for iCityPlot = 0, pCity:GetNumCityPlots() - 1, 1 do
					local pSpecificPlot = pCity:GetCityIndexPlot(iCityPlot)
					if pSpecificPlot ~= nil then
						if pSpecificPlot:GetOwner() == iPlayer then
							if pSpecificPlot:GetResourceType(-1) == iBananas then
								print("Bananas found")
								if Game.Rand(1, iChanceGoldenBanana1inX) == iChanceGoldenBanana1inX then
									print("Turn this to a Golden Banana!")
									pSpecificPlot:SetResourceType(iGoldenBananas, 1);
									local sTitle = ("Golden Bananas near " .. pCity:GetName() .. "!")
									local sDesc = ("Oh Banana! A bunch of bananas has turned into a bunch of Golden Bananas near " .. pCity:GetName() .. "!")
									if pPlayer:IsHuman() then
										pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, sDesc, sTitle, pCity:GetX(), pCity:GetY())
									end
									print(sDesc)
								end
							end
						end
					end
				end
			end
		end
		local iExtraSciencePerTurn = math.ceil(iFaithPercentageForScience * pPlayer:GetTotalFaithPerTurn())
		local iCurrentResearchItem = pPlayer:GetCurrentResearch()
		if (iCurrentResearchItem ~= -1) then
			local pTeam = Teams[pPlayer:GetTeam()]
			local pTeamTechs = pTeam:GetTeamTechs()
			pTeamTechs:ChangeResearchProgress(iCurrentResearchItem, iExtraSciencePerTurn)
		end
	end
end


function ResourceValid(pPlot)
        for iRes, bool in pairs(tValidResources) do
                if pPlot:CanHaveResource(iRes) then
                        return true;
                end
        end
        return false;
end
function GetResource(pPlot)
        ResCount = 0;
        ResVT = {}
        for iRes, bool in pairs(tValidResources) do
                if pPlot:CanHaveResource(iRes) then
                        ResCount = ResCount + 1;
                        ResVT[ResCount] = iRes;
                end
        end
        if ResCount > 0 then
                return ResVT[Game.Rand(1, ResCount)];
        else
                print("It cannot be! It's impossibru!")
                return -1;
        end
end
function AddBananas(pCity)
        local iPlotCount = 0;
        local PlotVT = {}
        for i = 1, pCity:GetNumCityPlots() -1 do
                if pCity:GetCityIndexPlot(i) ~= nil then
                        local pPlot = pCity:GetCityIndexPlot(i);
                        if pPlot:GetResourceType(-1) == -1 then
                                if ResourceValid(pPlot) then
                                        iPlotCount = iPlotCount + 1;
                                        PlotVT[iPlotCount] = pPlot;
                                end
                        end
                end
        end
        local RandomPlot = nil;
        for i = 1, math.min(iPlotCount, 2) do
                local OldRandom = RandomPlot;
                RandomPlot = Game.Rand(1, iPlotCount);
                while OldRandom == RandomPlot do
                        RandomPlot = Game.Rand(1, iPlotCount);
                end
                PlotVT[RandomPlot]:SetResourceType(GetResource(PlotVT[RandomPlot]), 1);
        end
        PlotVT = nil;
end
function BananasOnCapitalFounding(iPlayer, iCityX, iCityY)
        if Players[iPlayer]:GetCivilizationType() == iRequiredCivilization then
                local pPlot = Map.GetPlot(iCityX, iCityY);
                local pCity = pPlot:GetPlotCity();
                if pCity:IsOriginalMajorCapital() then
                        AddBananas(pCity)
                end
		GameEvents.PlayerCityFounded.Remove(BananasOnCapitalFounding)
        end
end

------------------------------------------------------------
---- WilliamHoward's IsCivInPlay
------------------------------------------------------------

function IsCivInPlay(iCivType)
  for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local iSlotStatus = PreGame.GetSlotStatus(iSlot)
    if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
      if (PreGame.GetCivilization(iSlot) == iCivType) then
        return true
      end
    end
  end
  
  return false
end

------------------------------------------------------------
---- Game Event Hooks
------------------------------------------------------------

if IsCivInPlay(iRequiredCivilization) then
	GameEvents.PlayerCityFounded.Add(BananasOnCapitalFounding)
	GameEvents.PlayerDoTurn.Add(DK_Isles_PlayerDoTurn)
end
  • You will have to change RESOURCE_BANANA_GOLDEN to the correct resource xml-name for the Golden Bananas, and you will probably have to play around with the 1-in-X chance being set as "10" after some testing to see if I am correct that it will pretty quickly convert all Banana plots the player owns to Golden Banana plots.
  • I'm still not 100% sure I've analyzed correctly exactly what was/is going on in the banana placement code for original city founding. I don't believe I made any eggregious errors editing that part of the code, but testing is required.
  • There is still an outstanding possible issue with the Faith > Science thing in that without William's most recent version of VMC-DLL there is no place for the science points to "go" during turn processing when the player completes a research project (so they are lost as I have written the code), and I am not sure what happens to the overflow points (if any) as I have written the code. As part of next-turn processing, the research project is completed before any PlayerDoTurn events fire, so the player's current research project is "-1" during PlayerDoTurn events in that condition since the player has not yet had a chance to select their next research project.
    • The easiest expediant might be to apply the research to the 1st unresearched tech found in the technologies table. But this also requires a little think-through, as it is possible the 1st unresearched tech found might be an early-era one with essentially no tech cost.
 
I forgot to mention that the Faith into Science code is for a different Civ, I was wondering how to take that part out without wrecking rest of the code.

I also got an Lua error while trying to "move" the code myself:
Code:
[49175.531] Runtime Error: C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Test Mod (v 1)\DK Trait.lua:91: attempt to index field '?' (a nil value)
stack traceback:
	C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Test Mod (v 1)\DK Trait.lua:91: in function 'AddBananas'
	C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Test Mod (v 1)\DK Trait.lua:100: in function <C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Test Mod (v 1)\DK Trait.lua:95>

Here's the coding you did, now split up:
Code:
-- DK Trait
-- Author: Admin
-- DateCreated: 12/1/2015 12:02:06 AM
-- Based on Colonial Legacies' Inuit Civ and Pridelands Civ
--------------------------------------------------------------
local iChanceGoldenBanana1inX = 5
local iBananas = GameInfoTypes.RESOURCE_BANANA
local iGoldenBananas = GameInfoTypes.RESOURCE_SILK
local iRequiredCivilization = GameInfoTypes.CIVILIZATION_SIAM
local tValidResources = {[GameInfoTypes.RESOURCE_BANANA] = "true"}

-- And this turns Banana into Golden Bananas during a Golden Age.
	-- percentage chance is configurable within variable iChanceGoldenBanana1inX where "10" is 1 chance in 10 for each banana found
	-- this percentage is probably too high as it quickly reaches statistical certainty that all bananas will be converted during a golden age
function DK_Isles_PlayerDoTurn(iPlayer)
	local pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == iRequiredCivilization) then
		if pPlayer:IsGoldenAge() then
			for pCity in pPlayer:Cities() do
				for iCityPlot = 0, pCity:GetNumCityPlots() - 1, 1 do
					local pSpecificPlot = pCity:GetCityIndexPlot(iCityPlot)
					if pSpecificPlot ~= nil then
						if pSpecificPlot:GetOwner() == iPlayer then
							if pSpecificPlot:GetResourceType(-1) == iBananas then
								print("Bananas found")
								if Game.Rand(1, iChanceGoldenBanana1inX) == iChanceGoldenBanana1inX then
									print("Turn this to a Golden Banana!")
									pSpecificPlot:SetResourceType(iGoldenBananas, 1);
									local sTitle = ("Golden Bananas near " .. pCity:GetName() .. "!")
									local sDesc = ("Oh Banana! A bunch of bananas has turned into a bunch of Golden Bananas near " .. pCity:GetName() .. "!")
									if pPlayer:IsHuman() then
										pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, sDesc, sTitle, pCity:GetX(), pCity:GetY())
									end
									print(sDesc)
								end
							end
						end
					end
				end
			end
		end
	end
end


function ResourceValid(pPlot)
        for iRes, bool in pairs(tValidResources) do
                if pPlot:CanHaveResource(iRes) then
                        return true;
                end
        end
        return false;
end
function GetResource(pPlot)
        ResCount = 0;
        ResVT = {}
        for iRes, bool in pairs(tValidResources) do
                if pPlot:CanHaveResource(iRes) then
                        ResCount = ResCount + 1;
                        ResVT[ResCount] = iRes;
                end
        end
        if ResCount > 0 then
                return ResVT[Game.Rand(1, ResCount)];
        else
                print("It cannot be! It's impossibru!")
                return -1;
        end
end
function AddBananas(pCity)
        local iPlotCount = 0;
        local PlotVT = {}
        for i = 1, pCity:GetNumCityPlots() -1 do
                if pCity:GetCityIndexPlot(i) ~= nil then
                        local pPlot = pCity:GetCityIndexPlot(i);
                        if pPlot:GetResourceType(-1) == -1 then
                                if ResourceValid(pPlot) then
                                        iPlotCount = iPlotCount + 1;
                                        PlotVT[iPlotCount] = pPlot;
                                end
                        end
                end
        end
        local RandomPlot = nil;
        for i = 1, math.min(iPlotCount, 2) do
                local OldRandom = RandomPlot;
                RandomPlot = Game.Rand(1, iPlotCount);
                while OldRandom == RandomPlot do
                        RandomPlot = Game.Rand(1, iPlotCount);
                end
                PlotVT[RandomPlot]:SetResourceType(GetResource(PlotVT[RandomPlot]), 1);
        end
        PlotVT = nil;
end
function BananasOnCapitalFounding(iPlayer, iCityX, iCityY)
        if Players[iPlayer]:GetCivilizationType() == iRequiredCivilization then
                local pPlot = Map.GetPlot(iCityX, iCityY);
                local pCity = pPlot:GetPlotCity();
                if pCity:IsOriginalMajorCapital() then
                        AddBananas(pCity)
                end
		GameEvents.PlayerCityFounded.Remove(BananasOnCapitalFounding)
        end
end

------------------------------------------------------------
---- WilliamHoward's IsCivInPlay
------------------------------------------------------------

function IsCivInPlay(iCivType)
  for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local iSlotStatus = PreGame.GetSlotStatus(iSlot)
    if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
      if (PreGame.GetCivilization(iSlot) == iCivType) then
        return true
      end
    end
  end
  
  return false
end

------------------------------------------------------------
---- Game Event Hooks
------------------------------------------------------------

if IsCivInPlay(iRequiredCivilization) then
	GameEvents.PlayerCityFounded.Add(BananasOnCapitalFounding)
	GameEvents.PlayerDoTurn.Add(DK_Isles_PlayerDoTurn)
end

And the other part:
Code:
-- Palutena_UA
-- Author: Admin
-- DateCreated: 5/24/2016 9:40:17 PM
--------------------------------------------------------------
	-- converts 20% of FaithPerTurn to Science against current research project
	-- percentage is configurable within variable iFaithPercentageForScience	
		local iFaithPercentageForScience = .2
		local iExtraSciencePerTurn = math.ceil(iFaithPercentageForScience * pPlayer:GetTotalFaithPerTurn())
		local iCurrentResearchItem = pPlayer:GetCurrentResearch()
		if (iCurrentResearchItem ~= -1) then
			local pTeam = Teams[pPlayer:GetTeam()]
			local pTeamTechs = pTeam:GetTeamTechs()
			pTeamTechs:ChangeResearchProgress(iCurrentResearchItem, iExtraSciencePerTurn)
		end

I'm sure that there's an error somewhere...
 
This line
Code:
PlotVT[RandomPlot]:SetResourceType(GetResource(PlotVT[RandomPlot]), 1);
appears to be getting garbage from the "GetResource" function so is generating the error because you can't specifiy a resource as "-1" for the SetResourceType method I don't think.

Changing iChanceGoldenBanana1inX to "5" means it is now more likely. 1-in-5 is 20%; 1-in10 is 10%; 1-in-100 is 1%.

The other part won't work because the faith-to-science thing is not in a function that is hooked to run from a game event. You need (assuming this code goes into a different mod than the other thing with the Bananas):
Code:
-- converts 20% of FaithPerTurn to Science against current research project
-- percentage is configurable within variable iFaithPercentageForScience

local iFaithPercentageForScience = .2
local iRequiredFaithToScienceCivilization = GameInfoTypes.CIVILIZATION_SOMETHING

function PlayerFaithToScience(iPlayer)
	local pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == iRequiredFaithToScienceCivilization) then
		local iExtraSciencePerTurn = math.ceil(iFaithPercentageForScience * pPlayer:GetTotalFaithPerTurn())
		local iCurrentResearchItem = pPlayer:GetCurrentResearch()
		if (iCurrentResearchItem ~= -1) then
			local pTeam = Teams[pPlayer:GetTeam()]
			local pTeamTechs = pTeam:GetTeamTechs()
			pTeamTechs:ChangeResearchProgress(iCurrentResearchItem, iExtraSciencePerTurn)
		end
	end
end
------------------------------------------------------------
---- WilliamHoward's IsCivInPlay
------------------------------------------------------------

function IsCivInPlay(iCivType)
  for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local iSlotStatus = PreGame.GetSlotStatus(iSlot)
    if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
      if (PreGame.GetCivilization(iSlot) == iCivType) then
        return true
      end
    end
  end
  
  return false
end

------------------------------------------------------------
---- Game Event Hooks
------------------------------------------------------------

if IsCivInPlay(iiRequiredFaithToScienceCivilization) then
	GameEvents.PlayerDoTurn.Add(PlayerFaithToScience)
end
If the two sets of code are for the same mod, they can go in the same file and then you only need this part once because the function can be shared by both civilizations if they are both part of the same mod:
Code:
------------------------------------------------------------
---- WilliamHoward's IsCivInPlay
------------------------------------------------------------

function IsCivInPlay(iCivType)
  for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local iSlotStatus = PreGame.GetSlotStatus(iSlot)
    if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
      if (PreGame.GetCivilization(iSlot) == iCivType) then
        return true
      end
    end
  end
  
  return false
end



It is getting late enough here that I will have to look at the root cause of the error you are getting in the Bananas code sometime tomorrow when I am not as sleepy/sloppy. Unless someone else sees where I went wrong editing the original code.
 
can't specifiy a resource as "-1" for the SetResourceType method I don't think.

You can (also SetFeatureType), it removes any resource/feature on the plot.

However, note that SetTerrainType(-1) will CTD!
 
You can (also SetFeatureType), it removes any resource/feature on the plot.

However, note that SetTerrainType(-1) will CTD!
Yeah, the problem ended up being in the usage of Game.Rand

I didn't pick up on the fact that Game.Rand was being stated as if it were math.random in the original code, ie, it was being stated as
Code:
Game.Rand(1, ResCount)
which is incorrect argument usage (as you know) for Game.Rand if you are trying to select as a range between "1" and "ResCount". What was commonly happening was that the 'return' on the Game.Rand method was '0', which was giving an invalid key reference for the lua-tables being used since none of the keys had an integer value of "0".

I wallbashed for a while before I realized what was going on, mostly because I usually use math.random even though it isn't MP friendly.

I forgot to mention that the Faith into Science code is for a different Civ, I was wondering how to take that part out without wrecking rest of the code.

I also got an Lua error while trying to "move" the code myself:
Code:
[49175.531] Runtime Error: C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Test Mod (v 1)\DK Trait.lua:91: attempt to index field '?' (a nil value)
stack traceback:
	C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Test Mod (v 1)\DK Trait.lua:91: in function 'AddBananas'
	C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Test Mod (v 1)\DK Trait.lua:100: in function <C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Test Mod (v 1)\DK Trait.lua:95>
I ended up re-writing the entire code for the starting bananas and the banana conversion before I realized the errors were coming from the way Game.Rand was being used. In any event here is a testing mod attached with functioning code for Banana placement near the capital city and for conversion of Banana into 'Golden Banana' during golden ages.
  • The code is in the lua folder in file Lua Script1.lua
  • I used Brazil and Silk as test civ and test "Golden Banana" resource, so you will have to change those.
  • If you change the "2" found here:
    Code:
    local tValidResources = {[GameInfoTypes.RESOURCE_BANANA] = {NumberTilesWanted=2}}
    this will make the code spawn more or less Banana resources near the capital depending on what integer value you specify. Just don't specify "0" because I did not code for that because it would be pointless.
  • The code will attempt to add up to the specified number of Banana resources stated for "NumberTilesWanted" but has some restrictions:
    • It accounts for existing resources within the working range of the capital city, and if there is already 1 Banana near the capital (as there was in my test) it will only add one (1) more banana.
    • It will only add the specified resources to valid tiles for that resource (although currently I haven't written anything in to only consider Hill tiles where Hill tiles are required)
    • It will work for multiple resources and for any resource that should be spawned on the main game map
    • For strategic resources, it will make the plot's "resource amount" the highest value valid for that resource as defined within the game's Resource_QuantityTypes table.
    • If you state a crazy high number for "NumberTilesWanted" it will only place the highest number it can based on other restrictions
    • It will never remove an existing resource from a plot
  • I'm thinking of revamping the code slighlty to make it more generic and therefore more generally useful than as it currently is (ie, it only runs on player founding an original capital city). I had this in mind when I structured the code as I did, but in a re-draft we would want to be able to state something like PlaceResourceNearCity(pCity, iResource, iNumberResourcesDesired) or perhaps PlaceResourcesNearCity(pCity, tTableDataOfResources). Gritty details on this final point is probably better left for a thread of its own.
The attachment is a zipped version of the mod taken from the game's MODs folder, so unzip and then you can open the files and edit as needed, or copy the lua file directly into your mod and edit as needed. You can also unzip the attachment and place it into your MODS folder and enable and run it like any other mod to fiddle with the settings.
 

Attachments

Yeah, the problem ended up being in the usage of Game.Rand

I didn't pick up on the fact that Game.Rand was being stated as if it were math.random in the original code, ie, it was being stated as
Code:
Game.Rand(1, ResCount)
which is incorrect argument usage (as you know) for Game.Rand if you are trying to select as a range between "1" and "ResCount". What was commonly happening was that the 'return' on the Game.Rand method was '0', which was giving an invalid key reference for the lua-tables being used since none of the keys had an integer value of "0".

I wallbashed for a while before I realized what was going on, mostly because I usually use math.random even though it isn't MP friendly.


I ended up re-writing the entire code for the starting bananas and the banana conversion before I realized the errors were coming from the way Game.Rand was being used. In any event here is a testing mod attached with functioning code for Banana placement near the capital city and for conversion of Banana into 'Golden Banana' during golden ages.
  • The code is in the lua folder in file Lua Script1.lua
  • I used Brazil and Silk as test civ and test "Golden Banana" resource, so you will have to change those.
  • If you change the "2" found here:
    Code:
    local tValidResources = {[GameInfoTypes.RESOURCE_BANANA] = {NumberTilesWanted=2}}
    this will make the code spawn more or less Banana resources near the capital depending on what integer value you specify. Just don't specify "0" because I did not code for that because it would be pointless.
  • The code will attempt to add up to the specified number of Banana resources stated for "NumberTilesWanted" but has some restrictions:
    • It accounts for existing resources within the working range of the capital city, and if there is already 1 Banana near the capital (as there was in my test) it will only add one (1) more banana.
    • It will only add the specified resources to valid tiles for that resource (although currently I haven't written anything in to only consider Hill tiles where Hill tiles are required)
    • It will work for multiple resources and for any resource that should be spawned on the main game map
    • For strategic resources, it will make the plot's "resource amount" the highest value valid for that resource as defined within the game's Resource_QuantityTypes table.
    • If you state a crazy high number for "NumberTilesWanted" it will only place the highest number it can based on other restrictions
    • It will never remove an existing resource from a plot
  • I'm thinking of revamping the code slighlty to make it more generic and therefore more generally useful than as it currently is (ie, it only runs on player founding an original capital city). I had this in mind when I structured the code as I did, but in a re-draft we would want to be able to state something like PlaceResourceNearCity(pCity, iResource, iNumberResourcesDesired) or perhaps PlaceResourcesNearCity(pCity, tTableDataOfResources). Gritty details on this final point is probably better left for a thread of its own.
The attachment is a zipped version of the mod taken from the game's MODs folder, so unzip and then you can open the files and edit as needed, or copy the lua file directly into your mod and edit as needed. You can also unzip the attachment and place it into your MODS folder and enable and run it like any other mod to fiddle with the settings.

Thanks for the code, LeeS!
I'll post in this thread again If I need some more code to be written.
 
Hi, I'm after some Lua code to make one technology become un-researched when another technology is researched. This is the first time I've tried to used Lua so it's all very confusing to me. This is what I've tried:

function LockProsperity(pTeam)
local pPlayer = Players[Game.GetActivePlayer()];
local pTeam = Teams[pPlayer:GetTeam()];
local pTeamTechs = pTeam:GetTeamTechs();
local iMight = GameInfoTypes[ "TECH_PATHOGEN_MIGHT" ];
local iProsperity = GameInfoTypes[ "TECH_PATHOGEN_PROSPERITY" ];
if( pTeamTechs:HasTech( iMight ) and
eLastTech = ( iProsperity )) then
TeamTechs:SetHasTech(( iMight ), false)
end
end

TECH_PATHOGEN_MIGHT and TECH_PATHOGEN_PROSPERITY have been defined in XML.

I tried to do it without this line:
eLastTech = ( iProsperity ))
and instead have discovering Prosperity be the trigger to make the code happen, but I wasn't sure how to do that.
 
I'm using this guide here to have a unique building get +2 Science per plantation.
I'm trying to see if I'm doing the code right and to solve a syntax error:

Code:
Syntax Error: C:\Users\Admin\Documents\My Games\Sid Meier's Civilization 5\MODS\Donkey Kong Donkey Kong and DK Island (BNW Only) (v 1)\Lua/BuildingsToNearbyImprovements.lua:32: unexpected symbol near '{

Code:
--[[

USER CONFIGURABLE VARIABLES

	Make changes to these variables as desired and needed

]]--
--------------------------------------------------------------

local bRequiresSpecificCiv = true
local iSpecificRequiredCiv = GameInfoTypes["CIVILIZATION_DK_ISLES"]
local bDoNotApplyToMinorCivs = true




----------------------------------------------------------------
--enter data into table tRealBuildingData here

--each subtable with table 'Counters' for a 'Real' building MUST have a designation of 'DummyBuilding=XXXXX'
----------------------------------------------------------------

tRealBuildingData[GameInfoTypes.BUILDING_TREEHOUSE] = {ApplyToAllInClass=true, Counters= {DummyBuilding=GameInfoTypes["BUILDING_TREEHOUSE_DUMMY"], ImprovementType=GameInfoTypes.IMPROVEMENT_PLANTATION, LimitPerCity=-1} }


{DummyBuilding="PLANTATIONS_TOTAL", ImprovementType=GameInfoTypes.IMPROVEMENT_PLANTATIONS, MustBeOwned=false, MustBeWorked=false, LimitPerCity=-1 },
{DummyBuilding="PLANTATIONS_OWNED", ImprovementType=GameInfoTypes.IMPROVEMENT_PLANTATIONS, MustBeOwned=true, MustBeWorked=false, LimitPerCity=-1 }}}
tRealBuildingData[GameInfoTypes.BUILDING_TREEHOUSE].SpecialHandling = (
	function(BuildingID, tDummyQuantitiesTable, pCity, iPlayer)
		local pPlayer = Players[iPlayer]
		if not pPlayer:IsHuman() then return end
		local iDummyBuilding = GameInfoTypes["BUILDING_TREEHOUSE_DUMMY"]
		local iOwnedPlantations = tDummyQuantitiesTable["PLANTATIONS_OWNED"]
		local iTotalPlantations = tDummyQuantitiesTable["PLANTATIONS_TOTAL"]
		local iNumberDummyToAdd = tDummyQuantitiesTable[iDummyBuilding]
		local sDummyBuildingName = Locale.ConvertTextKey(GameInfo.Buildings[iDummyBuilding].Description)
		print("The total number of Plantations within the working range of " .. pCity:GetName() .. " is " .. iTotalPlantations)
		print("The total number of Plantations within the working range of " .. pCity:GetName() .. " that are owned by player " .. pPlayer:GetName() .. " is " .. iOwnedPlantations)
		print("The total number of Dummy Buildings " .. sDummyBuildingName .. " that should be added if " .. pCity:GetName() .. " has a Treehouse-Class Building is " .. iNumberDummyToAdd)
		if pCity:IsHasBuilding(BuildingID) then
			pCity:SetNumRealBuilding(iDummyBuilding, iNumberDummyToAdd)
		else pCity:SetNumRealBuilding(iDummyBuilding, 0)
		end
	end
	)
 
I'm using this guide here to have a unique building get +2 Science per plantation.
I'm trying to see if I'm doing the code right and to solve a syntax error:
You really should have posted on the thread for that. You have a couple of different syntax mistakes. Plus it looks like you have misunderstood how to configure the "Counters". If all you want is to add one dummy building that gives +2 science for every plantation when there is a BUILDING_TREEHOUSE in a city, then all you should need is:
Code:
tRealBuildingData[GameInfoTypes.BUILDING_TREEHOUSE] = { Counters= {{DummyBuilding=GameInfoTypes["BUILDING_TREEHOUSE_DUMMY"], ImprovementType=GameInfoTypes.IMPROVEMENT_PLANTATION, LimitPerCity=-1} } }
You don't want this part for a unique building because "ApplyToAllInClass" makes the code apply the effect for all versions of a Building within the same Building-Class, and in your case "ApplyToAllInClass" refers to the class that BUILDING_TREEHOUSE belongs to:
Code:
ApplyToAllInClass=true
Nor should you need any of this because you aren't going to need any special handling (all you need to do is make sure BUILDING_TREEHOUSE_DUMMY gives +2 Science):
Code:
{DummyBuilding="PLANTATIONS_TOTAL", ImprovementType=GameInfoTypes.IMPROVEMENT_PLANTATIONS, MustBeOwned=false, MustBeWorked=false, LimitPerCity=-1 },
{DummyBuilding="PLANTATIONS_OWNED", ImprovementType=GameInfoTypes.IMPROVEMENT_PLANTATIONS, MustBeOwned=true, MustBeWorked=false, LimitPerCity=-1 }}}
tRealBuildingData[GameInfoTypes.BUILDING_TREEHOUSE].SpecialHandling = (
	function(BuildingID, tDummyQuantitiesTable, pCity, iPlayer)
		local pPlayer = Players[iPlayer]
		if not pPlayer:IsHuman() then return end
		local iDummyBuilding = GameInfoTypes["BUILDING_TREEHOUSE_DUMMY"]
		local iOwnedPlantations = tDummyQuantitiesTable["PLANTATIONS_OWNED"]
		local iTotalPlantations = tDummyQuantitiesTable["PLANTATIONS_TOTAL"]
		local iNumberDummyToAdd = tDummyQuantitiesTable[iDummyBuilding]
		local sDummyBuildingName = Locale.ConvertTextKey(GameInfo.Buildings[iDummyBuilding].Description)
		print("The total number of Plantations within the working range of " .. pCity:GetName() .. " is " .. iTotalPlantations)
		print("The total number of Plantations within the working range of " .. pCity:GetName() .. " that are owned by player " .. pPlayer:GetName() .. " is " .. iOwnedPlantations)
		print("The total number of Dummy Buildings " .. sDummyBuildingName .. " that should be added if " .. pCity:GetName() .. " has a Treehouse-Class Building is " .. iNumberDummyToAdd)
		if pCity:IsHasBuilding(BuildingID) then
			pCity:SetNumRealBuilding(iDummyBuilding, iNumberDummyToAdd)
		else pCity:SetNumRealBuilding(iDummyBuilding, 0)
		end
	end
	)
----------------------------------------------------------------------------------------------------------------------------------------

If you look at the bottom of Post#2 of the "Handler" thread, under the header called "Further Example of Configuring Table tRealBuildingData", you'll see a step-by-step for how to set-up a Linkage between a "Real" Building and an Improvement-Type where all that is needed is a one-to-one "link" between the number of Improvements found and the number of dummy buildings to add to the city.

In that example I used "ApplyToAllInClass=true" because I wanted to show how to make all versions of a Shrine give the same extra effect to Holy Sites.

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

In case I wasn't clear up-post, this is all you will need in place of the code you quoted:
Code:
--[[

USER CONFIGURABLE VARIABLES

	Make changes to these variables as desired and needed

]]--
--------------------------------------------------------------

local bRequiresSpecificCiv = true
local iSpecificRequiredCiv = GameInfoTypes["CIVILIZATION_DK_ISLES"]
local bDoNotApplyToMinorCivs = true




----------------------------------------------------------------
--enter data into table tRealBuildingData here

--each subtable with table 'Counters' for a 'Real' building MUST have a designation of 'DummyBuilding=XXXXX'
----------------------------------------------------------------


tRealBuildingData[GameInfoTypes.BUILDING_TREEHOUSE] = { Counters= { {DummyBuilding=GameInfoTypes["BUILDING_TREEHOUSE_DUMMY"], ImprovementType=GameInfoTypes.IMPROVEMENT_PLANTATION, LimitPerCity=-1} } }
 
Alright, I have some questions to answer again. However, there's a lot here, so take your time, or just answer some of the questions if you can.

1.) I'm trying to make a archery unit where it can be stacked with other military units and gets a bit stronger per era. It would be much weaker than the Composite Bowman, and gets killed when the main unit in its tile dies. It this possible?

2.) I'm updating a old mod of mine to have a unique Worker replacement to be upgradable to an military unit during war. How could I write this and how could I set it to upgrade to the strongest type of unit that the player can build?

3.) I've been putting E&D support to one of my mods, and I kinda got it to working, expect that the second decision isn't showing up. Here's the code: (I've posted this before. And I even PM'd Sukritac, about it, but he didn't respond.)

Code:
--------------------------------------------------------------------------------------------------------------------------
-- Expand the Krusty Krab Talent Show
--------------------------------------------------------------------------------------------------------------------------
local Decisions_KrustyKrabTalentShow = {}
	Decisions_KrustyKrabTalentShow.Name = "TXT_KEY_DECISIONS_KRUSTYKRABTALENTSHOW"
	Decisions_KrustyKrabTalentShow.Desc = "TXT_KEY_DECISIONS_KRUSTYKRABTALENTSHOW_DESC"
	HookDecisionCivilizationIcon(Decisions_KrustyKrabTalentShow, "CIVILIZATION_KRUSTY_KRAB")
	Decisions_KrustyKrabTalentShow.CanFunc = (
	function(pPlayer)
		if pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_KRUSTY_KRAB then return false, false end
		if load(pPlayer, "Decisions_KrustyKrabTalentShow") == true then
			Decisions_KrustyKrabTalentShow.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_KRUSTYKRABTALENTSHOW_ENACTED_DESC")
			return false, false, true
		end
		
		local iCost = math.ceil(500 * iMod)
		Decisions_KrustyKrabTalentShow.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_KRUSTYKRABTALENTSHOW_DESC", iCost)	
		if (pPlayer:GetNumResourceAvailable(iMagistrate, false) < 2) then return true, false end
		if (Teams[pPlayer:GetTeam()]:IsHasTech(GameInfoTypes.TECH_ACOUSTICS)) and (pPlayer:GetGold() >= iCost) then
			return true, true
		else
			return true, false
		end
	end
	)

	Decisions_KrustyKrabTalentShow.DoFunc = (
	function(pPlayer)
		local iCost = math.ceil(500 * iMod)
		pPlayer:ChangeGold(-iCost)
		pPlayer:ChangeNumResourceTotal(iMagistrate, -2)
		pPlayer:SetNumFreePolicies(1)
		pPlayer:SetNumFreePolicies(0)
		pPlayer:SetHasPolicy(GameInfoTypes.POLICY_DECISIONS_KRUSTYKRABTALENTSHOW, true)
		save(pPlayer, "Decisions_KrustyKrabTalentShow", true)
	end
	)

	Decisions_AddCivilisationSpecific(GameInfoTypes.CIVILIZATION_KRUSTY_KRAB, "Decisions_KrustyKrabTalentShow", Decisions_KrustyKrabTalentShow)

	--------------------------------------------------------------------------------------------------------------------------
-- Turn the Krusty Krab into a Hotel
--------------------------------------------------------------------------------------------------------------------------
local eraModernlID	 = GameInfoTypes["ERA_MODERN"]
local policyKrustyTowers = GameInfoTypes["POLICY_DECISIONS_KRUSTYKRABKRUSTYTOWERS"]
local Decisions_KrustyKrabKrustyTowers = {}
	Decisions_KrustyKrabKrustyTowers.Name = "TXT_KEY_DECISIONS_KRUSTYKRABKRUSTYTOWERS"
	Decisions_KrustyKrabKrustyTowers.Desc = "TXT_KEY_DECISIONS_KRUSTYKRABKRUSTYTOWERS_DESC"
	HookDecisionCivilizationIcon(Decisions_KrustyKrabKrustyTowers, "CIVILIZATION_KRUSTY_KRAB")
	Decisions_KrustyKrabKrustyTowers.CanFunc = (
	function(pPlayer)
		if pPlayer:GetCivilizationType() ~= civilizationID then return false, false end
		if load(player, "Decisions_KrustyKrabKrustyTowers") == true then
			Decisions_KrustyKrabKrustyTowers.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_KRUSTYKRABKRUSTYTOWERS_ENACTED_DESC")
			return false, false, true
		end

		local playerID = player:GetID()
		local goldCost = mathCeil(650*iMod)
		Decisions_KrustyKrabKrustyTowers.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_KRUSTYKRABKRUSTYTOWERS_DESC", goldCost)
		if pPlayer:GetCurrentEra() < eraModernlID then return true, false end
		if pPlayer:GetNumResourceAvailable(iMagistrate, false) < 2 then return true, false end
		if pPlayer:GetGold() < goldCost then return true, false end
		return true, true
	end
	)
	
	Decisions_KrustyKrabKrustyTowers.DoFunc = (
	function(pplayer)
		local goldCost = math.ceil(650*iMod)
		pPlayer:ChangeNumResourceTotal(iMagistrate, -2)
		pPlayer:ChangeGold(-goldCost)
		pPlayer:SetNumFreePolicies(1)
		pPlayer:SetNumFreePolicies(0)
		pPlayer:SetHasPolicy(policyKrustyTowers, true)
		save(pPlayer, "Decisions_KrustyKrabKrustyTowers", true)
	end
	)

		Decisions_AddCivilisationSpecific(GameInfoTypes.CIVILIZATION_KRUSTY_KRAB, "Decisions_KrustyKrabKrustyTowers", Decisions_KrustyKrabKrustyTowers)

Here's the SQL file too:

Code:
--==========================================================================================================================
-- Policies
--==========================================================================================================================
INSERT INTO Policies 
			(Type, 											Description) 
VALUES		('POLICY_DECISIONS_KRUSTYKRABTALENTSHOW',	 	'TXT_KEY_DECISIONS_KRUSTYKRABTALENTSHOW'),
			('POLICY_DECISIONS_KRUSTYKRABKRUSTYTOWERS',		'TXT_KEY_DECISIONS_KRUSTYKRABKRUSTYTOWERS');

--==========================================================================================================================
-- Policy_BuildingClassYieldModifiers
--==========================================================================================================================
INSERT INTO Policy_BuildingClassYieldModifiers 
			(PolicyType, 									BuildingClassType,					YieldType, 				YieldMod)
VALUES 		('POLICY_DECISIONS_KRUSTYKRABTALENTSHOW', 		'BUILDING_OPERA_HOUSE',				'YIELD_GOLD',			20);
--==========================================================================================================================
-- Policy_BuildingClassTourismModifiers
--==========================================================================================================================
INSERT INTO Policy_BuildingClassTourismModifiers
		(PolicyType, 										BuildingClassType,			TourismModifier)
VALUES	('POLICY_DECISIONS_KRUSTYKRABKRUSTYTOWERS', 		'BUILDING_KRUSTY_KRAB',		10);

Also, i'm not sure that the POLICY_DECISIONS_KRUSTYKRABTALENTSHOW is working- There's doesn't seem to be increase of Gold when it's active.

4.) Is it possible to have a decision where there's a temporary boost in Production for a few turns (Maybe around 20 to 30)?

5.) I'm making a Civ where their UA is their units are stronger if they have more policy trees completed than the enemy (Excluding City-States). Would there need to be a limit so it doesn't get too powerful? Also, their UU would generate Golden Age points when born.


6.) I'm also making another Civ where their UA is when a unit conquers a Capital or a City-State, they receive a special promotion, randomly chosen from a pool of special promotions. The unit is only supposed to the promotion once per city. That Civ also has an UB that replaces the Forge and gets extra production and doesn't need Iron when built in a conquered city.
 
#1 -- Nope, not without adjusting the number of units that can share a tile, and then code to monitor unit dying and to determine whether there's a unit of your special type occupying the same tile.

#3 --
Code:
--==========================================================================================================================
INSERT INTO Policy_BuildingClassYieldModifiers 
		(PolicyType,				BuildingClassType,		YieldType,		YieldMod)
VALUES 		('POLICY_DECISIONS_KRUSTYKRABTALENTSHOW',	'BUILDING_OPERA_HOUSE',		'YIELD_GOLD',		20);
--==========================================================================================================================
'BUILDING_OPERA_HOUSE' is not a Building-Class. Nor, for that matter, is 'BUILDING_KRUSTY_KRAB'. You need to specify the Building-Class in the two Policy_BuildingClassXYZ tables.

Haven't looked into the other stuff. May or may not get a chance to later today or sometime tomorrow.
 
#1 -- Nope, not without adjusting the number of units that can share a tile, and then code to monitor unit dying and to determine whether there's a unit of your special type occupying the same tile.

Speaking of that, I just found out that LastSword did something similar with his Napoleon mod, where pre-industrial siege units can be stacked with military units. Also, If unit stacked with Siege Unit is killed (in close-combat, not ranged one), the Siege unit will be destroyed just like a civilian.

Would it still be possible somehow?
 
Speaking of that, I just found out that LastSword did something similar with his Napoleon mod, where pre-industrial siege units can be stacked with military units. Also, If unit stacked with Siege Unit is killed (in close-combat, not ranged one), the Siege unit will be destroyed just like a civilian.

Would it still be possible somehow?
What LS is doing is a bit complex. He's defining a set of 'half-dummy' units that the game consders to be both siege units as well as civilian units, and swapping out the 'normal' version of a siege unit into one of these half-dummy units when necessary. Since these half-dummy units have no combat power for direct combat, they are insta-destroyed if an enemy successfully enters the tile they occupy.

This is why the special versions of the siege units cannot occupy the same tile as a true civilian, though -- the game believes them to be civilian units.

LS has a fair bit of lua code going on in that mod to handle part of this, and the rest is handled in the xml definitions of the special 'half-dummy' units.
 
What LS is doing is a bit complex. He's defining a set of 'half-dummy' units that the game consders to be both siege units as well as civilian units, and swapping out the 'normal' version of a siege unit into one of these half-dummy units when necessary. Since these half-dummy units have no combat power for direct combat, they are insta-destroyed if an enemy successfully enters the tile they occupy.

This is why the special versions of the siege units cannot occupy the same tile as a true civilian, though -- the game believes them to be civilian units.

LS has a fair bit of lua code going on in that mod to handle part of this, and the rest is handled in the xml definitions of the special 'half-dummy' units.

So, it looks like that's out of the picture, then.
One more question related to this: It is possible to have a Unit that generates Faith upon it's death?
 
Back
Top Bottom