Lua "At War check" function

ZeeB

Chieftain
Joined
Aug 13, 2023
Messages
1
I'm trying to create a .lua function that checks if the player unit is at war with any unit in a target plot. But regardless, the function I created generates a false statement. Any help is appreciated.

function CheckAreAtWar(plotId, pUnit)
local pOwner = pUnit:GetOwner()
local attackingPlayer = Players[pOwner]
local tPlot = Map.GetPlotByIndex(plotId)
local tUnits = Units.GetUnitsInPlot(tPlot)
local ptAtWar = false
local targetPlayer
for _, tUnit in ipairs(tUnits) do
local tOwner = tUnit:GetOwner()
targetPlayer = Players[tOwner]
local apDiplomacy = attackingPlayer:GetDiplomacy()
if apDiplomacy:IsAtWarWith(targetPlayer) then
ptAtWar = true
else
LuaEvents.CityStates_ConfirmWarDialog(attackingPlayer:GetID(), targetPlayer:GetID(), WarTypes.SURPRISE_WAR);
end
end
return false
end
 
Back
Top Bottom