Events and Decisions LUA help required - LUA not seeming to work

Rob (R8XFT)

Ancient Briton
Retired Moderator
Joined
Aug 11, 2002
Messages
10,866
Location
Leeds (UK)
I need some help with a decision LUA that doesn't seem to recognise that the conditions have been met. I'm not sure at all what the problem is. In a nutshell, a policy (POLICY_FLEECE) should be enacted when the following conditions are met
  • The civilization is Colchis
  • Epic Journeys has been discovered
  • Colchis has fought at least one war
  • There's a magistrate and some gold available to pay for it
As mentioned above, even with the prerequisites having been met, the decision shows as still unavailable and I'm unsure why. Could anyone please point me in the right direction? I'm not proficient in LUA and have adapted a similar decision from elsewhere.
Code:
--------------------------------------------------------------------------------------------------------------------------
-- Colchis: Use the Golden Fleece
--------------------------------------------------------------------------------------------------------------------------
local Decisions_ColchisFleece = {}
    Decisions_ColchisFleece.Name = "TXT_KEY_DECISIONS_COLCHIS_FLEECE"
	Decisions_ColchisFleece.Desc = "TXT_KEY_DECISIONS_COLCHIS_FLEECE_DESC"
	HookDecisionCivilizationIcon(Decisions_ColchisFleece, "CIVILIZATION_COLCHIS")
	Decisions_ColchisFleece.CanFunc = (
	function(pPlayer)
		if pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_COLCHIS then return false, false end
		if load(pPlayer, "Decisions_ColchisFleece") == true then
			Decisions_ColchisFleece.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_COLCHIS_FLEECE_ENACTED_DESC")
			return false, false, true
		end
		
		local iCost = math.ceil(100 * iMod)
		Decisions_ColchisFleece.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_COLCHIS_FLEECE_DESC", iCost)

		if (pPlayer:GetGold() < iCost) then	return true, false end
		if (pPlayer:GetNumResourceAvailable(iMagistrate, false) < 1) then return true, false end
		if not(Teams[pPlayer:GetTeam()]:IsHasTech(GameInfoTypes.TECH_EPIC_JOURNEYS)) then return true, false end

		local iNumWarsFought = 0
		for iPlayer, pOtherPlayer in pairs(Players) do
			if pPlayer:GetID() ~= iPlayer then
				iNumWarsFought = iNumWarsFought + pPlayer:GetNumWarsFought()
			end
		end
		if iNumWarsFought < 1 then return true, false end
		
		return true, true
	end
	)
	
	Decisions_ColchisFleece.DoFunc = (
	function(pPlayer)
	
		local iCost = math.ceil(100 * iMod)
		pPlayer:ChangeGold(-iCost)		
		pPlayer:ChangeNumResourceTotal(iMagistrate, -1)
		pPlayer:SetNumFreePolicies(1)
		pPlayer:SetNumFreePolicies(0)
		pPlayer:SetHasPolicy(GameInfoTypes.POLICY_FLEECE, true)
		
		save(pPlayer, "Decisions_ColchisFleece", true)
	end
	)
	
Decisions_AddCivilisationSpecific(GameInfoTypes.CIVILIZATION_COLCHIS, "Decisions_ColchisFleece", Decisions_ColchisFleece)
 
http://modiki.civfanatics.com/index.php?title=Player.GetNumWarsFought_(Civ5_API)

You need to state as:
Code:
iNumWarsFought = iNumWarsFought + pPlayer:GetNumWarsFought(iPlayer)
Otherwise I think the way you have it is going to be equivalent to saying
Code:
iNumWarsFought = iNumWarsFought + 0
because I think "pPlayer:GetNumWarsFought()" is going to give "0" or "nil" which I think will be interpretted as "0".
 
Does the decision appear on the decision list? And does your lua.log say anything interesting about that fragment of code? (it's especially 'interesting' if it uses the word "error" :))
 
Problem is with the method. Although there is darn little info on it, from whoward's API as XML 'mod', he has the designation of eWithPlayer shown as the value to be used as this
Code:
pPlayer:GetNumWarsFought([COLOR="Blue"]eWithPlayer[/COLOR])
which when comparing to other usages he has of the same designation leads me to believe the "otherplayer" ID # in method GetNumWarsFought is for specifying a player with whom 'pPlayer' has conducted a cooperative war.

I threw this code into a mod I am running:
Code:
print("processing turn for player " .. iPlayer .. " who is being used as " .. Players[iPlayer]:GetName())
local iTotalWarsFoughtWithMajors = 0
for PlayerID = 1, GameDefines.MAX_MAJOR_CIVS - 1 do
	if Players[PlayerID]:IsAlive() then
		print("pPlayer:GetNumWarsFought(PlayerID) for PlayerID: " .. Players[PlayerID]:GetName() .. ": returns a value of " .. pPlayer:GetNumWarsFought(PlayerID))
		iTotalWarsFoughtWithMajors = iTotalWarsFoughtWithMajors + pPlayer:GetNumWarsFought(PlayerID)
	end
end
print("Total Wars " .. pPlayer:GetName() .. " has fought with living major players is calculated as: " .. iTotalWarsFoughtWithMajors)
and got this in the lua.log:
Code:
[1673427.375] GenericScript: processing turn for player 0 who is being used as Catherine
[1673427.375] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Suleiman: returns a value of 0
[1673427.375] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Ramkhamhaeng: returns a value of 0
[1673427.375] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Pachacuti: returns a value of 0
[1673427.375] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Darius I: returns a value of 0
[1673427.375] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Montezuma: returns a value of 0
[1673427.390] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Napoleon: returns a value of 0
[1673427.390] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Ahmad al-Mansur: returns a value of 0
[1673427.390] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Pedro II: returns a value of 0
[1673427.390] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Dido: returns a value of 0
[1673427.390] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Genghis Khan: returns a value of 0
[1673427.390] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Pacal: returns a value of 0
[1673427.406] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Ashurbanipal: returns a value of 0
[1673427.406] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Casimir III: returns a value of 0
[1673427.406] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Gustavus Adolphus: returns a value of 0
[1673427.406] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Pocatello: returns a value of 0
[1673427.406] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Bismarck: returns a value of 0
[1673427.406] GenericScript: Total Wars Catherine has fought with living major players is calculated as: 0
I am playing as Catherine and I had only made peace with Gustavus Adolphus a couple of turns ago after fighting a little 'border-war', so if the method worked as desired I would have gotten '1' against Gustavus Adolphus and a total number of wars fought as '1'. Instead I got zeroes across the board.
 
The decision shows on the list for Colchis and is unique to them; it just doesn't become available for use. The lua log shows the following:
Code:
[15941.281] EnactDescisionsPopup: Use the Golden Fleece	true	false	nil

There is, however, an issue with a generic Events and Decisions code, so I thought I'd mention that here in case it's connected:
Code:
[15941.250] Runtime Error: C:\Users\Rob\Documents\My Games\Sid Meier's Civilization 5\MODS\Anno Domini (v 1)\EventsDecisions\Lua\EventsAndDecisions_Utilities.lua:307: attempt to index field '?' (a nil value)

Code:
-- Events and Decisions Utilities
-- Author: Sukritact
--=======================================================================================================================
-- Globals
--=======================================================================================================================
include("EventsAndDecisions_Settings.lua")
iMod = ((GameInfo.GameSpeeds[Game.GetGameSpeedType()].BuildPercent)/100)
iGAMod = ((GameInfo.GameSpeeds[Game.GetGameSpeedType()].GoldenAgePercent)/100)
iMagistrate = GameInfoTypes.RESOURCE_MAGISTRATES
--------------------------------------------------------------------------------------------------------------------------
--Convert Setting Globals
--------------------------------------------------------------------------------------------------------------------------
g_RandomEvents_Enabled 		= g_RandomEvents_Enabled > 0
g_TurnBetweenEvents 		= math.ceil(g_TurnBetweenEvents * 10 * iGAMod)
g_ScheduledEvents_Enabled 	= g_ScheduledEvents_Enabled > 0
g_CoreEvents_Enabled 		= g_CoreEvents_Enabled > 0
g_CoreDecisions_Enabled 	= g_CoreDecisions_Enabled > 0
g_PopupType 				= g_PopupType > 0
--=======================================================================================================================
-- Utility Functions
--=======================================================================================================================
-- JFD_IsCivilisationActive: Thanks to JFD for this one!
-------------------------------------------------------------------------------------------------------------------------
function JFD_IsCivilisationActive(civilisationID)
	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local slotStatus = PreGame.GetSlotStatus(iSlot)
		if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
			if PreGame.GetCivilization(iSlot) == civilisationID then
				return true
			end
		end
	end

	return false
end
--------------------------------------------------------------------------------------------------------------------------
-- JFD_GetUniqueUnit
--------------------------------------------------------------------------------------------------------------------------
function JFD_GetUniqueUnit(player, unitClass)
  local unitType = nil
  local civType = GameInfo.Civilizations[player:GetCivilizationType()].Type
 
  for uniqueUnit in GameInfo.Civilization_UnitClassOverrides{CivilizationType = civType, UnitClassType = unitClass} do
    unitType = uniqueUnit.UnitType
    break
  end
 
  if (unitType == nil) then
    unitType = GameInfo.UnitClasses[unitClass].DefaultUnit
  end
 
  return unitType
end
--------------------------------------------------------------------------------------------------------------------------
-- GetUniqueBuilding
--------------------------------------------------------------------------------------------------------------------------
function GetUniqueBuilding(pPlayer, sClass)
  local sBuilding = nil
  local sCiv = GameInfo.Civilizations[pPlayer:GetCivilizationType()].Type
 
  for tBuilding in GameInfo.Civilization_BuildingClassOverrides("CivilizationType = \'" .. sCiv .. "\' AND BuildingClassType = \'" .. sClass .. "\'") do
    sBuilding = tBuilding.BuildingType
    break
  end
 
  if (sBuilding == nil) then
    sBuilding = GameInfo.BuildingClasses[sClass].DefaultBuilding
  end
 
  return sBuilding
end
------------------------------------------------------------------------------------------------------------------------
-- JFD_SendNotification
------------------------------------------------------------------------------------------------------------------------
function JFD_SendNotification(playerID, notificationType, description, descriptionShort, global, iX, iY)
	local player = Players[playerID]
	if global then
			Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes[notificationType], description, descriptionShort, iX or -1, iY or -1)
	else
		if player:IsHuman() then
			Players[Game.GetActivePlayer()]:AddNotification(NotificationTypes[notificationType], description, descriptionShort, iX or -1, iY or -1)
		end
	end
end           
-------------------------------------------------------------------------------------------------------------------------
-- CompileCityID
-------------------------------------------------------------------------------------------------------------------------
function CompileCityID(pCity)
	local iOriginalOwner = pCity:GetOriginalOwner()
	local iTurnFounded = pCity:GetGameTurnFounded ()	--Used to Compile Unique City ID
	local iCityID = ("X" .. pCity:GetX() .. "Y" .. pCity:GetY() .. "P" .. iOriginalOwner .. "T" .. iTurnFounded)
	return iCityID
end
-------------------------------------------------------------------------------------------------------------------------
-- DecompilePlotID
-------------------------------------------------------------------------------------------------------------------------
function DecompilePlotID(sKey)
    iBreak = string.find(sKey, "Y")
    iX = tonumber(string.sub(sKey, 1, iBreak - 1))
    iY = tonumber(string.sub(sKey, iBreak + 1))
    pPlot = Map.GetPlot(iX, iY)
    return pPlot
end
-------------------------------------------------------------------------------------------------------------------------
-- InitUnitFromCity
-------------------------------------------------------------------------------------------------------------------------
function InitUnitFromCity(pCity, iUnitType, iNum)
	local tUnits = {}
	pPlayer = Players[pCity:GetOwner()]
	for i = 1, iNum do
		pUnit = pPlayer:InitUnit(iUnitType, pCity:GetX(), pCity:GetY())
		if not(pUnit:JumpToNearestValidPlot()) then return tUnits end
		
		table.insert(tUnits, pUnit)
		
		pUnit:SetExperience(pCity:GetDomainFreeExperience(pUnit:GetDomainType()))
		for promotion in GameInfo.UnitPromotions() do
			iPromotion = promotion.ID
				if (pCity:GetFreePromotionCount(iPromotion) > 0 and pUnit:IsPromotionValid(iPromotion)) then
				pUnit:SetHasPromotion(iPromotion, true)
			end
		end
		
	end
	return tUnits
end
-------------------------------------------------------------------------------------------------------------------------
-- GetStrongestMilitaryUnit
-------------------------------------------------------------------------------------------------------------------------
function GetStrongestMilitaryUnit(pPlayer, bIgnoreResources, ...)
	local tUnit = {["ID"] = GameInfoTypes.UNIT_WARRIOR, ["Combat"] = 0}
	for iKey, sCombatType in pairs(arg) do
		for row in GameInfo.Units("CombatClass = \'" .. sCombatType .. "\'") do
			if pPlayer:CanTrain(row.ID, bIgnoreResources) and row.Combat > tUnit.Combat then
				tUnit = row
			end
		end
	end
	return tUnit.ID
end
-------------------------------------------------------------------------------------------------------------------------
-- GetRandom
-------------------------------------------------------------------------------------------------------------------------
function GetRandom(lower, upper)
    return (Game.Rand((upper + 1) - lower, "")) + lower
end
--=======================================================================================================================
-- Religious Data
--=======================================================================================================================
-- Define Religious Groups
-------------------------------------------------------------------------------------------------------------------------

tReligiousGroups = {}

--Buddhism
tReligiousGroups.RELIGION_BUDDHISM = "RELIGIONGROUP_BUDDHISM"
tReligiousGroups.RELIGION_MAHAYANA = "RELIGIONGROUP_BUDDHISM"
tReligiousGroups.RELIGION_VAJRAYANA = "RELIGIONGROUP_BUDDHISM"
--Christianity
tReligiousGroups.RELIGION_CHRISTIANITY = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_ORTHODOXY = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_PROTESTANTISM = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_CHRISTIAN_ORIENTAL_ORTHODOX = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_CHRISTIAN_CHURCH_OF_THE_EAST = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_CHRISTIAN_MORMONISM = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_CHRISTIAN_ANGLICANISM = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_PROTESTANT_CALVINISM = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_PROTESTANT_METHODISM = "RELIGIONGROUP_CHRISTIANITY"
tReligiousGroups.RELIGION_PROTESTANT_BAPTIST = "RELIGIONGROUP_CHRISTIANITY"
--Confucianism
tReligiousGroups.RELIGION_CONFUCIANISM = "RELIGIONGROUP_CONFUCIANISM"
--Judaism
tReligiousGroups.RELIGION_JUDAISM = "RELIGIONGROUP_JUDAISM"
--Islam
tReligiousGroups.RELIGION_ISLAM = "RELIGIONGROUP_ISLAM"
tReligiousGroups.RELIGION_ISLAM_SHIA = "RELIGIONGROUP_ISLAM"
tReligiousGroups.RELIGION_ISLAM_IBADI = "RELIGIONGROUP_ISLAM"
--Hinduism
tReligiousGroups.RELIGION_HINDUISM = "RELIGIONGROUP_HINDUISM"
tReligiousGroups.RELIGION_VISHNU = "RELIGIONGROUP_HINDUISM"
tReligiousGroups.RELIGION_SHIVA = "RELIGIONGROUP_HINDUISM"
tReligiousGroups.RELIGION_SHAKTI = "RELIGIONGROUP_HINDUISM"
tReligiousGroups.RELIGION_VEDIC = "RELIGIONGROUP_HINDUISM"
--Shinto
tReligiousGroups.RELIGION_SHINTO = "RELIGIONGROUP_SHINTO"
--Sikhism
tReligiousGroups.RELIGION_SIKHISM = "RELIGIONGROUP_SIKHISM"
--Tengriism
tReligiousGroups.RELIGION_TENGRIISM = "RELIGIONGROUP_TENGRIISM"
--Taoism
tReligiousGroups.RELIGION_TAOISM = "RELIGIONGROUP_TAOISM"
--Zoroastrianism
tReligiousGroups.RELIGION_ZOROASTRIANISM = "RELIGIONGROUP_ZOROASTRIANISM"

-------------------------------------------------------------------------------------------------------------------------
--Determine if Religions are sected
-------------------------------------------------------------------------------------------------------------------------

bChristianitySect = false
bProtestantSect = false
bBuddhismSect = false
bIslamSect = false
bHinduismSect = false

for Religion in GameInfo.Religions() do
	local sReligion = Religion.Type
	if sReligion == "RELIGION_ORTHODOXY" then
		bChristianitySect = true
	elseif sReligion == "RELIGION_PROTESTANT_BAPTIST" then
		bProtestantSect = true
	elseif sReligion == "RELIGION_MAHAYANA" then
		bBuddhismSect = true
	elseif sReligion == "RELIGION_MAHAYANA" then
		bBuddhismSect = true
	elseif sReligion == "RELIGION_VISHNU" then
		bHinduismSect = true
	end
end

-------------------------------------------------------------------------------------------------------------------------
-- Religious Utility Functions
-------------------------------------------------------------------------------------------------------------------------

function ReturnReligionGroup(iReligion)
	local sReligionGroup = "RELIGIONGROUP_NIL"
	if	iReligion ~= nil then
		if tReligiousGroups[GameInfo.Religions[iReligion].Type] ~= nil then
			sReligionGroup = tReligiousGroups[GameInfo.Religions[iReligion].Type]
		end
	end
	return sReligionGroup
end

function GetMajorityReligionGroup(pPlayer)
	local iReligion = GetPlayerMajorityReligion(pPlayer)
	return ReturnReligionGroup(iReligion)
end

function GetReligionsinEmpire(pPlayer)

	local tReligions = {}
	for row in GameInfo.Religions("Type != 'RELIGION_PANTHEON'") do
	
		local iReligion = row.ID
		for pCity in pPlayer:Cities() do
		
			if (pCity:GetNumFollowers(iReligion) > 1) then
				table.insert(tReligions, iReligion)
				break
			end
			
		end
	end
	
	return tReligions
end

function GetNumReligionsinEmpire(pPlayer)
	return #(GetReligionsinEmpire(pPlayer))
end

function GetPlayerMajorityReligion(pPlayer)
	local iMajorityReligion = nil
	for row in GameInfo.Religions() do
		local iReligion = row.ID
		if pPlayer:HasReligionInMostCities(iReligion) then
			iMajorityReligion = iReligion
			break
		end
	end
	return iMajorityReligion
end

function GetReligiousUnity(pPlayer, iReligion)
	local iFollowers = 0
	for pCity in pPlayer:Cities() do
		iFollowers = iFollowers	+ pCity:GetNumFollowers(iReligion)
	end
	local iUnity = iFollowers/pPlayer:GetTotalPopulation()
	return iUnity
end

function ConvertPlayerReligion(pPlayer, iReligion, iPercentage)
	for pCity in pPlayer:Cities() do
		pCity:ConvertPercentFollowers(iReligion, -1, iPercentage)
		for row in GameInfo.Religions() do
			local iLoopReligion = row.ID
			pCity:ConvertPercentFollowers(iReligion, iLoopReligion, iPercentage)
		end
	end
end
--=======================================================================================================================
-- Decisions Specific Functions
--=======================================================================================================================
-- Decisions_AddCivilisationSpecific
-------------------------------------------------------------------------------------------------------------------------
function Decisions_AddCivilisationSpecific(iCiv, sKey, tDecision)
	if JFD_IsCivilisationActive(iCiv) then
		tDecision.Type = "Civilization"
		tDecisions[sKey] = tDecision
	end
end
-------------------------------------------------------------------------------------------------------------------------
-- HookDecisionIcon
-------------------------------------------------------------------------------------------------------------------------
function HookDecisionCivilizationIcon(tTable, sCiv)
	tTable.IconAtlas = GameInfo.Civilizations[sCiv].AlphaIconAtlas
	tTable.IconIndex = GameInfo.Civilizations[sCiv].PortraitIndex
end

function HookDecisionReligionIcon(tTable, sReligion)
	tTable.IconAtlas = GameInfo.Religions[sReligion].IconAtlas
	tTable.IconIndex = GameInfo.Religions[sReligion].PortraitIndex
end
--=======================================================================================================================
-- Event Specific Functions
--=======================================================================================================================
-- Events_AddCivilisationSpecific
-------------------------------------------------------------------------------------------------------------------------
function Events_AddCivilisationSpecific(iCiv, sEvent, tEvent)
	if JFD_IsCivilisationActive(iCiv) then
		tEvents[sEvent] = tEvent
	end
end
-------------------------------------------------------------------------------------------------------------------------
-- Events_AddCivilisationSpecificScheduled: Adds and schedules an event for a civilization
-------------------------------------------------------------------------------------------------------------------------
function Events_AddCivilisationSpecificScheduled(iCiv, sEvent, tEvent, iNum, bYear)
	if JFD_IsCivilisationActive(iCiv) then
	
		tEvents[sEvent] = tEvent
		if(load("Game", "Initial_Scheduled")) then return end
		
		for iPlayer, pPlayer in pairs(Players) do
			if pPlayer:GetCivilizationType() == iCiv then 
				LuaEvents.ScheduleEvent(iPlayer, sEvent, iNum, bYear)
			end
		end
		
	end
end
-------------------------------------------------------------------------------------------------------------------------
-- Events_ScheduleOnce: Schedules an event for a particular player once at the start of the game
-------------------------------------------------------------------------------------------------------------------------
function Events_ScheduleOnce(iPlayer, sEvent, iNum, bYear)
	if not(load("Game", "Initial_Scheduled")) then
		LuaEvents.ScheduleEvent(iPlayer, sEvent, iNum, bYear)
	end
end
-------------------------------------------------------------------------------------------------------------------------
-- Events_ScheduleOnceAllPlayers: Schedules an event for all players once at the start of the game
-------------------------------------------------------------------------------------------------------------------------
function Events_ScheduleOnceAllPlayers(sEvent, iNum, bYear)
	if not(load("Game", "Initial_Scheduled")) then
		for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
			LuaEvents.ScheduleEvent(iPlayer, sEvent, iNum, bYear)
		end
	end
end
--=======================================================================================================================
--=======================================================================================================================
 
The runtime error would appear to be coming from this line in Sukritact's code
Code:
tTable.IconAtlas = GameInfo.Civilizations[sCiv].AlphaIconAtlas
where the civ's AlphaIconAtlas designation is being stored into the "IconAtlas" key-variable for the civ-specific function "table".

It could be the next line
Code:
tTable.IconIndex = GameInfo.Civilizations[sCiv].PortraitIndex
where the portrait index # is being saved into the same table, but from what ModBUddy is showing me of the line numbers I think it is the first line rather than the second.

In any event I would double-check that there is a valid <AlphaIconAtlas> for the civ.

But see my previous on the test I ran re why you are never getting the decision to be enactable. Your condition for number of wars fought is likely always being returned as '0', and therefore the decision is never seen as being enactable.
 
eWithPlayer is the integer id of the player you want to check if you've declared war against (e for enum - but they can be treated as ints)

I've checked the C++ code and it's all hooked up correctly, so should work. Only thing that's not clear is if it counts a war when a player declares war on you.

That is, if A declares war on B, then A:GetNumWarsFought(B) should be 1, but what B:GetNumWarsFought(A) is (either 0 or 1) is unclear (ie, I didn't dig that deep!)
 
I declared war on GusAdolphus. We declared peace at his request (he gave me one of his crappy forward-settled cities which I promptly razed). I still get '0' as the number of wars fought with him. I'll see what happens if I 'reverse' the players.
 
Could you use a listener outside of the E&D code, and apply a dummy policy if the Civ in question goes to war? Then the decision condition is whether or not the Civ has that policy.

Sent from my Nexus 5 using Tapatalk
 
Code:
[1722261.093] GenericScript: processing turn for player 0 who is being used as Catherine
[1722261.125] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Gustavus Adolphus: returns a value of 0
[1722261.125] GenericScript: Total Wars Catherine has fought with living major players is calculated as: 0

[1722183.640] GenericScript: processing turn for player 18 who is being used as Gustavus Adolphus
[1722183.640] GenericScript: pPlayer:GetNumWarsFought(PlayerID) for PlayerID: Catherine: returns a value of 1
[1722183.671] GenericScript: Total Wars Gustavus Adolphus has fought with living major players is calculated as: 1
(I) Catherine declared on Gustavus Adolphus. Same pattern applies with Montezuma who is being a ^&*%$# to his neighbors. Monty shows '0' wars fought, but others show three total wars they have fought with him.

So that player method really ought to be called 'GetNumDefensiveWarsFought' or 'GetNumWarsFoughtAsDefender'
 
Rob,

try changing to as this
Code:
local pPlayerID = pPlayer:GetID()
local iNumWarsFought = 0
for iOtherPlayer, pOtherPlayer in pairs(Players) do
	if pPlayerID ~= iOtherPlayer and iOtherPlayer ~= 63 then
		iNumWarsFought = iNumWarsFought + pPlayer:GetNumWarsFought(iOtherPlayer) + pOtherPlayer:GetNumWarsFought(pPlayerID)
	end
end
if iNumWarsFought < 1 then return true, false end
 
Thanks ever so much for all the help everyone, I really appreciate it!

In my previous run-throughs, I have started the wars in order to complete the requirements, so I've played as an expanding menace to prompt others to declare war on me - this hasn't changed the situation.
EDIT: Scratch that - I hadn't checked that the other prerequisites had occurred - though I am now trying with the amended code that LeeS provided.

Thanks, LeeS, I'll try the amended code, see what happens!
 
LeeS, you are a star. I used your code and now the moment a war is declared (even if I start it myself), the decision becomes available to use. Thank-you ever so much, it's really appreciated!
 
Back
Top Bottom