Wichilie
Chieftain
- Joined
- Nov 9, 2017
- Messages
- 6
Hey, I'm working on an UA that gives a player's units a promotion based on the highest warmongering level out of everyone that player is at war with. This is what I have right now:
However, no matter how big of a warmongerer the opponent is, GetWarmongerThreat always returns -1 (print(pPlayer:GetWarmongerThreat(pOpponent)) always gives -1). This means the promotion is never given ("No promotions given: warmongering status too low" is always printed). Does anyone know what I'm doing wrong?
Code:
-- AssignAntiWarmongererStrength
-- Author: Wichilie
-- DateCreated: 12/16/2017 11:19:53 PM
--------------------------------------------------------------
print("Loading AssignAntiWarmongererStrength.lua...")
local iRequiredCiv = GameInfoTypes.CIVILIZATION_DEMACIA
local lPromotions = {GameInfo.UnitPromotions["PROMOTION_JUSTICE_1"].ID, GameInfo.UnitPromotions["PROMOTION_JUSTICE_2"].ID, GameInfo.UnitPromotions["PROMOTION_JUSTICE_3"].ID, GameInfo.UnitPromotions["PROMOTION_JUSTICE_4"].ID}
function AssignAntiWarmongererStrength(iTeam1, iTeam2, bWar)
print("War update detected")
-- Check if the required civ got a war update.
for i = 0, GameDefines.MAX_CIV_PLAYERS - 1, 1 do
local pPlayer = Players[i]
local iTeam = pPlayer:GetTeam()
if pPlayer:GetCivilizationType() == iRequiredCiv and (iTeam == iTeam1 or iTeam == iTeam2) then
print("Required Civ got a war update")
-- Go through every civ the required civ is at war with.
local lWarmongeringStatus = {}
for j = 0, GameDefines.MAX_CIV_PLAYERS - 1, 1 do
local pOpponent = Players[j]
if pOpponent ~= pPlayer and Teams[iTeam]:IsAtWar(pOpponent:GetTeam()) then
-- Compile a list of the opponents warmongering status.
print(pOpponent:GetCivilizationType())
print(pPlayer:GetWarmongerThreat(pOpponent))
table.insert(lWarmongeringStatus, pPlayer:GetWarmongerThreat(pOpponent))
end
end
-- Assign the right promotion based on the warmongering status
if next(lWarmongeringStatus) ~= nil then
table.sort(lWarmongeringStatus)
local iHighestWarmongerThreat = lWarmongeringStatus[#lWarmongeringStatus]
if iHighestWarmongerThreat > 0 then
for pUnit in pPlayer:Units() do
for j = 0, table.getn(lPromotions), 1 do
if j == iHighestWarmongerThreat - 1 then
pUnit:SetHasPromotion(lPromotions[j], true)
else
pUnit:SetHasPromotion(lPromotions[j], false)
end
end
print("Promotions have been given")
end
else
print("No promotions given: warmongering status too low")
end
end
end
end
end
Events.WarStateChanged.Add(AssignAntiWarmongererStrength)
print("Loaded AssignAntiWarmongererStrength.lua.")
However, no matter how big of a warmongerer the opponent is, GetWarmongerThreat always returns -1 (print(pPlayer:GetWarmongerThreat(pOpponent)) always gives -1). This means the promotion is never given ("No promotions given: warmongering status too low" is always printed). Does anyone know what I'm doing wrong?