Danmacsch
Geheimekabinetsminister
Hi,
I'm trying to detect if there is a city within a specific radius when a unit is killed. But for some reason, the code only executes to a certain point and I fail to see why that is.
Here's my code:
But upon testing (killing a unit next to a player-owned city with the required building) I only get these print statements:
So I imagine that the fault lies in the "if iPlot:IsCity() then" check.
Can somebody point out my error(s)? Thanks in advance..
I'm trying to detect if there is a city within a specific radius when a unit is killed. But for some reason, the code only executes to a certain point and I fail to see why that is.
Here's my code:
Code:
function DMS_UnitKilledNearBorg(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
local bEnemyKilledNearDanishBorg = false
if bDelay then
print("DMS_UnitKilledNearBorg: a unit is killed somewhere..")
local pPlayer = Players[iKiller]
local iPlayer = Players[iOwner]
if pPlayer and pPlayer:GetCivilizationType() == civilisationDenmarkValdemarIIID then
if pPlayer ~= iPlayer then
print("DMS_UnitKilledNearBorg: the unit was killed by the Kingdom of Denmark and was not Danish itself..")
local pUnit = iPlayer:GetUnitByID(iUnit)
local pPlot = Map.GetPlot(iX, iY)
for iPlot in PlotAreaSweepIterator(pPlot, 2, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_EXCLUDE) do
if iPlot:IsCity() then
print("DMS_UnitKilledNearBorg: the unit was killed within 2 tiles of a City..")
local pCity = iPlot:GetPlotCity()
if pCity:GetOwner() == pPlayer then
print("DMS_UnitKilledNearBorg: the city (" .. pCity:GetName() .. ") is owned by the Kingdom of Denmark..")
if pCity:IsHasBuilding(buildingBorgID) then
print("DMS_UnitKilledNearBorg: the city (" .. pCity:GetName() .. ") has a Borg..")
bEnemyKilledNearDanishBorg = true
break
end
end
end
return pCity, bEnemyKilledNearDanishCity
end
if (bEnemyKilledNearDanishBorg == true) then
print("DMS_UnitKilledNearBorg: calling function DMS_BorgGrantsFaithPerKill..")
DMS_BorgGrantsFaithPerKill(pCity)
end
end
end
end
end
if isDenmarkValdemarIICivActive then
GameEvents.UnitPrekill.Add(DMS_UnitKilledNearBorg)
end
Code:
DMS_DenmarkValdemarII_functions: DMS_UnitKilledNearBorg: a unit is killed somewhere..
DMS_DenmarkValdemarII_functions: DMS_UnitKilledNearBorg: the unit was killed by the Kingdom of Denmark and was not Danish itself..
DMS_DenmarkValdemarII_functions: PlotAreaSweepIterator((12, 42), r=2, s=1, d=fwd, w=out, c=no)
Can somebody point out my error(s)? Thanks in advance..