local object = require("object")
local func = require("functions")
local civlua = require("civluaModified")
local unitKilledEvents = {}
-- This will only run when a unit is killed in combat (i.e. not when an event
-- 'kills' a unit)
-- note that if the aggressor loses, aggressor.location will not work
--
function unitKilledEvents.unitKilledInCombat(loser,winner,aggressor,victim,loserLocation,winnerVetStatus,loserVetSatus)
end
-- This will run any time a unit is killed, either in combat or by events
--
function unitKilledEvents.unitDefeated(loser,winner,aggressor,victim,loserLocation,winnerVetStatus,loserVetStatus)
civ.ui.text("Unit Killed context 2 test")
--Here we see an example of a unitKilled event. Because I'm using "loser.owner" rather than "loser.type," it basically means "any unit" from the Druids civ.
--Note that xFuriesText is found in the object file.
--The next example will show a specific unit type that is killed.
if loser.owner == object.tDruids and winner.owner == object.tRomans then
civ.ui.text(func.splitlines(object.xFuriesText))
end
--Here is how you have a specific unit killed trigger an event. However, I have also added an "and" because I want to ensure that the event only triggers on a specific tile.
--Notice that object.lXXvictrixEvocati is a tile (hence the 'l' prefix) found in the object file (line 110).
if loser.type == object.uLegionStandard and loser.location == object.lXXvictrixEvocati and loser.owner == object.tTheGods and winner.owner == object.tRomans then
civ.ui.text("Recent retirees of the XX Valeria Victrix answer the call and rally behind their Evocati standard! They are a bit rusty, but battle will cure that!") -- Note you can have text this way as well if you don't want to store it in the object file
civlua.createUnit(object.uEvocatiFresh, object.tRomans, {{loser.location.x,loser.location.y,loser.location.z}}, {randomize=false, veteran=true})
civlua.createUnit(object.uEvocatiFresh, object.tRomans, {{loser.location.x,loser.location.y,loser.location.z}}, {randomize=false, veteran=true})
-- I create unit - but note that by using loser.location.x and so on, it will create exactly where the legion standard was killed. This doesn't really matter for this unit (as the legion standard is immobile) but if you wanted to use this to
-- capture "slaves" or something and have the unit show up in the same place as the defeated unit, this is how you achieve it.
end
--Here we switch things up a bit. Here, there is a small chance that a good event will happen, but a greater chance that an unfortunate event will happen.
if loser.type == object.uLegionStandard and loser.location == object.lLegioIIAugustaCallToArms and loser.owner == object.tTheGods and winner.owner == object.tRomans then
local probabilityRoll = math.random()
if probabilityRoll >= .9 then -- 10% chance of good event
civ.ui.text(func.splitlines("Roman general [insert text] has answered the call to arms!"))
elseif probabilityRoll < .9 then -- 90% chance of the historic bad event
civ.ui.text(func.splitlines("Roman general [insert text] has refused the call to arms!"))
end
end
end
-- this happens whenever a unit 'dies', regardless of combat, as long as it is not replaced
function unitKilledEvents.unitDeath(dyingUnit)
end
-- this happens if a unit is deleted (either through combat death, or by some other event,
-- but not if the unit is disbanded)
-- If the unit isn't being replaced, replacingUnit is nil
function unitKilledEvents.unitDeleted(deletedUnit,replacingUnit)
end
return unitKilledEvents