Skip to content

OnSiegeEngineHit

Another engine’s shot is about to damage a siege engine - return the damage to apply.

Runs for every siege engine within the shot’s radius of the point it came down on: a trebuchet, a cannon, a siege ladder or a pile of stones. damage is what the shot takes off its structure (SetSiegeEngineHealth: 100 is whole, 0 wrecks it) - up to 60 for a trebuchet’s stone, 35 for a cannon ball, less the farther off it came down (SetSiegeEngineRules). Return a number to take that instead (0 or false spares it), nothing to take damage. An engine that falls to 0 is wrecked (OnSiegeEngineDestroyed). Not asked: an engine that can not be wrecked (SetSiegeEngineHealth below 0), and a stone hurled from a pile (it breaks no engine).

function OnSiegeEngineHit(target, id, shooter, damage)
-- ...
end
Parameter Type
target number the engine it would damage
id number the engine that fired the shot
shooter number the player who fired it; -1 = the mode
damage number the structure it would take off

a number - the damage to apply instead; false = none; nothing = damage

-- an engine of the shooter's own side takes no harm, and the castle's own trebuchet half
local ENGINE_TEAM = {} -- engine id -> team, filled where the mode creates them
function OnSiegeEngineHit(target, id, shooter, damage)
if shooter >= 0 and ENGINE_TEAM[target] == GetPlayerTeam(shooter) then return 0 end
if target == CASTLE_TREBUCHET then return damage / 2 end
end

OnSiegeImpact · OnSiegeEngineDestroyed · SetSiegeEngineHealth · the Siege engines group of the index