You should be able to achieve the effect by using
as it's what the Firaxis scenarios use when setting up attacksCode:Players[63]:AddTemporaryDominanceZone (iX, iY)
thanks a lot ill try that
You should be able to achieve the effect by using
as it's what the Firaxis scenarios use when setting up attacksCode:Players[63]:AddTemporaryDominanceZone (iX, iY)
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)
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
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
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)
local [color="red"]DKCiv[/color] = GameInfoTypes.CIVILIZATION_DK_ISLES--Civ ID;
if Players[iPlayer]:GetCivilizationType() == [color="red"]LionCiv[/color] then
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
[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>
-- 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
-- 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
PlotVT[RandomPlot]:SetResourceType(GetResource(PlotVT[RandomPlot]), 1);
-- 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
------------------------------------------------------------
---- 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
can't specifiy a resource as "-1" for the SetResourceType method I don't think.
Yeah, the problem ended up being in the usage of Game.RandYou can (also SetFeatureType), it removes any resource/feature on the plot.
However, note that SetTerrainType(-1) will CTD!
Game.Rand(1, ResCount)
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.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>
local tValidResources = {[GameInfoTypes.RESOURCE_BANANA] = {NumberTilesWanted=2}}
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 aswhich 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".Code:Game.Rand(1, ResCount)
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 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.
- 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:
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.Code:local tValidResources = {[GameInfoTypes.RESOURCE_BANANA] = {NumberTilesWanted=2}}
- 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.
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
and instead have discovering Prosperity be the trigger to make the code happen, but I wasn't sure how to do that.eLastTech = ( iProsperity ))
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 '{
--[[
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
)
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: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:
tRealBuildingData[GameInfoTypes.BUILDING_TREEHOUSE] = { Counters= {{DummyBuilding=GameInfoTypes["BUILDING_TREEHOUSE_DUMMY"], ImprovementType=GameInfoTypes.IMPROVEMENT_PLANTATION, LimitPerCity=-1} } }
ApplyToAllInClass=true
{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
)
--[[
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} } }
--------------------------------------------------------------------------------------------------------------------------
-- 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)
--==========================================================================================================================
-- 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);
--==========================================================================================================================
INSERT INTO Policy_BuildingClassYieldModifiers
(PolicyType, BuildingClassType, YieldType, YieldMod)
VALUES ('POLICY_DECISIONS_KRUSTYKRABTALENTSHOW', 'BUILDING_OPERA_HOUSE', 'YIELD_GOLD', 20);
--==========================================================================================================================
#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.
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.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.