Combat

Group
player
Methods
13
Fields
None

Getting one

player:combat()

Methods

MethodReturnsDescription
attackSpeedTicks()numberTicks between auto-attacks for the current setup: 4 unarmed or for a weapon with no stats; the worn weapon's speed, one less on a ranged st…
isSpecialAttackEnabled()booleanWhether the special attack is switched on, the combat tab's special attack bar.
attackRange()numberHow far the worn weapon reaches now, in tiles: its base plus the long-range bonus on the long-range style (ranged weapons, powered staves),…
weaponClass(number?)WeaponClassA weapon's class: "RANGED", "MAGIC" or "MELEE". Unlike currentAttackStyle, which follows the selected style, this changes the momen…
currentAttackStyle()AttackStyle?The current attack style: AttackStyle.MELEE, RANGED or MAGIC, decided by the worn weapon's category and the selected style slot rathe…
attackCooldownTicks()numberTicks left before the next attack may land.
consumableCooldownTicks()numberTicks left before another consumable may be used: the longest of the eat, potion and karambwan cycles, from the same tracker as `attackCool…
canSpec()booleanWhether special energy covers the worn weapon's cost.
specCostPercent(number?)number?A weapon's special attack energy cost, as a percentage.
setAttackCooldownTicks(number)()The attack delay is ticks now (attackCooldownTicks reads it this tick), and the next tick counts it down. For an encounter that resets…
reduceNextAttackCooldownTicks(number)()The next swing that arms the attack delay arms it ticks shorter, once, and a later call replaces an earlier one. For an encounter that re…
bestSpecWeapon()number?The best special attack weapon worn or carried, as an item id; the worn weapon wins a tie.
wieldBestSpecWeapon()booleanWield bestSpecWeapon from the inventory, when there is the energy for its special.

Returned by

MethodReturnsDescription
PlayerDomain.combatCombatAttack range and speed, cooldowns, special attack, and attack style.

Method details

attackSpeedTicks

attackSpeedTicks: (Combat) -> number

Ticks between auto-attacks for the current setup: 4 unarmed or for a weapon with no stats; the worn weapon's speed, one less on a ranged style's Rapid; a few fixed overrides (the Keris partisan of Amascut 4, the Twinflame staff 6 in a magic style, the echo Venator bow read as the Venator bow); 1 for a Scurrius bone weapon at a Giant rat. An autocast is 5, the game's cast cycle (the Twinflame staff's 6 still wins).

isSpecialAttackEnabled

isSpecialAttackEnabled: (Combat) -> boolean

Whether the special attack is switched on, the combat tab's special attack bar.

attackRange

attackRange: (Combat) -> number

How far the worn weapon reaches now, in tiles: its base plus the long-range bonus on the long-range style (ranged weapons, powered staves), a staff's reach only while casting, the spell range while autocasting, 1 for melee.

weaponClass

weaponClass: (Combat, number?) -> WeaponClass

A weapon's class: "RANGED", "MAGIC" or "MELEE". Unlike currentAttackStyle, which follows the selected style, this changes the moment the weapon does.

itemId
The weapon to ask about; omit for the worn one. Nothing worn is "MELEE".

currentAttackStyle

currentAttackStyle: (Combat) -> AttackStyle?

The current attack style: AttackStyle.MELEE, RANGED or MAGIC, decided by the worn weapon's category and the selected style slot rather than the style's name, and nil when the weapon category cannot be read.

Returns
nil when it cannot be read.

attackCooldownTicks

attackCooldownTicks: (Combat) -> number

Ticks left before the next attack may land.

A 4-tick weapon reads 3, 2, 1, 0, 3, ...: 0 on the tick before each swing. One tracker per client, observed every tick and brought up to date before a read, so onGameTick reads this tick's swing. It arms on an attack animation (the worn weapon's own, or another known attack animation) while attacking an NPC with an Attack option or a level and health, a player, or nothing, and on a new attackable NPC target while it reads 0; never on a block, an eat or a drink. The speed is the same as attackSpeedTicks (4 unarmed, one less on Rapid, the fixed overrides), and one less under the Blood moon set. An autocast counts 5 ticks, the game's cycle; an animation that outlasts the cycle (the Blowpipe, the Eye of Ayak) arms once the delay is 0; an eat's delay is added only for an eat the sustain manager queues (when it queues it), never from the "You eat" line; a spell cast with no animation and the Salamander are not counted (setAttackCooldownTicks and reduceNextAttackCooldownTicks correct it); on a client build that cannot read the animation's frame, a swing that restarts under the same animation is seen only once the animation ends.

consumableCooldownTicks

consumableCooldownTicks: (Combat) -> number

Ticks left before another consumable may be used: the longest of the eat, potion and karambwan cycles, from the same tracker as attackCooldownTicks.

canSpec

canSpec: (Combat) -> boolean

Whether special energy covers the worn weapon's cost.

specCostPercent

specCostPercent: (Combat, number?) -> number?

A weapon's special attack energy cost, as a percentage.

itemId
The weapon to ask about; omit for the worn one.
Returns
nil when the item has no special attack.

setAttackCooldownTicks

setAttackCooldownTicks: (Combat, number) -> ()

The attack delay is ticks now (attackCooldownTicks reads it this tick), and the next tick counts it down. For an encounter that resets the player's cooldown (Tormented Demons' shield).

ticks
A whole number; a negative one is 0.

reduceNextAttackCooldownTicks

reduceNextAttackCooldownTicks: (Combat, number) -> ()

The next swing that arms the attack delay arms it ticks shorter, once, and a later call replaces an earlier one. For an encounter that refunds the cooldown at the cast (the Royal Titans).

ticks
A whole number; a negative one is 0.

bestSpecWeapon

bestSpecWeapon: (Combat) -> number?

The best special attack weapon worn or carried, as an item id; the worn weapon wins a tie.

Returns
nil when neither holds a weapon with a special attack.

wieldBestSpecWeapon

wieldBestSpecWeapon: (Combat) -> boolean

Wield bestSpecWeapon from the inventory, when there is the energy for its special.

Returns
false when nothing was queued: it is already worn, or the energy is short.