Skip to content

combat

Starts and ends the melee fights of mobiles, and tells whom a mobile fights.

Source: src/Moongate.Server.Ultima/Modules/CombatModule.cs

combat.aggress(attacker, target) -> boolean

Makes the first mobile the aggressor of the second without a blow or a hurt, as a curse is: a player who aggresses an innocent that did not act against it, and that it did not act against in the last two minutes, is a criminal (not for itself or its own pet) and the act is noted in the aggressor lists that the murder report reads, and an NPC that is aggressed fights back. False when either is not in the world, they are on another map, or the target is dead or invulnerable.

A curse makes the caster the aggressor of the target without hurting it: an innocent who is not fighting back makes the caster a criminal, and an NPC fights it:

combat.aggress(caster, target)
mobile.add_stat_curse(target, "strength", 11, 120)
ParameterTypeDefault
attackerinteger
targetinteger

Returns boolean.

combat.armor_rating(mobile) -> integer?

The armor rating of what the mobile wears, as its status shows it: the best piece of each part of the body, each weighted by its share. 0 for none, and nil for a mobile not in the world.

ParameterTypeDefault
mobileinteger

Returns integer?.

combat.attack(attacker, target) -> boolean

Makes the first mobile fight the second: it swings at it, by the swing timer, while the other is within reach. A player goes into war mode and is told whom it fights; one that attacks an innocent who is not fighting it is a criminal. False when either is not in the world, they are on another map, or the second is hidden, out of view or out of sight of the first. The fight ends when the target is gone or dead, after 60 seconds without a swing (ultima.combat.combatant_seconds), by combat.stop or, for a player, by peace.

A guard goes for the criminal it reached; the server swings, hits and kills by its combat rules:

if combat.target(guard_serial) ~= criminal then
combat.attack(guard_serial, criminal)
end
ParameterTypeDefault
attackerinteger
targetinteger

Returns boolean.

combat.harm(target, damage, attacker?, kind?, element?) -> boolean

Hurts the target by damage without a swing, as an explosion does, with the rules of a blow when an attacker is given: a player who harms an innocent that did not act against it, and that it did not act against in the last two minutes, is a criminal (not for harming itself), the act is noted in the aggressor lists that the murder report reads, the target shows the hurt and the damage, dies with the attacker as its killer, and an NPC fights back. The attacker may be left out, as for a trap. No war mode, and the attacker fights no one for it. The kind tells the on_damage of an NPC where the damage comes from: melee, ranged, spell (the default), poison or other, such as a field, an explosion or a trap. False for a target not in the world, dead or invulnerable, an attacker given but not in the world, a negative damage, or a kind or an element that does not exist. The element (physical, fire, cold, poison or energy) is what the resistance of the target to it reduces the damage by while resistances are on; a damage with no element is not resisted, except a poison kind, which is of the poison element.

A trap that burns whoever steps on it, with no one to blame:

function fire_trap.on_step(serial, user)
combat.harm(user, 15, nil, "other")
return true
end

The last argument names where the damage comes from for the on_damage of an NPC: melee, ranged, spell (the default), poison or other.

ParameterTypeDefault
targetinteger
damageinteger
attacker (optional)integernil
kind (optional)stringnil
element (optional)stringnil

Returns boolean.

combat.range(mobile) -> integer?

How far, in cells, the mobile's blows reach: the range of the bow (10) or crossbow (8) an NPC holds, else 1, the melee range of ultima.combat.max_range. nil for a mobile not in the world.

ParameterTypeDefault
mobileinteger

Returns integer?.

combat.spend_ammo(mobile) -> boolean

Takes one arrow or bolt out of the backpack of a mobile that holds a bow or crossbow, as a shot does, and shows the stack smaller. False, and nothing taken, when it holds none or has no ammunition.

ParameterTypeDefault
mobileinteger

Returns boolean.

combat.stop(mobile) -> boolean

Ends the fight of the mobile: it swings no more. False for a mobile not in the world.

Ends the fight of a mobile:

combat.stop(npc_serial)
ParameterTypeDefault
mobileinteger

Returns boolean.

combat.swing(mobile, x, y) -> boolean

Turns the mobile towards x, y and plays the swing of what it holds, seen by the players in range, with no fight, hit or cost: what practising on a dummy does. False for a mobile not in the world.

ParameterTypeDefault
mobileinteger
xinteger
yinteger

Returns boolean.

combat.swing_again(attacker, target, scalar?) -> boolean

A second blow of a player at once, as Double Strike gives: the chance to hit is rolled again with the weapon it holds and the damage is multiplied by the scalar (1 when not given), with the armor of the target in the way, and no special move is asked or spent. False for an NPC, a dead or missing mobile or a blow that missed.

ParameterTypeDefault
attackerinteger
targetinteger
scalar (optional)number1

Returns boolean.

combat.target(mobile) -> integer?

The serial of whom the mobile fights; nil when it fights no one or is not in the world.

The serial of whom a mobile fights, nil when it fights no one:

local target = combat.target(npc_serial)
ParameterTypeDefault
mobileinteger

Returns integer?.

combat.weapon(mobile) -> table?

What the mobile fights with, as a table { skill, ranged, range, item, projectile, ammo }: skill is the name of the skill the weapon trains (wrestling for fists), ranged is true for a bow or crossbow, range how far its blows reach, item the serial of the weapon in its hands (0 for its fists), and for a ranged weapon projectile is the graphic that flies and ammo is arrow or bolt. nil for a mobile not in the world.

ParameterTypeDefault
mobileinteger

Returns table?.

Made with ❤️ by Tom

Buy me a coffee