Hey all,
I'm trying to learn how to mod Civ 6, and I've been able to more or less work my way through the XML and SQL coding with trial and error. But I'm having a little more trouble with the LUA part.
I'm trying to make a leader trait where every time a unit by an enemy civ in friendly territory, the leader receives an envoy and a faith boost. I'm able to do the part where leader gets the rewards whenever a unit dies, but I can't seem to get the code to ONLY activate when the unit dies in friendly territory. It only seems to work anywhere, or nowhere at all.
I suspect it has something to do with the "Plot:GetOwner" part, but I just can't get it to work the way I want. Does anyone have any idea what the problem might be? Help would be greatly appreciated!
I'm trying to learn how to mod Civ 6, and I've been able to more or less work my way through the XML and SQL coding with trial and error. But I'm having a little more trouble with the LUA part.
I'm trying to make a leader trait where every time a unit by an enemy civ in friendly territory, the leader receives an envoy and a faith boost. I'm able to do the part where leader gets the rewards whenever a unit dies, but I can't seem to get the code to ONLY activate when the unit dies in friendly territory. It only seems to work anywhere, or nowhere at all.
Code:
function Els_Martin_UnitKilledInCombat(killedPlayerID, killedUnitID, playerID, unitID)
local player = Players[killedPlayerID]
local unitKilled = player:GetUnits():FindID(killedUnitID)
local numCombat = math.floor(GameInfo.Units[unitKilled:GetType()].Combat)
local unitPlot:table = Map.GetPlot(unitKilled:GetX(), unitKilled:GetY());
if unitPlot:GetOwner() == killedPlayerID then
player:GetReligion():ChangeFaithBalance(numCombat)
player:GetInfluence():ChangeTokensToGive(1)
end
end
Events.UnitKilledInCombat.Add(Els_Martin_UnitKilledInCombat)
I suspect it has something to do with the "Plot:GetOwner" part, but I just can't get it to work the way I want. Does anyone have any idea what the problem might be? Help would be greatly appreciated!