C++/Lua Request Thread

Replace
Code:
pCity:SetNumRealBuilding(iMonument, 1)
with
Code:
pCity:SetNumRealBuilding(pPlayer:GetSpecificBuildingType("BUILDINGCLASS_MONUMENT"), 1)

There's also no need to loop the player's cities - as the event was called, there must be a new city on the plot at (x,y), so you can just get the plot, get the city and use that directly
 
I'm trying to make a ranged, combat capable Great General replacement, that increases in both defensive melee strength and offensive ranged strength upon researching particular techs (specifically techs that unlock new archery and post-gunpowder siege units).

I tried adapting the code in Leugi's code from his Cuban civ, however, unlocking those techs does not do anything to the GG replacement. The code, as I understand it, is supposed to give the unit a new promotion that increases combat strength each time a specified tech is unlocked, however, those promotions are not being granted upon research.

Any ideas on how to get it working?

Mod DL link is here: https://www.dropbox.com/s/r5h6pam6s04rcjq/(BNW) DoktorAJ's Moon Kingdom - Sailor Moon (v 1).rar?dl=0
 
I think I might be able to code that, DoktorApplejuce.

It's going to be quite complicated with a simple idea, but it should work.
 
I think I might be able to code that, DoktorApplejuce.

It's going to be quite complicated with a simple idea, but it should work.

That would be hugely appreciated if you could. Thanks, Gpuzzle!
 
I'm trying to make a ranged, combat capable Great General replacement, that increases in both defensive melee strength and offensive ranged strength upon researching particular techs (specifically techs that unlock new archery and post-gunpowder siege units).

I tried adapting the code in Leugi's code from his Cuban civ, however, unlocking those techs does not do anything to the GG replacement. The code, as I understand it, is supposed to give the unit a new promotion that increases combat strength each time a specified tech is unlocked, however, those promotions are not being granted upon research.

Any ideas on how to get it working?

Mod DL link is here: https://www.dropbox.com/s/r5h6pam6s04rcjq/(BNW) DoktorAJ's Moon Kingdom - Sailor Moon (v 1).rar?dl=0

I adapted this code for RawSasquatch's Fallout civs. It uses Unit:SetBaseCombatStrength to adjust the combat strength. I don't find a comparable function for Ranged Combat Strength in the Lua and API Reference (but maybe it's "undocumented"). You may be able to accomplish the same thing using promotions (the code grants promotions, too - if I remember correctly, the promotions are mostly just markers and don't have any affect - but that could be changed).
 
  1. Basic Problem was a mismatch between what was in the XML for the ranged promotion names and what was in the lua you copy/paste-edited from Leugi
  2. I re-wrote to only fire the code when the units are created or the techs are researched. The playerDoTurn was not really necessary and would fire far too often.
  3. Also, you had this in multiple places in the Ranged Promotions:
    Code:
    <PediaEntry>TXT_KEY_PROMOTION_10PERCENT_RANGE</PediaEntry>
    which in testing I changed to match with the "Description" field for each promotion
  4. You may also encounter the problem where the great general spawning from combat XP gained ceases to work. If so, add this code to the SailorSenshiCombatUpgrades.lua file:
    Spoiler GG Issue Fix :
    Code:
    function FixSailorSenshiGG(PlayerID)
    	local pPlayer = Players[PlayerID]
    	if pPlayer:GetCivilizationType() == tSailorSenshiCombatInfos.Civilization then
    		if pPlayer:GetCombatExperience() >= pPlayer:GreatGeneralThreshold() then
    			local iCombatThreshold = pPlayer:GreatGeneralThreshold()
    			local pCapitalPlot = pCapitalCity:Plot()
    			pPlayer:CreateGreatGeneral(tSailorSenshiCombatInfos.UnitType, pCapitalPlot:GetX(), pCapitalPlot:GetY())
    			pPlayer:ChangeCombatExperience(iCombatThreshold * -1)
    		end
    	end
    end
    GameEvents.PlayerDoTurn.Add(FixSailorSenshiGG);
    Add it just above the print conformation line that everything loaded properly
  5. Also, since you already had Machiavelli's SerialEventUnitCreatedGood system as part of the mod, I changed the unit-created hook to use Machiavelli's system rather than the standard game event.

Spoiler New SailorSenshiCombatUpgrades.lua :
Code:
-------------------------------------------------------------------------------------------
--Lua-Table and Variable Assignments
-------------------------------------------------------------------------------------------
local tSailorSenshiCombatInfos = {}
tSailorSenshiCombatInfos.PreReqPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT
tSailorSenshiCombatInfos.UnitType = GameInfoTypes.UNIT_SAILORSENSHI
tSailorSenshiCombatInfos.UnitClassType = GameInfoTypes.UNITCLASS_GREAT_GENERAL
tSailorSenshiCombatInfos.BaseCombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_0
tSailorSenshiCombatInfos.BaseCombatPower = 6
tSailorSenshiCombatInfos.Civilization = GameInfoTypes.CIVILIZATION_SAILORMOON

local tSailorSenshiCombatTechsLevels = { [GameInfoTypes.TECH_CONSTRUCTION] = 1, [GameInfoTypes.TECH_MACHINERY] = 2, [GameInfoTypes.TECH_CHEMISTRY] = 3,
	[GameInfoTypes.TECH_DYNAMITE] = 4, [GameInfoTypes.TECH_ROCKETRY] = 5 }

local tSailorSenshiCombatInfoForTechs = {}
tSailorSenshiCombatInfoForTechs[1] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_1,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_1, CombatPower = 8 }
tSailorSenshiCombatInfoForTechs[2] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_2,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_2, CombatPower = 14 }
tSailorSenshiCombatInfoForTechs[3] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_3,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_3, CombatPower = 15 }
tSailorSenshiCombatInfoForTechs[4] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_4,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_4, CombatPower = 22 }
tSailorSenshiCombatInfoForTechs[5] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_5,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_5, CombatPower = 48 }

-------------------------------------------------------------------------------------------
--'Toolkit' Functions
-------------------------------------------------------------------------------------------

function SailorSenshiCombatPowers(pUnit, iTechLevel)
	if iTechLevel > 0 then
		pUnit:SetHasPromotion(tSailorSenshiCombatInfos.BaseCombatPromo, false)
		for k,v in pairs(tSailorSenshiCombatInfoForTechs) do
			if k ~= iTechLevel then
				pUnit:SetHasPromotion(v.RangedPromo, false)
				pUnit:SetHasPromotion(v.CombatPromo, false)
			else
				pUnit:SetHasPromotion(v.RangedPromo, true)
				pUnit:SetHasPromotion(v.CombatPromo, true)
				pUnit:SetBaseCombatStrength(v.CombatPower)
			end
		end
	end
end
function GetHighestTechLevel(pTeam)
	local iTechLevel = 0
	for k,v in pairs(tSailorSenshiCombatTechsLevels) do
		if pTeam:IsHasTech(k) and v > iTechLevel then
			iTechLevel = v
		end
	end
	return iTechLevel
end
-------------------------------------------------------------------------------------------
--'Hook' Functions
-------------------------------------------------------------------------------------------

function SailorSenshiCreated(PlayerID, UnitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState, selected, military, notInvisible)
	local pUnit = Players[PlayerID]:GetUnitByID(UnitID)
	if pUnit:IsHasPromotion(tSailorSenshiCombatInfos.PreReqPromo) then
		pUnit:SetHasPromotion(tSailorSenshiCombatInfos.BaseCombatPromo, true);
		pUnit:SetBaseCombatStrength(tSailorSenshiCombatInfos.BaseCombatPower)
		local pTeam = Teams[Players[PlayerID]:GetTeam()]
		SailorSenshiCombatPowers(pUnit, GetHighestTechLevel(pTeam))
	end
end
function SailorSenshiTechResearched(iTeam, iTech, iChange)
	if tSailorSenshiCombatTechsLevels[iTech] then
		local pTeam = Teams[iTeam]
		for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
			if (Players[iPlayer] ~= nil) then
				if (Players[iPlayer]:GetTeam() == iTeam) then
					local pPlayer = Players[iPlayer]
					if pPlayer:GetUnitClassCount(tSailorSenshiCombatInfos.UnitClassType) > 0 then
						for pUnit in pPlayer:Units() do
							if pUnit:IsHasPromotion(tSailorSenshiCombatInfos.PreReqPromo) then
								SailorSenshiCombatPowers(pUnit, tSailorSenshiCombatTechsLevels[iTech])
							end
						end
					end
				end
			end
 		end
	end
end
GameEvents.TeamTechResearched.Add(SailorSenshiTechResearched)
LuaEvents.SerialEventUnitCreatedGood.Add(SailorSenshiCreated);

-------------------------------------------------------------------------------
--should not really need the following, so it is disabled
-------------------------------------------------------------------------------

function SailorSenshi(PlayerID)
	local pPlayer = Players[PlayerID]
	if pPlayer:GetUnitClassCount(tSailorSenshiCombatInfos.UnitClassType) > 0 then
		local iTechLevel = GetHighestTechLevel(Teams[pPlayer:GetTeam()])
		for pUnit in pPlayer:Units() do
			if pUnit:IsHasPromotion(tSailorSenshiCombatInfos.PreReqPromo) then
				SailorSenshiCombatPowers(pUnit, iTechLevel)
			end
		end
	end
end
--GameEvents.PlayerDoTurn.Add(SailorSenshi);

print("The Sailor Senshi Combat Lua loaded succesfully")

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

[edit]The melee combat promotions aren't actually doing anything. It is the pUnit:SetBaseCombatStrength(v.CombatPower) line which is actually adjusting the unit's basic melee defense combat power.
 
  1. Basic Problem was a mismatch between what was in the XML for the ranged promotion names and what was in the lua you copy/paste-edited from Leugi
  2. I re-wrote to only fire the code when the units are created or the techs are researched. The playerDoTurn was not really necessary and would fire far too often.
  3. Also, you had this in multiple places in the Ranged Promotions:
    Code:
    <PediaEntry>TXT_KEY_PROMOTION_10PERCENT_RANGE</PediaEntry>
    which in testing I changed to match with the "Description" field for each promotion
  4. You may also encounter the problem where the great general spawning from combat XP gained ceases to work. If so, add this code to the SailorSenshiCombatUpgrades.lua file:
    Spoiler GG Issue Fix :
    Code:
    function FixSailorSenshiGG(PlayerID)
    	local pPlayer = Players[PlayerID]
    	if pPlayer:GetCivilizationType() == tSailorSenshiCombatInfos.Civilization then
    		if pPlayer:GetCombatExperience() >= pPlayer:GreatGeneralThreshold() then
    			local iCombatThreshold = pPlayer:GreatGeneralThreshold()
    			local pCapitalPlot = pCapitalCity:Plot()
    			pPlayer:CreateGreatGeneral(tSailorSenshiCombatInfos.UnitType, pCapitalPlot:GetX(), pCapitalPlot:GetY())
    			pPlayer:ChangeCombatExperience(iCombatThreshold * -1)
    		end
    	end
    end
    GameEvents.PlayerDoTurn.Add(FixSailorSenshiGG);
    Add it just above the print conformation line that everything loaded properly
  5. Also, since you already had Machiavelli's SerialEventUnitCreatedGood system as part of the mod, I changed the unit-created hook to use Machiavelli's system rather than the standard game event.

Spoiler New SailorSenshiCombatUpgrades.lua :
Code:
-------------------------------------------------------------------------------------------
--Lua-Table and Variable Assignments
-------------------------------------------------------------------------------------------
local tSailorSenshiCombatInfos = {}
tSailorSenshiCombatInfos.PreReqPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT
tSailorSenshiCombatInfos.UnitType = GameInfoTypes.UNIT_SAILORSENSHI
tSailorSenshiCombatInfos.UnitClassType = GameInfoTypes.UNITCLASS_GREAT_GENERAL
tSailorSenshiCombatInfos.BaseCombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_0
tSailorSenshiCombatInfos.BaseCombatPower = 6

local tSailorSenshiCombatTechsLevels = { [GameInfoTypes.TECH_CONSTRUCTION] = 1, [GameInfoTypes.TECH_MACHINERY] = 2, [GameInfoTypes.TECH_CHEMISTRY] = 3,
	[GameInfoTypes.TECH_DYNAMITE] = 4, [GameInfoTypes.TECH_ROCKETRY] = 5 }

local tSailorSenshiCombatInfoForTechs = {}
tSailorSenshiCombatInfoForTechs[1] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_1,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_1, CombatPower = 8 }
tSailorSenshiCombatInfoForTechs[2] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_2,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_2, CombatPower = 14 }
tSailorSenshiCombatInfoForTechs[3] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_3,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_3, CombatPower = 15 }
tSailorSenshiCombatInfoForTechs[4] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_4,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_4, CombatPower = 22 }
tSailorSenshiCombatInfoForTechs[5] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_5,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_5, CombatPower = 48 }

-------------------------------------------------------------------------------------------
--'Toolkit' Functions
-------------------------------------------------------------------------------------------

function SailorSenshiCombatPowers(pUnit, iTechLevel)
	if iTechLevel > 0 then
		pUnit:SetHasPromotion(tSailorSenshiCombatInfos.BaseCombatPromo, false)
		for k,v in pairs(tSailorSenshiCombatInfoForTechs) do
			if k ~= iTechLevel then
				pUnit:SetHasPromotion(v.RangedPromo, false)
				pUnit:SetHasPromotion(v.CombatPromo, false)
			else
				pUnit:SetHasPromotion(v.RangedPromo, true)
				pUnit:SetHasPromotion(v.CombatPromo, true)
				pUnit:SetBaseCombatStrength(v.CombatPower)
			end
		end
	end
end
function GetHighestTechLevel(pTeam)
	local iTechLevel = 0
	for k,v in pairs(tSailorSenshiCombatTechsLevels) do
		if pTeam:IsHasTech(k) and v > iTechLevel then
			iTechLevel = v
		end
	end
	return iTechLevel
end
-------------------------------------------------------------------------------------------
--'Hook' Functions
-------------------------------------------------------------------------------------------

function SailorSenshiCreated(PlayerID, UnitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState, selected, military, notInvisible)
	local pUnit = Players[PlayerID]:GetUnitByID(UnitID)
	if pUnit:IsHasPromotion(tSailorSenshiCombatInfos.PreReqPromo) then
		pUnit:SetHasPromotion(tSailorSenshiCombatInfos.BaseCombatPromo, true);
		pUnit:SetBaseCombatStrength(tSailorSenshiCombatInfos.BaseCombatPower)
		local pTeam = Teams[Players[PlayerID]:GetTeam()]
		SailorSenshiCombatPowers(pUnit, GetHighestTechLevel(pTeam))
	end
end
function SailorSenshiTechResearched(iTeam, iTech, iChange)
	if tSailorSenshiCombatTechsLevels[iTech] then
		local pTeam = Teams[iTeam]
		for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
			if (Players[iPlayer] ~= nil) then
				if (Players[iPlayer]:GetTeam() == iTeam) then
					local pPlayer = Players[iPlayer]
					if pPlayer:GetUnitClassCount(tSailorSenshiCombatInfos.UnitClassType) > 0 then
						for pUnit in pPlayer:Units() do
							if pUnit:IsHasPromotion(tSailorSenshiCombatInfos.PreReqPromo) then
								SailorSenshiCombatPowers(pUnit, tSailorSenshiCombatTechsLevels[iTech])
							end
						end
					end
				end
			end
 		end
	end
end
GameEvents.TeamTechResearched.Add(SailorSenshiTechResearched)
LuaEvents.SerialEventUnitCreatedGood.Add(SailorSenshiCreated);

-------------------------------------------------------------------------------
--should not really need the following, so it is disabled
-------------------------------------------------------------------------------

function SailorSenshi(PlayerID)
	local pPlayer = Players[PlayerID]
	if pPlayer:GetUnitClassCount(tSailorSenshiCombatInfos.UnitClassType) > 0 then
		local iTechLevel = GetHighestTechLevel(Teams[pPlayer:GetTeam()])
		for pUnit in pPlayer:Units() do
			if pUnit:IsHasPromotion(tSailorSenshiCombatInfos.PreReqPromo) then
				SailorSenshiCombatPowers(pUnit, iTechLevel)
			end
		end
	end
end
--GameEvents.PlayerDoTurn.Add(SailorSenshi);

print("The Sailor Senshi Combat Lua loaded succesfully")

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

[edit]The melee combat promotions aren't actually doing anything. It is the pUnit:SetBaseCombatStrength(v.CombatPower) line which is actually adjusting the unit's basic melee defense combat power.

One of these days, I'll be able to do some sort of Lua editing on my own without messing things up.

But, as this is not that day; thank you so much for this, LeeS! A couple of tests show it works beautifully.

BTW; I've recently learned that having a Great General replacement without the PROMOTION_GREAT_GENERAL promotion apparently can not be spawned in through warfare. If that is true, and I wanted a great general replacement for another civ that didn't actually have that promotion, would including this code:
Spoiler GG Issue Fix :
Code:
function FixSailorSenshiGG(PlayerID)
	local pPlayer = Players[PlayerID]
	if pPlayer:GetCivilizationType() == tSailorSenshiCombatInfos.Civilization then
		if pPlayer:GetCombatExperience() >= pPlayer:GreatGeneralThreshold() then
			local iCombatThreshold = pPlayer:GreatGeneralThreshold()
			local pCapitalPlot = pCapitalCity:Plot()
			pPlayer:CreateGreatGeneral(tSailorSenshiCombatInfos.UnitType, pCapitalPlot:GetX(), pCapitalPlot:GetY())
			pPlayer:ChangeCombatExperience(iCombatThreshold * -1)
		end
	end
end
GameEvents.PlayerDoTurn.Add(FixSailorSenshiGG);
fix that?
 
Yup. You just need to change this: tSailorSenshiCombatInfos.UnitType to the correct ID# designation for the unit you need to be treated as a Great General. So you would replace that with GameInfoTypes.UNIT_WHATEVER_IT_IS

[edit] and also you would need to change tSailorSenshiCombatInfos.Civilization so that it looks at the correct civilization ID#, so you would replace that with GameInfoTypes.CIVILIZATION_WHATEVER_IT_IS.

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

PS to Peeps in general looking at post # 387:

I also re-wrote that code to make it more-easily adaptable to adding or removing Techs from the list that would give those sorts of effects. So if you wanted to add TECH_ADVANCED_BALLISTICS to the list of techs, for example, the changes such as here as highlighted in blue are all that are required within the lua script (everything else remains the same):
Spoiler :
Code:
local tSailorSenshiCombatTechsLevels = { [GameInfoTypes.TECH_CONSTRUCTION] = 1, [GameInfoTypes.TECH_MACHINERY] = 2, [GameInfoTypes.TECH_CHEMISTRY] = 3,
	[GameInfoTypes.TECH_DYNAMITE] = 4, [GameInfoTypes.TECH_ROCKETRY] = 5[color="blue"], [GameInfoTypes.TECH_ADVANCED_BALLISTICS] = 6[/color] }

local tSailorSenshiCombatInfoForTechs = {}
tSailorSenshiCombatInfoForTechs[1] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_1,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_1, CombatPower = 8 }
tSailorSenshiCombatInfoForTechs[2] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_2,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_2, CombatPower = 14 }
tSailorSenshiCombatInfoForTechs[3] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_3,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_3, CombatPower = 15 }
tSailorSenshiCombatInfoForTechs[4] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_4,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_4, CombatPower = 22 }
tSailorSenshiCombatInfoForTechs[5] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_5,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_5, CombatPower = 48 }
[color="blue"]tSailorSenshiCombatInfoForTechs[6] = { RangedPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_RANGED_COMBAT_6,
	CombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_6, CombatPower = 65 }[/color]
If you want to change the unit type, civilization, etc., to use a similar system for one of your units, you also would need to edit this portion
Code:
local tSailorSenshiCombatInfos = {}
tSailorSenshiCombatInfos.PreReqPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT
tSailorSenshiCombatInfos.UnitType = GameInfoTypes.UNIT_SAILORSENSHI
tSailorSenshiCombatInfos.UnitClassType = GameInfoTypes.UNITCLASS_GREAT_GENERAL
tSailorSenshiCombatInfos.BaseCombatPromo = GameInfoTypes.PROMOTION_SAILOR_SENSHI_COMBAT_0
tSailorSenshiCombatInfos.BaseCombatPower = 6
tSailorSenshiCombatInfos.Civilization = GameInfoTypes.CIVILIZATION_SAILORMOON
for the correct unit, civ, etc. And you would have to edit the tech and promotion names.
 
One of these days, I'll be able to do some sort of Lua editing on my own without messing things up.

But, as this is not that day; thank you so much for this, LeeS! A couple of tests show it works beautifully.

BTW; I've recently learned that having a Great General replacement without the PROMOTION_GREAT_GENERAL promotion apparently can not be spawned in through warfare. If that is true, and I wanted a great general replacement for another civ that didn't actually have that promotion, would including this code:
Spoiler GG Issue Fix :
Code:
function FixSailorSenshiGG(PlayerID)
	local pPlayer = Players[PlayerID]
	if pPlayer:GetCivilizationType() == tSailorSenshiCombatInfos.Civilization then
		if pPlayer:GetCombatExperience() >= pPlayer:GreatGeneralThreshold() then
			local iCombatThreshold = pPlayer:GreatGeneralThreshold()
			local pCapitalPlot = pCapitalCity:Plot()
			pPlayer:CreateGreatGeneral(tSailorSenshiCombatInfos.UnitType, pCapitalPlot:GetX(), pCapitalPlot:GetY())
			pPlayer:ChangeCombatExperience(iCombatThreshold * -1)
		end
	end
end
GameEvents.PlayerDoTurn.Add(FixSailorSenshiGG);
fix that?

Change your code so that it reads as this in the appropriate section:
Code:
tSailorSenshiCombatInfos.BaseCombatPower = 6
tSailorSenshiCombatInfos.Civilization = GameInfoTypes.CIVILIZATION_SAILORMOON
I had that extra line in the code I used to test the script, but I somehow deleted that line when I pasted the code to the forum in post #387. The missing line would only affect you if you added the GG-spawning fixer for the Sailor Senshi unit. It would not have a bad effect on the rest of the code.

I also added the missing line to the code in Post #387 so you can better see where it ought to go.
 
Alright, awesome! That part works now!

However, I've run into another issue. The same Great General replacement is supposed to have an ability where units affected by its leadership are granted a promotion that allow them to capture barbarians. Up until recently, it was working.

It was done through Lua that (as I understand it) granted the barbarian capture promotion to units within two tiles of a unit with the Great General promotion. The only issue was that other civs were getting this same ability with their Great Generals. So, I replaced the Great General promotion dependency in the Lua with a dummy promotion that I gave to the GG replacement in question. Now, nearby units aren't receiving the barbarian capture promotion.

Any ideas on how to rectify this?
https://www.dropbox.com/s/r5h6pam6s04rcjq/(BNW) DoktorAJ's Moon Kingdom - Sailor Moon (v 1).rar?dl=0
 
Replace the old version of the UnitsNearSailorSenshi function with this code:
Spoiler :
Code:
function PlotUnitHandling(pPlot, playerID, iRequiredDomain, iExcludeUnit, iPromotionType)
	for i = 0, pPlot:GetNumUnits() do
		local pPlotUnit = pPlot:GetUnit(i)
		if pPlotUnit then
			if pPlotUnit:GetOwner() == playerID then
				if pPlotUnit:IsCombatUnit() and (pPlotUnit:GetDomainType() == iRequiredDomain) and (pPlotUnit:GetUnitType() ~= iExcludeUnit) then
					pPlotUnit:SetHasPromotion(iPromotionType, true)
				end
			end
		end
	end
end

function UnitsNearSailorSenshi(playerID, unitID, unitX, unitY)
	if Players[playerID]:GetCivilizationType() == civilisationID then
		local player = Players[playerID]
		local pUnit = player:GetUnitByID(unitID)
		if pUnit:GetUnitType() == unitSailorSenshiID then
			local pUnitPlot = pUnit:GetPlot()
			if pUnitPlot:GetNumUnits() > 1 then
				PlotUnitHandling(pUnitPlot, playerID, iDomainLand, unitSailorSenshiID, unitPromotionSailorSenshiCaptureBarbID)
			end
			for direction = 0, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
				local pAdjacentPlot = Map.PlotDirection(pUnitPlot:GetX(), pUnitPlot:GetY(), direction)
				if pAdjacentPlot and pAdjacentPlot:IsUnit() then
					PlotUnitHandling(pAdjacentPlot, playerID, iDomainLand, unitSailorSenshiID, unitPromotionSailorSenshiCaptureBarbID)
				end
			end
			for pEdgePlot in PlotRingIterator(pUnitPlot, 2, SECTOR_NORTH, DIRECTION_CLOCKWISE) do
				if pEdgePlot and pEdgePlot:IsUnit() then
					PlotUnitHandling(pEdgePlot, playerID, iDomainLand, unitSailorSenshiID, unitPromotionSailorSenshiCaptureBarbID)
				end
			end
		elseif pUnit:IsCombatUnit() and (pUnit:GetDomainType() == iDomainLand) then
			pUnit:SetHasPromotion(unitPromotionSailorSenshiCaptureBarbID, pUnit:IsNearGreatGeneral())
		end
	end
end
GameEvents.UnitSetXY.Add(UnitsNearSailorSenshi)
There will be a difference in the way the newer code works in that when the Sailor Senshi unit moves out of range of a land combat unit, that combat unit will retain the capturing promotion until the combat unit makes its next move. Then the code will correct for whether the land combat unit still qualifies for having the promotion.

The problem with scanning through all units every time a Sailor Senshi or a combat unit moves is that in the late game and on larger maps this will likely start creating perceptible lagginess for the player. The code as re-written is an attempt to split the difference between performance in terms of processing overhead and 100% 'perfect' reaction to changing conditions.
 
Replace the old version of the UnitsNearSailorSenshi function with this code:
Spoiler :
Code:
function PlotUnitHandling(pPlot, playerID, iRequiredDomain, iExcludeUnit, iPromotionType)
	for i = 0, pPlot:GetNumUnits() do
		local pPlotUnit = pPlot:GetUnit(i)
		if pPlotUnit then
			if pPlotUnit:GetOwner() == playerID then
				if pPlotUnit:IsCombatUnit() and (pPlotUnit:GetDomainType() == iRequiredDomain) and (pPlotUnit:GetUnitType() ~= iExcludeUnit) then
					pPlotUnit:SetHasPromotion(iPromotionType, true)
				end
			end
		end
	end
end

function UnitsNearSailorSenshi(playerID, unitID, unitX, unitY)
	if Players[playerID]:GetCivilizationType() == civilisationID then
		local player = Players[playerID]
		local pUnit = player:GetUnitByID(unitID)
		if pUnit:GetUnitType() == unitSailorSenshiID then
			local pUnitPlot = pUnit:GetPlot()
			if pUnitPlot:GetNumUnits() > 1 then
				PlotUnitHandling(pUnitPlot, playerID, iDomainLand, unitSailorSenshiID, unitPromotionSailorSenshiCaptureBarbID)
			end
			for direction = 0, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
				local pAdjacentPlot = Map.PlotDirection(pUnitPlot:GetX(), pUnitPlot:GetY(), direction)
				if pAdjacentPlot and pAdjacentPlot:IsUnit() then
					PlotUnitHandling(pAdjacentPlot, playerID, iDomainLand, unitSailorSenshiID, unitPromotionSailorSenshiCaptureBarbID)
				end
			end
			for pEdgePlot in PlotRingIterator(pUnitPlot, 2, SECTOR_NORTH, DIRECTION_CLOCKWISE) do
				if pEdgePlot and pEdgePlot:IsUnit() then
					PlotUnitHandling(pEdgePlot, playerID, iDomainLand, unitSailorSenshiID, unitPromotionSailorSenshiCaptureBarbID)
				end
			end
		elseif pUnit:IsCombatUnit() and (pUnit:GetDomainType() == iDomainLand) then
			pUnit:SetHasPromotion(unitPromotionSailorSenshiCaptureBarbID, pUnit:IsNearGreatGeneral())
		end
	end
end
GameEvents.UnitSetXY.Add(UnitsNearSailorSenshi)
There will be a difference in the way the newer code works in that when the Sailor Senshi unit moves out of range of a land combat unit, that combat unit will retain the capturing promotion until the combat unit makes its next move. Then the code will correct for whether the land combat unit still qualifies for having the promotion.

The problem with scanning through all units every time a Sailor Senshi or a combat unit moves is that in the late game and on larger maps this will likely start creating perceptible lagginess for the player. The code as re-written is an attempt to split the difference between performance in terms of processing overhead and 100% 'perfect' reaction to changing conditions.

Oh, awesome, thanks again, LeeS! Now with this, all the coding is complete for this mod. All that's left is the written stuff.
 
I'd like to request some code for a civ trait.

Cities yield 1 additional tourism when advancing to a new era.

Here you go, you're going to need to create 7 dummy buildings that will yield one tourism and of course necessary adjustments to the code below.

Code:
function OnNextyTurn (iPlayer)
   local pplayer = Players[iPlayer]
   local civUA = GameInfoTypes.CIVILIZATION_WHATEVERITIS
	if (pplayer:GetCivilizationType() == civUA) then 
		for pCity in pplayer:Cities() do
			if (pPlayer:GetCurrentEra() == 1) then
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_CLASSICAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MEDIEVAL_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_RENAISSANCE_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_INDUSTRIAL_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MODERN_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FUTURE_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_POSTMODERN_TOURISM"], 0)
			end
			if (pPlayer:GetCurrentEra() == 2) then
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_CLASSICAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MEDIEVAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_RENAISSANCE_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_INDUSTRIAL_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MODERN_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FUTURE_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_POSTMODERN_TOURISM"], 0)
			end
			if (pPlayer:GetCurrentEra() == 3) then
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_CLASSICAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MEDIEVAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_RENAISSANCE_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_INDUSTRIAL_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MODERN_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FUTURE_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_POSTMODERN_TOURISM"], 0)
			end
			if (pPlayer:GetCurrentEra() == 4) then
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_CLASSICAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MEDIEVAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_RENAISSANCE_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_INDUSTRIAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MODERN_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FUTURE_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_POSTMODERN_TOURISM"], 0)
			end
			if (pPlayer:GetCurrentEra() == 5) then
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_CLASSICAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MEDIEVAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_RENAISSANCE_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_INDUSTRIAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MODERN_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FUTURE_TOURISM"], 0)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_POSTMODERN_TOURISM"], 0)
			end
			if (pPlayer:GetCurrentEra() == 6) then
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_CLASSICAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MEDIEVAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_RENAISSANCE_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_INDUSTRIAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MODERN_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FUTURE_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_POSTMODERN_TOURISM"], 0)
			end
			if (pPlayer:GetCurrentEra() == 7) then
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_CLASSICAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MEDIEVAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_RENAISSANCE_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_INDUSTRIAL_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MODERN_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FUTURE_TOURISM"], 1)
				pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_POSTMODERN_TOURISM"], 1)
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(OnNextyTurn)
 
I have a few issues with some code I'm trying to get to work.

1.
Spoiler :
I'm trying to write a function that checks for the highest of any yields of a plot, but I'm getting an error, so I've messed something up obviously.
Here's the code:
Code:
local tYieldTypes = {YieldTypes.YIELD_FOOD, YieldTypes.YIELD_PRODUCTION, YieldTypes.YIELD_GOLD, YieldTypes.YIELD_SCIENCE, YieldTypes.YIELD_CULTURE, YieldTypes.YIELD_FAITH}

function DMS_GetTileHighestYield(plot)
	local iTileHighestYield = 0
	for _, yieldType in pairs(tYieldTypes) do
		if plot:GetYield(yieldType) and plot:GetYield(yieldType) > iTileHighestYield then
			iTileHighestYield = plot:GetYield(yieldType)
		end
	end

	return iTileHighestYield
end
.. And here's the error message I'm receiving:
Code:
bad argument #1 to 'pairs' (table expected, got nil)
2.
Spoiler :
For another unrelated function I'm trying to iterate through units on a plot to determine if there's a worker unit stacked with another unit.
Code:
local civilisationSennarID								= GameInfoTypes["CIVILIZATION_DMS_SENNAR"]
local unitAbdallabID									= GameInfoTypes["UNIT_DMS_ABDALLAB"]
local unitClassWorkerID									= GameInfoTypes["UNITCLASS_WORKER"]

function DMS_SennarAbdallabCaptureWorker(playerID, unitID, unitX, unitY)
   local pPlayer = Players[playerID]
   if pPlayer and pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == civilisationSennarID then
       local pUnit = pPlayer:GetUnitByID(unitID)
		if pUnit and pUnit:GetUnitType() == unitAbdallabID then
           print("DMS_SennarAbdallabCaptureWorker initializing for unitAbdallabID on plot (" .. unitX .. "," .. unitY .. ")..")
           local pPlot = Map:GetPlot(unitX, unitY);
           local numUnits = pPlot:GetNumUnits()
           for i = 0, numUnits do
                print("DMS_SennarAbdallabCaptureWorker: iterate through units on plot..")
                local pCapturedUnit = pPlot:GetUnit(i);
                if pCapturedUnit ~= nil then
                    print("DMS_SennarAbdallabCaptureWorker: pCapturedUnit ~= nil..")
                    if (pCapturedUnit:GetUnitClassType() == unitClassWorkerID) and (pCapturedUnit:GetOriginalOwner() ~= playerID) then
                        -- do stuff
                        
                    end
                else
                    print("DMS_SennarAbdallabCaptureWorker: pCapturedUnit is nil..")
                end
            end
        end
    end
end

if isSennarCivActive then
	GameEvents.UnitSetXY.Add(DMS_SennarAbdallabCaptureWorker)
end
But when testing the code, it doesn't seem to detect when the Abdallab unit is stacked with a worker unit.
 
I have a few issues with some code I'm trying to get to work.

1.
Spoiler :
I'm trying to write a function that checks for the highest of any yields of a plot, but I'm getting an error, so I've messed something up obviously.
Here's the code:
Code:
local tYieldTypes = {YieldTypes.YIELD_FOOD, YieldTypes.YIELD_PRODUCTION, YieldTypes.YIELD_GOLD, YieldTypes.YIELD_SCIENCE, YieldTypes.YIELD_CULTURE, YieldTypes.YIELD_FAITH}

function DMS_GetTileHighestYield(plot)
	local iTileHighestYield = 0
	for _, yieldType in pairs(tYieldTypes) do
		if plot:GetYield(yieldType) and plot:GetYield(yieldType) > iTileHighestYield then
			iTileHighestYield = plot:GetYield(yieldType)
		end
	end

	return iTileHighestYield
end
.. And here's the error message I'm receiving:
Code:
bad argument #1 to 'pairs' (table expected, got nil)
2.
Spoiler :
For another unrelated function I'm trying to iterate through units on a plot to determine if there's a worker unit stacked with another unit.
Code:
local civilisationSennarID								= GameInfoTypes["CIVILIZATION_DMS_SENNAR"]
local unitAbdallabID									= GameInfoTypes["UNIT_DMS_ABDALLAB"]
local unitClassWorkerID									= GameInfoTypes["UNITCLASS_WORKER"]

function DMS_SennarAbdallabCaptureWorker(playerID, unitID, unitX, unitY)
   local pPlayer = Players[playerID]
   if pPlayer and pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == civilisationSennarID then
       local pUnit = pPlayer:GetUnitByID(unitID)
		if pUnit and pUnit:GetUnitType() == unitAbdallabID then
           print("DMS_SennarAbdallabCaptureWorker initializing for unitAbdallabID on plot (" .. unitX .. "," .. unitY .. ")..")
           local pPlot = Map:GetPlot(unitX, unitY);
           local numUnits = pPlot:GetNumUnits()
           for i = 0, numUnits do
                print("DMS_SennarAbdallabCaptureWorker: iterate through units on plot..")
                local pCapturedUnit = pPlot:GetUnit(i);
                if pCapturedUnit ~= nil then
                    print("DMS_SennarAbdallabCaptureWorker: pCapturedUnit ~= nil..")
                    if (pCapturedUnit:GetUnitClassType() == unitClassWorkerID) and (pCapturedUnit:GetOriginalOwner() ~= playerID) then
                        -- do stuff
                        
                    end
                else
                    print("DMS_SennarAbdallabCaptureWorker: pCapturedUnit is nil..")
                end
            end
        end
    end
end

if isSennarCivActive then
	GameEvents.UnitSetXY.Add(DMS_SennarAbdallabCaptureWorker)
end
But when testing the code, it doesn't seem to detect when the Abdallab unit is stacked with a worker unit.

For #2, where is this defined?
Code:
if [COLOR="Red"]isSennarCivActive[/COLOR] then
	GameEvents.UnitSetXY.Add(DMS_SennarAbdallabCaptureWorker)
end
Still scratching my head on #1. Nothing obvious as yet. I'll add an edit to this post of the lightbuilb goes off -- but it would be better to see the whole code within the same file -- it looks like you have a localization issue.
 
For #2, where is this defined?
Code:
if [COLOR="Red"]isSennarCivActive[/COLOR] then
GameEvents.UnitSetXY.Add(DMS_SennarAbdallabCaptureWorker)
end
Still scratching my head on #1. Nothing obvious as yet. I'll add an edit to this post of the lightbuilb goes off

Thanks Less. It's defined at the top of the file along with the other variables - simply forgot to copy that one over. But it's there. The function does fire, but when iterating through units on the plot, it doesn't detect any.

Edit (to answer LeeS own edit):
Fair enough, I'll post the whole thing when I get back to my desktop. Thanks.
 
Problem #1:Simple change here solved the problem:
Code:
function DMS_GetTileHighestYield(plot)
	local iTileHighestYield = 0
	for [color="blue"]k[/color], yieldType in pairs(tYieldTypes) do
		if plot:GetYield(yieldType) and plot:GetYield(yieldType) > iTileHighestYield then
			iTileHighestYield = plot:GetYield(yieldType)
		end
	end

	return iTileHighestYield
end
I generally don't use the "_" method with "pairs(tablename)" so it wasn't obvious this was not being liked by the game.

Problem #2:This code solved the issue:
Spoiler :
Note that besides making the changes to look at Russia and Musketman so I could test the code on my end, I made a few changes within the code in addition to adding copious print statements for trouble-shooting purposes.
Code:
local civilisationSennarID = GameInfoTypes["CIVILIZATION_RUSSIA"]
local unitAbdallabID = GameInfoTypes["UNIT_MUSKETMAN"]
local unitClassWorkerID = GameInfoTypes["UNITCLASS_WORKER"]

function DMS_SennarAbdallabCaptureWorker(playerID, unitID, unitX, unitY)
	local pPlayer = Players[playerID]
	if pPlayer and pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == civilisationSennarID then
		local pUnit = pPlayer:GetUnitByID(unitID)
		if pUnit and pUnit:GetUnitType() == unitAbdallabID then
			print("DMS_SennarAbdallabCaptureWorker initializing for unitAbdallabID on plot (" .. unitX .. "," .. unitY .. ")..")
			local pPlot = pUnit:GetPlot()
			local numUnits = pPlot:GetNumUnits()
			for i = 0, numUnits do
				print("DMS_SennarAbdallabCaptureWorker: iterate through units on plot..")
				local pCapturedUnit = pPlot:GetUnit(i)
				if pCapturedUnit then
					print("DMS_SennarAbdallabCaptureWorker: pCapturedUnit ~= nil..")
					print("Unit on the plot is " .. GameInfo.Units[pCapturedUnit:GetUnitType()].Type)
					if (pCapturedUnit:GetUnitClassType() == unitClassWorkerID) and (pCapturedUnit:GetOriginalOwner() ~= playerID) then
						print("Unit was considered to be a captured worker")
					else
						print("Unit was not considered to be a captured worker")
					end
				else
					print("DMS_SennarAbdallabCaptureWorker: pCapturedUnit is nil..")
				end
			end
		end
	end
end

--if isSennarCivActive then
	GameEvents.UnitSetXY.Add(DMS_SennarAbdallabCaptureWorker)
--end
and gave me this in the logs when I made a Musketman belonging to Catherine capture one of William's Workers*:
Spoiler :
Code:
[985949.406] Lua Script1: DMS_SennarAbdallabCaptureWorker initializing for unitAbdallabID on plot (16,46)..
[985949.421] Lua Script1: DMS_SennarAbdallabCaptureWorker: iterate through units on plot..
[985949.421] Lua Script1: DMS_SennarAbdallabCaptureWorker: pCapturedUnit ~= nil..
[985949.421] Lua Script1: Unit on the plot is UNIT_MUSKETMAN
[985949.421] Lua Script1: Unit was not considered to be a captured worker
[985949.421] Lua Script1: DMS_SennarAbdallabCaptureWorker: iterate through units on plot..
[985949.421] Lua Script1: DMS_SennarAbdallabCaptureWorker: pCapturedUnit ~= nil..
[985949.421] Lua Script1: Unit on the plot is UNIT_WORKER
[985949.437] Lua Script1: Unit was considered to be a captured worker
[985949.437] Lua Script1: DMS_SennarAbdallabCaptureWorker: iterate through units on plot..
[985949.437] Lua Script1: DMS_SennarAbdallabCaptureWorker: pCapturedUnit is nil..
Obviously lots of extra print-statements you won't want in final code.

If look close you can see you are getting an extra set of print-outs. There are actually seen by lua to be three (3) units sharing the tile and not (2) via Plot:GetNumUnits(): this is normal when not subtracting "1" from "numUnits" on the "for i = 0, numUnits do" line because of the numerical de-synch between Plot:GetNumUnits() and pPlot:GetUnit(i) with "i" starting at "0" in the loop. But you really can't start the loop at "i = 1" because this would chop-off the 1st unit seen to be on the plot (ie, in this case: the Musketman).



Spoiler * :
it felt nice to declare war on William and capture a low-hanging worker from him in the test-game I'm currently running because forward-settle-spam. Even if I did exit before saving anything.
 
Hi all great and powerful coders,

I was hoping to request some code for the Tehuelche.

I would need the following elements:

The UA adds Tourism to Happiness before Circumnavigation. After Circumnavigation, Tourism adds to Science.

The UU needs a promotion (Bolas) that reduces movement of adjacent enemy units by 1.

The UI (Kan) Produces extra food if a Tehuelche unit is on top of it, and Tehuelche units heal faster if they're on a Kan.

Thanks!

We already have the UU and UI models, so once we have the code we can put it all together and get it released.
 
Back
Top Bottom