Class: Unit
Defined in: handles/unit.ts:30
A unit on the map: a soldier, a hero, a structure, a worker or a critter.
Remarks
A unit is a widget: its life comes from Widget, and Unit.fromHandle
upgrades the Wrapper that a widget lookup made earlier for it. The
hero members (agility, experience, setHeroLevel and the like) act on
heroes only: on another unit they read 0 and change nothing.
Example
Creating units, reading an inventory slot and the owner
// A footman and a Paladin for the first player. Creating a unit throws on an
// unknown rawcode; reading an inventory slot is a lookup, undefined when the
// slot is empty; the owner is never undefined.
import { Init, tsGlobals, Unit } from "reforged-ts";
Init.onTriggers(() => {
const owner = tsGlobals.Players[0];
const footman = Unit.create(owner, FourCC("hfoo"), -128, 0);
const paladin = Unit.create(owner, FourCC("Hpal"), 128, 0, 90);
paladin.setHeroLevel(3, false);
paladin.addItemById(FourCC("rde1"));
const ring = paladin.getItemInSlot(0);
const secondSlot = paladin.getItemInSlot(1);
print(`level ${String(paladin.getHeroLevel())}`);
print(`ring carried: ${String(ring !== undefined)}`);
print(`second slot empty: ${String(secondSlot === undefined)}`);
print(`owned by the first player: ${String(paladin.getOwner() === owner)}`);
footman.destroy();
});
Native
Extends
Properties
handle
readonlyhandle:unit
Defined in: handles/unit.ts:32
The game's unit Handle this Wrapper owns.
Overrides
Accessors
acquireRange
Get Signature
get acquireRange():
number
Defined in: handles/unit.ts:213
Gets the range within which the unit picks targets to engage, in world units.
Native
Returns
number
The current acquire range.
Set Signature
set acquireRange(
value):void
Defined in: handles/unit.ts:204
The range within which the unit picks targets to engage, in world units; it is not the attack range.
Remarks
- A unit whose acquire range exceeds its attack range walks up to the targets it picks, then attacks them.
- In the object editor, an acquire range below the attack range caps the attack range. This setter does not: the attack range, and the value the UI shows, stay as they were, whatever is often claimed.
Native
Parameters
value
number
Returns
void
agility
Get Signature
get agility():
number
Defined in: handles/unit.ts:222
Gets the hero's agility without the bonuses of items and buffs.
Native
Returns
number
The base agility; 0 for a unit that is not a hero.
Set Signature
set agility(
value):void
Defined in: handles/unit.ts:230
The hero's base agility; the change is permanent.
Native
Parameters
value
number
Returns
void
armor
Get Signature
get armor():
number
Defined in: handles/unit.ts:240
Gets the unit's armor as it stands, the bonus armor of agility, auras, buffs and items counted in.
Native
Returns
number
The total armor.
Set Signature
set armor(
armorAmount):void
Defined in: handles/unit.ts:249
The unit's total armor, which may be negative: the game changes the base armor so that base and bonus armor add up to the value.
Native
Parameters
armorAmount
number
Returns
void
bagSize
Get Signature
get bagSize():
number
Defined in: handles/unit.ts:258
Gets the size of the unit's bag, its extended inventory.
Native
UnitExtendedInventorySize (jassbot)
Returns
number
The number of bag slots.
canSleep
Get Signature
get canSleep():
boolean
Defined in: handles/unit.ts:275
Gets whether the unit may sleep at night.
Native
Returns
boolean
True when the unit may sleep.
Set Signature
set canSleep(
flag):void
Defined in: handles/unit.ts:266
Whether the unit may sleep at night, as creeps do.
Native
Parameters
flag
boolean
Returns
void
collisionSize
Get Signature
get collisionSize():
number
Defined in: handles/unit.ts:285
Gets the radius the unit occupies for collision, in world units: 16 for a Peasant, 48 for a Mountain Giant.
Native
BlzGetUnitCollisionSize (jassbot)
Returns
number
The collision size.
color
Set Signature
set color(
whichColor):void
Defined in: handles/unit.ts:294
The team colour accent of the unit's model, such as PLAYER_COLOR_RED; the
effects attached to the unit take it too.
Native
Parameters
whichColor
playercolor
Returns
void
currentOrder
Get Signature
get currentOrder():
number
Defined in: handles/unit.ts:303
Gets the id of the order the unit is carrying out.
Native
Returns
number
The order id, or 0 when the unit has no order.
defaultAcquireRange
Get Signature
get defaultAcquireRange():
number
Defined in: handles/unit.ts:312
Gets the acquire range the unit type defines, in world units.
Native
GetUnitDefaultAcquireRange (jassbot)
Returns
number
The default acquire range.
defaultFlyHeight
Get Signature
get defaultFlyHeight():
number
Defined in: handles/unit.ts:321
Gets the flying height the unit type defines, in world units.
Native
GetUnitDefaultFlyHeight (jassbot)
Returns
number
The default flying height.
defaultMoveSpeed
Get Signature
get defaultMoveSpeed():
number
Defined in: handles/unit.ts:330
Gets the movement speed the unit type defines, in world units per second.
Native
GetUnitDefaultMoveSpeed (jassbot)
Returns
number
The default movement speed.
defaultPropWindow
Get Signature
get defaultPropWindow():
number
Defined in: handles/unit.ts:341
Gets the unit type's default propulsion window, in degrees.
Remarks
Unlike the other propulsion window Natives, which take and give radians, this one gives degrees.
Native
GetUnitDefaultPropWindow (jassbot)
Returns
number
The default propulsion window, in degrees.
defaultTurnSpeed
Get Signature
get defaultTurnSpeed():
number
Defined in: handles/unit.ts:351
Gets the turn rate the unit type defines, its object editor field Movement - Turn Rate.
Native
GetUnitDefaultTurnSpeed (jassbot)
Returns
number
The default turn rate, whatever turnSpeed was set to since.
experience
Get Signature
get experience():
number
Defined in: handles/unit.ts:360
Gets the hero's experience points.
Native
Returns
number
The experience; 0 for a unit that is not a hero.
Set Signature
set experience(
newXpVal):void
Defined in: handles/unit.ts:368
The hero's experience points; a level gained this way shows its effects.
Native
Parameters
newXpVal
number
Returns
void
facing
Get Signature
get facing():
number
Defined in: handles/unit.ts:386
Gets the direction the unit faces, in degrees.
Native
Returns
number
The facing, in degrees (0 east, 90 north).
Set Signature
set facing(
value):void
Defined in: handles/unit.ts:377
The direction the unit turns to face, in degrees (0 east, 90 north); it turns at its turn rate, and a moving unit ignores the change.
Native
Parameters
value
number
Returns
void
foodMade
Get Signature
get foodMade():
number
Defined in: handles/unit.ts:395
Gets the food the unit provides to its owner, such as a farm's.
Native
Returns
number
The food provided.
foodUsed
Get Signature
get foodUsed():
number
Defined in: handles/unit.ts:404
Gets the food the unit costs its owner.
Native
Returns
number
The food used.
id
Get Signature
get id():
number
Defined in: handles/handle.ts:148
Gets the game's numeric id of the Handle.
Remarks
Ids are not recycled immediately when the object is destroyed (a new
Handle created right after gets the next id), and they are allocated
deterministically from map start. An id is never data: key a collection
on the Handle (or use HandleMap and HandleSet), never on its id.
Native
Returns
number
The id, unique among the live Handles.
Inherited from
ignoreAlarmToggled
Get Signature
get ignoreAlarmToggled():
boolean
Defined in: handles/unit.ts:413
Gets whether the unit raises no alarm, the "under attack" warning, when it is attacked.
Native
UnitIgnoreAlarmToggled (jassbot)
Returns
boolean
True when the unit raises no alarm.
intelligence
Get Signature
get intelligence():
number
Defined in: handles/unit.ts:422
Gets the hero's intelligence without the bonuses of items and buffs.
Native
Returns
number
The base intelligence; 0 for a unit that is not a hero.
Set Signature
set intelligence(
value):void
Defined in: handles/unit.ts:430
The hero's base intelligence; the change is permanent.
Native
Parameters
value
number
Returns
void
inventorySize
Get Signature
get inventorySize():
number
Defined in: handles/unit.ts:439
Gets the number of slots of the unit's inventory.
Native
Returns
number
The slot count, from 0 to 6; 0 for a unit with no inventory.
invulnerable
Get Signature
get invulnerable():
boolean
Defined in: handles/unit.ts:459
Gets whether the unit is invulnerable.
Native
BlzIsUnitInvulnerable (jassbot)
Returns
boolean
True when the unit is invulnerable.
Set Signature
set invulnerable(
flag):void
Defined in: handles/unit.ts:450
Whether the unit is invulnerable; false removes only the invulnerability
this setter gave.
Remarks
The Native appears to work through the 'Avul' ability of the
default AbilityData.slk: when a map lacks 'Avul', it crashes the game.
Native
Parameters
flag
boolean
Returns
void
isHeroGlowAllowed
Get Signature
get isHeroGlowAllowed():
boolean
Defined in: handles/unit.ts:468
Gets whether the hero glow may show on the unit.
Native
HeroGlowIsAllowedOnUnit (jassbot)
Returns
boolean
True when the hero glow is allowed.
level
Get Signature
get level():
number
Defined in: handles/unit.ts:477
Gets the unit's level: the level its type defines, or a hero's current level.
Native
Returns
number
The level.
life
Get Signature
get life():
number
Defined in: handles/widget.ts:19
Gets how many hit points the widget has left.
Native
Returns
number
The hit points left, an amount rather than a percentage.
Set Signature
set life(
value):void
Defined in: handles/widget.ts:27
The widget's current hit points, an amount rather than a percentage.
Native
Parameters
value
number
Returns
void
Inherited from
localZ
Get Signature
get localZ():
number
Defined in: handles/unit.ts:492
Async
Gets the height of the unit's position, as the local client sees it.
Remarks
The value can differ between clients: never let it decide game state. It is
the same value as z today.
Example
Placing visuals from local heights
// A halo over a flying unit and a shadow on the ground below it, placed from
// heights and positions as each client sees them. The terrain height, a
// unit's height and where an effect is drawn can differ between clients, so
// they place visuals only: game logic reads positions every client shares,
// such as the unit's x and y.
import { Effect, Init, Point, Timer, tsGlobals, Unit } from "reforged-ts";
Init.onGameStart(() => {
const gryphon = Unit.create(tsGlobals.Players[0], FourCC("hgry"), 0, 0);
const halo = Effect.create(
"Abilities\\Spells\\Human\\InnerFire\\InnerFireTarget.mdl",
0,
0,
);
const shadow = Effect.create(
"Abilities\\Spells\\Undead\\RegenerationAura\\ObsidianRegenAura.mdl",
0,
0,
);
const ground = Point.create(0, 0);
Timer.every(0.03, () => {
ground.setPosition(gryphon.x, gryphon.y);
// `localZ` reads the same height as `z` today.
halo.setPosition(gryphon.x, gryphon.y, gryphon.localZ + 100);
halo.setAlpha(gryphon.z - ground.z < 50 ? 0 : 255);
// The shadow lies on the terrain under the halo and shrinks as it rises.
shadow.setPosition(halo.x, halo.y, ground.z);
shadow.scale = Math.max(0.2, 1 - (halo.z - ground.z) / 1000);
});
});
Native
Returns
number
The height, in world units.
mana
Get Signature
get mana():
number
Defined in: handles/unit.ts:502
Gets the mana the unit has left to cast its abilities with, from 0 up to
maxMana.
Native
Returns
number
The current mana; 0 for a unit without mana.
Set Signature
set mana(
value):void
Defined in: handles/unit.ts:511
The mana the unit has left to cast its abilities with; the game keeps
the value between 0 and maxMana.
Native
Parameters
value
number
Returns
void
maxLife
Get Signature
get maxLife():
number
Defined in: handles/unit.ts:520
Gets the most life the unit can have, the full length of its health bar.
Native
Returns
number
The maximum life, a whole number of hit points.
Set Signature
set maxLife(
value):void
Defined in: handles/unit.ts:529
The most life the unit can have, the full length of its health bar, as a whole number of hit points.
Native
Parameters
value
number
Returns
void
maxMana
Get Signature
get maxMana():
number
Defined in: handles/unit.ts:538
Gets the most mana the unit can have, the full length of its mana bar.
Native
Returns
number
The maximum mana, a whole number; 0 for a unit without mana.
Set Signature
set maxMana(
value):void
Defined in: handles/unit.ts:547
The most mana the unit can have, the full length of its mana bar, as a whole number.
Native
Parameters
value
number
Returns
void
moveSpeed
Get Signature
get moveSpeed():
number
Defined in: handles/unit.ts:564
Gets the unit's movement speed, in world units per second.
Native
Returns
number
The movement speed.
Set Signature
set moveSpeed(
value):void
Defined in: handles/unit.ts:555
The unit's movement speed, in world units per second.
Native
Parameters
value
number
Returns
void
name
Get Signature
get name():
string
Defined in: handles/unit.ts:578
Async
Gets the unit's name as the local client's language shows it.
Remarks
The value can differ between clients: never let it decide game state.
Example
Showing names in the local language
// The names and texts of units, items and destructables come in each
// client's own language, so they differ between players: show them, and
// decide by the type's rawcode, which every client shares.
import {
Destructable,
Init,
Item,
on,
tsGlobals,
Unit,
UnitEvents,
} from "reforged-ts";
Init.onTriggers(() => {
// A rawcode decides which item counts; the text only describes it.
on(
UnitEvents.pickupItem,
({ unit, item }) => {
print(`${unit.name} picked up ${item.name}: ${item.tooltip}`);
print(
item.extendedTooltip !== "" ? item.extendedTooltip : item.description,
);
},
({ item }) => item.typeId === FourCC("ratf"),
);
const tree = Destructable.create({ typeId: FourCC("LTlt"), x: 256, y: 0 });
const footman = Unit.create(tsGlobals.Players[0], FourCC("hfoo"), 0, 0);
print(`${footman.name} stands next to a ${tree.name ?? "tree"}`);
Item.create(FourCC("ratf"), 128, 0);
});
Native
Returns
string
The localized name, or an empty string when the game returns none.
Set Signature
set name(
value):void
Defined in: handles/unit.ts:587
The unit's own name, which replaces its type's name at once.
Native
Bug
Setting an empty name crashes the game.
Parameters
value
string
Returns
void
nameProper
Get Signature
get nameProper():
string
Defined in: handles/unit.ts:607
Gets the hero's proper name, the name shown above its experience bar.
Remarks
The Native gives null for a unit that is not a hero, and for an
illusion.
Native
Returns
string
The proper name, or an empty string for a unit that is not a hero or an illusion.
Set Signature
set nameProper(
value):void
Defined in: handles/unit.ts:595
The hero's proper name, the name shown above its experience bar.
Native
BlzSetHeroProperName (jassbot)
Parameters
value
string
Returns
void
orderCount
Get Signature
get orderCount():
number
Defined in: handles/unit.ts:616
Gets the number of orders the unit has, the current one and the queued ones.
Native
BlzGetUnitOrderCount (jassbot)
Returns
number
The order count.
paused
Get Signature
get paused():
boolean
Defined in: handles/unit.ts:639
Gets whether the unit is paused.
Native
Returns
boolean
True when the paused setter paused the unit; pauseEx leaves it false.
Set Signature
set paused(
flag):void
Defined in: handles/unit.ts:630
Whether the unit is paused.
Remarks
While paused, a unit:
- has its buffs and effects on hold;
- keeps the orders it is given and carries them out once unpaused;
- takes no powerups:
addItemreturns true, yet the item stays where it was.
Native
Parameters
flag
boolean
Returns
void
pointValue
Get Signature
get pointValue():
number
Defined in: handles/unit.ts:648
Gets the point value the unit type defines, which the score screen counts.
Native
Returns
number
The point value.
propWindow
Get Signature
get propWindow():
number
Defined in: handles/unit.ts:672
Gets the unit's propulsion window, in radians.
Native
Returns
number
The propulsion window, in radians.
Set Signature
set propWindow(
newPropWindowAngle):void
Defined in: handles/unit.ts:663
The unit's propulsion window, in radians: how far its facing may be from the direction of an order's target (move, attack, patrol, smart) for it to start moving at once; further off, it turns without moving first.
Remarks
- At 0 the unit cannot move at all, so it cannot attack either. At the full 180 degrees it moves off as soon as it gets an order that needs movement.
- Source: http://www.hiveworkshop.com/forums/2391397-post20.html
Native
Parameters
newPropWindowAngle
number
Returns
void
race
Get Signature
get race():
race
Defined in: handles/unit.ts:681
Gets the race of the unit's type.
Native
Returns
race
The race, such as RACE_HUMAN.
rallyDestructable
Get Signature
get rallyDestructable():
Destructable|undefined
Defined in: handles/unit.ts:690
Gets the destructable the unit's rally point is set on.
Native
GetUnitRallyDestructable (jassbot)
Returns
Destructable | undefined
The destructable, or undefined when the rally point is not on a destructable.
rallyPoint
Get Signature
get rallyPoint():
Point|undefined
Defined in: handles/unit.ts:700
The unit's rally point, or undefined for a unit that has none: a lookup, although the game allocates a new location each time it returns one.
Native
Returns
Point | undefined
The rally point, or undefined when the unit has none.
rallyUnit
Get Signature
get rallyUnit():
Unit|undefined
Defined in: handles/unit.ts:709
Gets the unit the unit's rally point is set on.
Native
Returns
Unit | undefined
The unit, or undefined when the rally point is not on a unit.
resourceAmount
Get Signature
get resourceAmount():
number
Defined in: handles/unit.ts:726
Gets the gold left in the gold mine.
Native
Returns
number
The gold amount; 0 for a unit that is not a gold mine.
Set Signature
set resourceAmount(
amount):void
Defined in: handles/unit.ts:717
The gold left in the gold mine; a negative amount counts as 0.
Native
Parameters
amount
number
Returns
void
selectable
Get Signature
get selectable():
boolean
Defined in: handles/unit.ts:735
Gets whether a player can select the unit.
Native
Returns
boolean
True when the unit is selectable.
selectionScale
Get Signature
get selectionScale():
number
Defined in: handles/unit.ts:752
Gets the scale of the unit's selection circle.
Native
Returns
number
The selection scale, or 0 when the game returns none.
Set Signature
set selectionScale(
scale):void
Defined in: handles/unit.ts:743
The scale of the unit's selection circle, where 1 is its type's size.
Native
Parameters
scale
number
Returns
void
show
Get Signature
get show():
boolean
Defined in: handles/unit.ts:771
Gets whether the unit is shown.
Native
Returns
boolean
True when the unit is shown, false when it is hidden.
Set Signature
set show(
flag):void
Defined in: handles/unit.ts:762
Whether the unit is shown; a hidden unit is not drawn, cannot be selected and takes no part in the game until it is shown again.
Native
Parameters
flag
boolean
Returns
void
skillPoints
Get Signature
get skillPoints():
number
Defined in: handles/unit.ts:798
Gets the hero's unspent skill points.
Native
Returns
number
The unspent skill points; 0 for a unit that is not a hero.
Set Signature
set skillPoints(
skillPoints):void
Defined in: handles/unit.ts:812
Sets the hero's unspent skill points, by the difference from the points it has; nothing for a unit that is not a hero.
Remarks
The game never goes below 0, nor above the points the hero has left to spend on its abilities (9 at most for three abilities of 3 levels each), so the count read back can be lower than the one set.
Native
Native
UnitModifySkillPoints (jassbot)
Parameters
skillPoints
number
Returns
void
skin
Get Signature
get skin():
number
Defined in: handles/unit.ts:780
Gets the rawcode of the unit type whose model the unit uses.
Native
Returns
number
The skin's rawcode.
Set Signature
set skin(
skinId):void
Defined in: handles/unit.ts:789
The rawcode of the unit type whose model, scale and sounds the unit uses; a change removes every effect attached to the unit.
Native
Parameters
skinId
number
Returns
void
sleeping
Get Signature
get sleeping():
boolean
Defined in: handles/unit.ts:824
Gets whether the unit is asleep.
Native
Returns
boolean
True when the unit sleeps.
strength
Get Signature
get strength():
number
Defined in: handles/unit.ts:833
Gets the hero's strength without the bonuses of items and buffs.
Native
Returns
number
The base strength; 0 for a unit that is not a hero.
Set Signature
set strength(
value):void
Defined in: handles/unit.ts:842
The hero's base strength; the change is permanent, and lowering it lowers the hero's life.
Native
Parameters
value
number
Returns
void
turnSpeed
Get Signature
get turnSpeed():
number
Defined in: handles/unit.ts:862
Gets how fast the unit turns to a new facing: a higher value turns faster.
Native
Returns
number
The turn rate, on the scale of the object editor field Movement - Turn Rate.
Set Signature
set turnSpeed(
value):void
Defined in: handles/unit.ts:851
How fast the unit turns to a new facing, on the scale of the object editor field Movement - Turn Rate: a higher value turns faster.
Native
Parameters
value
number
Returns
void
typeId
Get Signature
get typeId():
number
Defined in: handles/unit.ts:871
Gets the rawcode of the unit's type.
Native
Returns
number
The rawcode, such as FourCC("hfoo").
userData
Get Signature
get userData():
number
Defined in: handles/unit.ts:880
Gets the custom integer stored on the unit.
Native
Returns
number
The value, 0 until one is set.
Set Signature
set userData(
value):void
Defined in: handles/unit.ts:889
A custom integer the unit carries for the map's own use.
Remarks
No mechanism of the game reads it.
Native
Parameters
value
number
Returns
void
waygateActive
Get Signature
get waygateActive():
boolean
Defined in: handles/unit.ts:906
Gets whether the unit works as a waygate.
Native
Returns
boolean
True when the unit has the Waygate ability and is activated.
Set Signature
set waygateActive(
flag):void
Defined in: handles/unit.ts:897
Whether the unit works as a waygate; it needs the Waygate ability ('Awrp').
Native
Parameters
flag
boolean
Returns
void
x
Get Signature
get x():
number
Defined in: handles/unit.ts:917
Gets the unit's x-coordinate, alive or dead.
Native
Bug
For a unit loaded into a zeppelin, it returns where the unit boarded, not the zeppelin's position.
Returns
number
The x-coordinate, in world units.
Set Signature
set x(
value):void
Defined in: handles/unit.ts:929
The unit's x-coordinate: the unit moves at once, ignoring pathing.
Remarks
- A unit with a movement speed of 0 is moved, but its model stays where it was.
- The unit keeps its orders;
setPositioncancels them.
Native
Parameters
value
number
Returns
void
Overrides
y
Get Signature
get y():
number
Defined in: handles/unit.ts:940
Gets the unit's y-coordinate, alive or dead.
Native
Bug
For a unit loaded into a zeppelin, it returns where the unit boarded, not the zeppelin's position.
Returns
number
The y-coordinate, in world units.
Set Signature
set y(
value):void
Defined in: handles/unit.ts:952
The unit's y-coordinate: the unit moves at once, ignoring pathing.
Remarks
- A unit with a movement speed of 0 is moved, but its model stays where it was.
- The unit keeps its orders;
setPositioncancels them.
Native
Parameters
value
number
Returns
void
Overrides
z
Get Signature
get z():
number
Defined in: handles/unit.ts:967
Async
Gets the height of the unit's position: the ground, water or walkable destructable below it plus the unit's own height.
Remarks
The value can differ between clients: never let it decide game state.
Example
Placing visuals from local heights
// A halo over a flying unit and a shadow on the ground below it, placed from
// heights and positions as each client sees them. The terrain height, a
// unit's height and where an effect is drawn can differ between clients, so
// they place visuals only: game logic reads positions every client shares,
// such as the unit's x and y.
import { Effect, Init, Point, Timer, tsGlobals, Unit } from "reforged-ts";
Init.onGameStart(() => {
const gryphon = Unit.create(tsGlobals.Players[0], FourCC("hgry"), 0, 0);
const halo = Effect.create(
"Abilities\\Spells\\Human\\InnerFire\\InnerFireTarget.mdl",
0,
0,
);
const shadow = Effect.create(
"Abilities\\Spells\\Undead\\RegenerationAura\\ObsidianRegenAura.mdl",
0,
0,
);
const ground = Point.create(0, 0);
Timer.every(0.03, () => {
ground.setPosition(gryphon.x, gryphon.y);
// `localZ` reads the same height as `z` today.
halo.setPosition(gryphon.x, gryphon.y, gryphon.localZ + 100);
halo.setAlpha(gryphon.z - ground.z < 50 ? 0 : 255);
// The shadow lies on the terrain under the halo and shrinks as it rises.
shadow.setPosition(halo.x, halo.y, ground.z);
shadow.scale = Math.max(0.2, 1 - (halo.z - ground.z) / 1000);
});
});
Native
Returns
number
The height, in world units.
Methods
addAbility()
addAbility(
abilityId):boolean
Defined in: handles/unit.ts:977
Adds an ability to the unit, at level 1 and off cooldown.
Parameters
abilityId
number
The ability's rawcode, such as FourCC("AHbz").
Returns
boolean
True when the ability was added, false when the unit already has it.
Native
addAnimationProps()
addAnimationProps(
animProperties,add):void
Defined in: handles/unit.ts:1008
Adds or removes animation tags, such as "alternate" or "defend", that the
game adds to every animation the unit plays.
Parameters
animProperties
string
The tags, separated by spaces.
add
boolean
True to add the tags, false to remove them.
Returns
void
Native
AddUnitAnimationProperties (jassbot)
addExperience()
addExperience(
xpToAdd,showEyeCandy):void
Defined in: handles/unit.ts:1024
Gives the hero experience; beyond what a level needs, the hero gains that level and the rest carries over to the next one.
Parameters
xpToAdd
number
The experience points to add, a whole number.
showEyeCandy
boolean
true to show the level-up effect when the hero
gains a level.
Returns
void
Native
Bug
A negative amount takes that much experience away, but the hero keeps its level, even with less experience than the level needs.
Bug
Experience does not go below zero: a result under zero wraps around
to 4294967296 plus that negative result.
addIndicator()
addIndicator(
red,green,blue,alpha):void
Defined in: handles/unit.ts:1036
Flashes a coloured indicator on the unit, as the game does on a unit that is attacked.
Parameters
red
number
The red component, from 0 to 255.
green
number
The green component, from 0 to 255.
blue
number
The blue component, from 0 to 255.
alpha
number
The opacity, from 0 (invisible) to 255 (opaque).
Returns
void
Native
Overrides
addItem()
addItem(
whichItem):boolean
Defined in: handles/unit.ts:1052
Puts an item in the unit's inventory.
Parameters
whichItem
The item to put in the inventory.
Returns
boolean
True when the item is now in the inventory, it was already there included; false when the unit has no inventory or no free slot.
Native
addItemById()
addItemById(
itemId):Item
Defined in: handles/unit.ts:1081
Creates an item of a type at the unit's position and puts it in the unit's inventory.
Parameters
itemId
number
The item type's rawcode, such as FourCC("rde1").
Returns
The new item.
Remarks
- When the inventory is full, the unit cannot carry items or it is dead,
the item stays on the ground at the unit's position (for a unit loaded
into a zeppelin, where it boarded, as
xandyread) and is returned all the same. hasItemis false for the returned item in that case, and also when the game used it at once (a powerup such as a tome) or merged its charges into an item the unit holds: the item is then removed.UnitAddItemByIdis not used: it returns nothing for the item it drops.
Throws
When no item is created, for example for an unknown rawcode or a
removed unit: reforged-ts: failed to create Item (<rawcode>), at the
calling line. In Dev mode, also before the globals Init stage and inside
MapPlayer.runLocal.
Native
Native
Native
Native
Native
addItemToSlotById()
addItemToSlotById(
itemId,itemSlot):boolean
Defined in: handles/unit.ts:1100
Creates an item of a type in one slot of the unit's inventory.
Parameters
itemId
number
The item type's rawcode, such as FourCC("rde1").
itemSlot
number
The slot, from 0 to 5.
Returns
boolean
True when the item landed in the slot.
Remarks
When the slot is taken or does not exist, the game drops the new item at the unit's feet.
Native
UnitAddItemToSlotById (jassbot)
addItemToStock()
addItemToStock(
itemId,currentStock,stockMax):void
Defined in: handles/unit.ts:1111
Adds an item type to the stock of the shop.
Parameters
itemId
number
The item type's rawcode.
currentStock
number
The number of items in stock now.
stockMax
number
The most items the stock holds.
Returns
void
Native
addResourceAmount()
addResourceAmount(
amount):void
Defined in: handles/unit.ts:1126
Adds gold to the gold mine; a negative amount takes gold away.
Parameters
amount
number
The gold to add, a whole number.
Returns
void
Native
Bug
A total under zero shows as a negative amount, but a worker who then gathers from the mine brings back no gold, and the mine is destroyed.
addSleepPerm()
addSleepPerm(
add):void
Defined in: handles/unit.ts:1135
Sets whether the unit sleeps at all times, by day as well as at night.
Parameters
add
boolean
True to make the unit sleep at all times.
Returns
void
Native
addType()
addType(
whichUnitType):boolean
Defined in: handles/unit.ts:1145
Adds a classification to the unit, such as UNIT_TYPE_UNDEAD.
Parameters
whichUnitType
unittype
The classification to add.
Returns
boolean
True when the game added it.
Native
addUnitToStock()
addUnitToStock(
unitId,currentStock,stockMax):void
Defined in: handles/unit.ts:1156
Adds a unit type to the stock of the shop.
Parameters
unitId
number
The unit type's rawcode.
currentStock
number
The number of units in stock now.
stockMax
number
The most units the stock holds.
Returns
void
Native
adjustAbilityCooldownPercent()
adjustAbilityCooldownPercent(
abilId,delta):void
Defined in: handles/unit.ts:987
Adjusts the remaining cooldown of one of the unit's abilities by a share of its full cooldown.
Parameters
abilId
number
The ability's rawcode.
delta
number
The share of the full cooldown to add; negative to shorten the cooldown.
Returns
void
Native
BlzAdjustUnitAbilityCooldownPercent (jassbot)
adjustAbilityCooldownRemaining()
adjustAbilityCooldownRemaining(
abilId,delta):void
Defined in: handles/unit.ts:997
Adjusts the remaining cooldown of one of the unit's abilities by a number of seconds.
Parameters
abilId
number
The ability's rawcode.
delta
number
The seconds to add; negative to shorten the cooldown.
Returns
void
Native
BlzAdjustUnitAbilityCooldownRemaining (jassbot)
allowHeroGlow()
allowHeroGlow(
allow):void
Defined in: handles/unit.ts:1170
Allows or disallows the hero glow on the unit.
Parameters
allow
boolean
True to allow the glow, false to disallow it.
Returns
void
Native
Native
DisallowHeroGlowOnUnit (jassbot)
applyTimedLife()
applyTimedLife(
buffId,duration):void
Defined in: handles/unit.ts:1186
Gives the unit a timed life: it dies once the duration has passed, and its interface shows the time left.
Parameters
buffId
number
The timed-life buff's rawcode, such as FourCC("BTLF") (the
generic one); an unknown buff falls back to it.
duration
number
The time left to live, in seconds.
Returns
void
Native
attachSound()
attachSound(
sound):void
Defined in: handles/unit.ts:1195
Attaches a 3D sound to the unit, so that it plays from the unit's position.
Parameters
sound
The sound, which must have been created as a 3D sound.
Returns
void
Native
bagItem()
bagItem(
index):Item|undefined
Defined in: handles/unit.ts:1205
Gets the item in one slot of the unit's bag, its extended inventory.
Parameters
index
number
The bag slot, from 0.
Returns
Item | undefined
The item, or undefined when the slot is empty.
Native
cancelTimedLife()
cancelTimedLife():
void
Defined in: handles/unit.ts:1213
Removes the unit's timed life, which kills it; does nothing to a unit without one.
Returns
void
Native
BlzUnitCancelTimedLife (jassbot)
canEquip()
canEquip(
equipmentType):boolean
Defined in: handles/unit.ts:1224
Checks whether the unit can equip items of an equipment type.
Parameters
equipmentType
The equipment type.
Returns
boolean
True when the unit can equip such items.
Native
UnitCanEquipItemOfEquipmentType (jassbot)
Native
ConvertEquipmentType (jassbot)
canSleepPerm()
canSleepPerm():
boolean
Defined in: handles/unit.ts:1236
Checks whether the unit sleeps at all times, by day as well as at night.
Returns
boolean
True when the unit sleeps at all times.
Native
clearOrders()
clearOrders(
onlyQueued):void
Defined in: handles/unit.ts:3301
Clears the unit's orders, through BlzUnitClearOrders.
Parameters
onlyQueued
boolean
Clears only the queued orders, keeping the current one.
Returns
void
Native
countBuffs()
countBuffs(
removePositive,removeNegative,magic,physical,timedLife,aura,autoDispel):number
Defined in: handles/unit.ts:1257
Counts the buffs on the unit that match the filters.
Parameters
removePositive
boolean
Counts positive buffs; with removeNegative, both
false counts positive and negative buffs.
removeNegative
boolean
Counts negative buffs.
magic
boolean
Counts only magical buffs, unless physical is true too, which
matches none; both false counts magical and physical buffs.
physical
boolean
Counts only physical buffs, unless magic is true too.
timedLife
boolean
Includes timed-life buffs; false leaves them out.
aura
boolean
Includes aura buffs; false leaves them out.
autoDispel
boolean
Counts only the buffs that dispelling removes.
Returns
number
The number of matching buffs.
Remarks
The filters combine differently here than in removeBuffsEx: see
the Native's reference.
Native
createMinimapIcon()
createMinimapIcon(
red,green,blue,pingPath,fogVisibility):minimapicon
Defined in: handles/unit.ts:3318
Creates a minimap icon at the unit's position, and returns the game's
minimapicon, which the library does not wrap.
Parameters
red
number
The red channel, from 0 to 255.
green
number
The green channel, from 0 to 255.
blue
number
The blue channel, from 0 to 255.
pingPath
string
The model of the icon.
fogVisibility
fogstate
The fog state in which the icon is visible.
Returns
minimapicon
The new minimap icon.
Throws
When the game creates none:
reforged-ts: failed to create minimapicon (<pingPath>), at the calling line.
Native
CreateMinimapIconOnUnit (jassbot)
damageAt()
damageAt(
delay,radius,x,y,amount,attack,ranged,attackType,damageType,weaponType):boolean
Defined in: handles/unit.ts:1294
Deals damage from the unit to everything in a circle, after a delay.
Parameters
delay
number
The delay before the damage, in seconds.
radius
number
The circle's radius, in world units.
x
number
The x-coordinate of the circle's centre, in world units.
y
number
The y-coordinate of the circle's centre, in world units.
amount
number
The damage dealt to each target.
attack
boolean
Deals the damage as an attack.
ranged
boolean
Deals the damage as a ranged one.
attackType
attacktype
The attack type, such as ATTACK_TYPE_NORMAL.
damageType
damagetype
The damage type, such as DAMAGE_TYPE_NORMAL.
weaponType
weapontype
The weapon type, which picks the impact sound, such as
WEAPON_TYPE_WHOKNOWS.
Returns
boolean
True when the game scheduled the damage.
Native
damageTarget()
damageTarget(
target,amount,attack,ranged,attackType,damageType,weaponType):boolean
Defined in: handles/unit.ts:1351
Makes the unit deal damage to a widget.
Parameters
target
widget
The unit, item or destructable that takes the damage.
amount
number
The damage to deal, before the target's armor and the attack and damage types change it.
attack
boolean
true to count the damage as an attack.
ranged
boolean
true to count the damage as coming from range.
attackType
attacktype
The attack type, such as ATTACK_TYPE_NORMAL.
damageType
damagetype
The damage type, such as DAMAGE_TYPE_NORMAL.
weaponType
weapontype
The weapon type, which picks the impact sound, such as
WEAPON_TYPE_WHOKNOWS.
Returns
boolean
True when the game dealt the damage.
Remarks
Dealing damage inside a damage handler fires the damage events again, so
a handler that damages back without a stop loops until the client
crashes. In Dev mode every action and condition of a Trigger carrying a
damage event (an on() damage subscription included) runs one level
deeper in a shared damage depth, and this member raises
reforged-ts: Unit#<id> Unit.damageTarget at damage depth <depth>, past the limit of <limit>: ...
when the depth exceeds the limit: eight nested dispatches by default,
Reforged.configure({ damageDepthLimit }) to change it. A single bounce
(reflect damage) passes. With Dev mode off nothing is counted and nothing
raises.
How the attack, damage and weapon types combine is explained in this wc3c post.
Throws
In Dev mode, past the damage depth limit:
reforged-ts: Unit#<id> Unit.damageTarget at damage depth <depth>, past the limit of <limit>: ...
Native
decAbilityLevel()
decAbilityLevel(
abilCode):number
Defined in: handles/unit.ts:1382
Lowers one of the unit's abilities by one level, down to level 1 at least.
Parameters
abilCode
number
The ability's rawcode, such as FourCC("AHbz").
Returns
number
The new ability level.
Native
destroy()
destroy():
void
Defined in: handles/unit.ts:1399
Instantly removes the unit from the game.
Returns
void
Remarks
In Dev mode the destroyed Wrapper becomes a tombstone: any later access,
a second destroy() included, raises
reforged-ts: used after destroy: <Class>#<id>, and
Reforged.debug.report() counts it destroyed.
Example
Removing game objects without a death
// Removing a unit, an item or a destructable from the game at once with
// destroy(), where kill() would let it die. A destroyed unit fires no death
// event, leaves no corpse and gives no bounty, so call destroy() for what
// must vanish without a trace, such as a dummy unit or a used token.
// Every reference to it is dead afterwards: remove it from the maps and
// groups that hold it, since in Dev mode any use of a destroyed Wrapper
// raises `reforged-ts: used after destroy: <Class>#<id>`.
import {
Destructable,
HandleMap,
Init,
Item,
tsGlobals,
Unit,
} from "reforged-ts";
/** The token each hero carries, while it carries one. */
const tokens = new HandleMap<Unit, Item>();
/** Spends `hero`'s token: the item vanishes and the entry goes with it. */
export function spendToken(hero: Unit): void {
const token = tokens.get(hero);
if (token === undefined) {
return;
}
tokens.delete(hero);
token.destroy();
}
Init.onTriggers(() => {
const owner = tsGlobals.Players[0];
const hero = Unit.create(owner, FourCC("Hpal"), 0, 0);
const token = Item.create(FourCC("ratf"), 64, 0);
hero.addItem(token);
tokens.set(hero, token);
spendToken(hero);
// A dummy unit, removed once its work is done: no death, no corpse.
const dummy = Unit.create(owner, FourCC("hfoo"), 128, 0);
dummy.destroy();
// A gate removed when opened, rather than left as a broken one.
const gate = Destructable.create({ typeId: FourCC("LTg1"), x: 256, y: 0 });
gate.destroy();
});
Throws
In Dev mode, inside MapPlayer.runLocal:
reforged-ts: destroying Unit#<id> inside MapPlayer.runLocal changes game state for one client, which desyncs the game: only visuals belong inside runLocal
Native
disableAbility()
disableAbility(
abilId,flag,hideUI):void
Defined in: handles/unit.ts:1416
Disables or enables one of the unit's abilities, and hides or shows its icon.
Parameters
abilId
number
The ability's rawcode.
flag
boolean
True to disable the ability, false to enable it.
hideUI
boolean
True to hide the ability's icon, false to show it.
Returns
void
Remarks
A disabled ability that stays visible shows its disabled icon.
Native
BlzUnitDisableAbility (jassbot)
Bug
The game counts the calls instead of storing the flags: after hiding an icon several times, as many calls are needed to show it again (report).
dropItem()
dropItem(
whichItem,x,y):boolean
Defined in: handles/unit.ts:1430
Orders the unit to walk to a point and drop one of its items there.
Parameters
whichItem
The item, in the unit's inventory.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
boolean
True when the unit carries the item and took the order.
Remarks
A unit that cannot reach the point stops as close as it gets and keeps the item.
Native
dropItemTarget()
dropItemTarget(
whichItem,target):boolean
Defined in: handles/unit.ts:1444
Orders the unit to walk to a target and give it one of its items.
Parameters
whichItem
The item, in the unit's inventory.
target
The widget to give the item to, usually a unit.
Returns
boolean
True when the unit carries the item and took the order.
Remarks
A target with no free inventory slot gets the item dropped at its feet. A unit that cannot reach the target stops as close as it gets and keeps the item.
Native
enableAuras()
enableAuras(
enable,affectsUI):void
Defined in: handles/unit.ts:1457
Enables or disables the unit's auras.
Parameters
enable
boolean
True to enable the auras, false to disable them.
affectsUI
boolean
Whether the change also shows in the unit's interface.
Returns
void
Native
endAbilityCooldown()
endAbilityCooldown(
abilCode):void
Defined in: handles/unit.ts:1466
Ends the cooldown of one of the unit's abilities at once.
Parameters
abilCode
number
The ability's rawcode.
Returns
void
Native
BlzEndUnitAbilityCooldown (jassbot)
equip()
equip(
whichItem):boolean
Defined in: handles/unit.ts:1476
Equips an item on the unit.
Parameters
whichItem
The item to equip.
Returns
boolean
True when the item was equipped.
Native
equippedItem()
equippedItem(
slot):Item|undefined
Defined in: handles/unit.ts:1487
Gets the item equipped in one of the unit's loadout slots.
Parameters
slot
The loadout slot.
Returns
Item | undefined
The item, or undefined when the slot is empty.
Native
UnitItemInEquipmentSlot (jassbot)
Native
forceStopOrder()
forceStopOrder(
clearQueue):void
Defined in: handles/unit.ts:3344
Stops the unit's current order, through BlzUnitForceStopOrder.
Parameters
clearQueue
boolean
Also clears the queued orders.
Returns
void
Native
BlzUnitForceStopOrder (jassbot)
getAbility()
getAbility(
abilId):ability|undefined
Defined in: handles/unit.ts:1499
Gets the unit's instance of an ability, for the ability Natives.
Parameters
abilId
number
The ability's rawcode.
Returns
ability | undefined
The game's ability Handle, or undefined when the unit lacks the ability.
Native
getAbilityByIndex()
getAbilityByIndex(
index):ability|undefined
Defined in: handles/unit.ts:1509
Gets one of the unit's ability instances by its index, buffs included.
Parameters
index
number
The index, from 0: the ability added last is at 0.
Returns
ability | undefined
The game's ability Handle, or undefined past the last index.
Native
BlzGetUnitAbilityByIndex (jassbot)
getAbilityCooldown()
getAbilityCooldown(
abilId,level):number
Defined in: handles/unit.ts:1520
Gets the full cooldown of one of the unit's abilities at a level, not the time remaining.
Parameters
abilId
number
The ability's rawcode.
level
number
The ability level, counted from 0 (level 1 is 0).
Returns
number
The cooldown, in seconds.
Native
BlzGetUnitAbilityCooldown (jassbot)
getAbilityCooldownPercent()
getAbilityCooldownPercent(
abilId):number
Defined in: handles/unit.ts:1530
Gets the remaining cooldown of one of the unit's abilities as a share of its full cooldown.
Parameters
abilId
number
The ability's rawcode.
Returns
number
The share of the cooldown left.
Native
BlzGetUnitAbilityCooldownPercent (jassbot)
getAbilityCooldownRemaining()
getAbilityCooldownRemaining(
abilId):number
Defined in: handles/unit.ts:1542
Gets the remaining cooldown of one of the unit's abilities.
Parameters
abilId
number
The ability's rawcode.
Returns
number
The time left, in seconds; 0 when the ability is ready.
Native
BlzGetUnitAbilityCooldownRemaining (jassbot)
Bug
During the cooldown of an ability built on Channel, it sometimes gives 0.
getAbilityLevel()
getAbilityLevel(
abilCode):number
Defined in: handles/unit.ts:1553
Gets the level the unit has in one of its abilities.
Parameters
abilCode
number
The ability's rawcode.
Returns
number
The level, from 1; 0 when the unit lacks the ability.
Remarks
Levels count from 1, not from 0.
Native
getAbilityManaCost()
getAbilityManaCost(
abilId,level):number
Defined in: handles/unit.ts:1564
Gets the mana cost of one of the unit's abilities at a level.
Parameters
abilId
number
The ability's rawcode.
level
number
The ability level, counted from 0 (level 1 is 0).
Returns
number
The mana cost.
Native
BlzGetUnitAbilityManaCost (jassbot)
getAgility()
getAgility(
includeBonuses):number
Defined in: handles/unit.ts:1574
Gets the hero's agility.
Parameters
includeBonuses
boolean
True to add the bonuses of items and buffs.
Returns
number
The agility; 0 for a unit that is not a hero.
Native
getAnimationDuration()
getAnimationDuration(
animation):number
Defined in: handles/unit.ts:1585
Gets the duration of one of the animations of the unit's model.
Parameters
animation
string | number
The animation's name, or its index in the model.
Returns
number
The duration, in seconds.
Native
BlzGetUnitAnimationDuration (jassbot)
Native
BlzGetUnitAnimationDurationByIndex (jassbot)
getAttackCooldown()
getAttackCooldown(
weaponIndex):number
Defined in: handles/unit.ts:1599
Gets the base cooldown of one of the unit's attacks, without the bonuses of items, agility and buffs.
Parameters
weaponIndex
number
The attack, 0 or 1.
Returns
number
The cooldown, in seconds.
Native
BlzGetUnitAttackCooldown (jassbot)
getBaseDamage()
getBaseDamage(
weaponIndex):number
Defined in: handles/unit.ts:1609
Gets the base damage of one of the unit's attacks, added to the dice roll.
Parameters
weaponIndex
number
The attack, 0 or 1.
Returns
number
The base damage.
Native
BlzGetUnitBaseDamage (jassbot)
getDiceNumber()
getDiceNumber(
weaponIndex):number
Defined in: handles/unit.ts:1619
Gets the number of dice one of the unit's attacks rolls for its damage.
Parameters
weaponIndex
number
The attack, 0 or 1.
Returns
number
The number of dice.
Native
BlzGetUnitDiceNumber (jassbot)
getDiceSides()
getDiceSides(
weaponIndex):number
Defined in: handles/unit.ts:1629
Gets the number of sides of the dice one of the unit's attacks rolls for its damage.
Parameters
weaponIndex
number
The attack, 0 or 1.
Returns
number
The number of sides.
Native
getField()
getField(
field):string|number|boolean|undefined
Defined in: handles/unit.ts:1645
Reads one of the unit's fields, through the Native of the field's type.
Parameters
field
unitbooleanfield | unitintegerfield | unitrealfield | unitstringfield
A field constant of any of the four types, such as UNIT_RF_SELECTION_SCALE.
Returns
string | number | boolean | undefined
The field's value, as a boolean, a number or a string, or 0 for a constant of no known field type.
Remarks
Many fields do not work: the game ignores them.
Native
BlzGetUnitBooleanField (jassbot)
Native
BlzGetUnitIntegerField (jassbot)
Native
Native
BlzGetUnitStringField (jassbot)
getFlyHeight()
getFlyHeight():
number
Defined in: handles/unit.ts:1684
Gets the unit's flying height above the ground.
Returns
number
The height, in world units.
Remarks
In w3ts 3.x it was named getflyHeight, with a lowercase f.
Native
getHeroLevel()
getHeroLevel():
number
Defined in: handles/unit.ts:1693
Gets the hero's level.
Returns
number
The level; 0 for a unit that is not a hero.
Native
getIntelligence()
getIntelligence(
includeBonuses):number
Defined in: handles/unit.ts:1703
Gets the hero's intelligence.
Parameters
includeBonuses
boolean
True to add the bonuses of items and buffs.
Returns
number
The intelligence; 0 for a unit that is not a hero.
Native
getItemInSlot()
getItemInSlot(
slot):Item|undefined
Defined in: handles/unit.ts:1713
Gets the item in one of the unit's inventory slots.
Parameters
slot
number
The slot, from 0 to 5.
Returns
Item | undefined
The item, or undefined when the slot is empty or the unit has no such slot.
Native
getOwner()
getOwner():
MapPlayer
Defined in: handles/unit.ts:2978
Gets the player who owns the unit.
Returns
The owner, never undefined.
Remarks
A live unit always has an owner, which the Typings cannot express for the Wrapper, so this goes through the non-null lookup helper: typed non-null, and not counted as a creation.
Throws
Should the game ever break that invariant:
reforged-ts: failed to create MapPlayer, at the calling line.
Native
getPoint()
getPoint():
Point
Defined in: handles/unit.ts:3001
Gets the unit's position as a new point, which the caller destroys.
Returns
A new point at the unit's position.
Throws
When the game returns no handle: reforged-ts: failed to create Point,
at the calling line. In Dev mode, also before the globals Init stage and
inside MapPlayer.runLocal.
Native
Bug
For a unit loaded into a zeppelin, it returns where the unit boarded, not the zeppelin's position.
getState()
getState(
whichUnitState):number
Defined in: handles/unit.ts:1724
Gets one of the unit's states, such as its life or mana.
Parameters
whichUnitState
unitstate
The state, such as UNIT_STATE_LIFE or UNIT_STATE_MAX_MANA.
Returns
number
The value, in the state's own unit: hit points for
UNIT_STATE_LIFE, mana for UNIT_STATE_MANA.
Native
getStrength()
getStrength(
includeBonuses):number
Defined in: handles/unit.ts:1734
Gets the hero's strength.
Parameters
includeBonuses
boolean
True to add the bonuses of items and buffs.
Returns
number
The strength; 0 for a unit that is not a hero.
Native
getWeaponField()
getWeaponField(
field,index):string|number|boolean|undefined
Defined in: handles/unit.ts:3361
Reads a field of one of the unit's weapons, through the
BlzGetUnitWeapon*Field Native of the field's type.
Parameters
field
unitweaponbooleanfield | unitweaponintegerfield | unitweaponrealfield | unitweaponstringfield
A weapon field constant of any of the four field types.
index
number
The weapon's index.
Returns
string | number | boolean | undefined
The field's value, as a boolean, a number or a string, or 0 for a constant of no known field type.
Native
BlzGetUnitWeaponBooleanField (jassbot)
Native
BlzGetUnitWeaponIntegerField (jassbot)
Native
BlzGetUnitWeaponRealField (jassbot)
Native
BlzGetUnitWeaponStringField (jassbot)
Bug
A unit without any attack can make it crash the game.
hasAnyEquipped()
hasAnyEquipped():
boolean
Defined in: handles/unit.ts:1745
Checks whether the unit has any item equipped.
Returns
boolean
True when an item is equipped.
Remarks
The Native's name is misspelt: UnitHasAnyItemEquiped.
Native
UnitHasAnyItemEquiped (jassbot)
hasBagged()
hasBagged(
whichItem):boolean
Defined in: handles/unit.ts:1755
Checks whether an item is in the unit's bag.
Parameters
whichItem
The item to look for in the bag.
Returns
boolean
True when the item is in the bag.
Native
hasBuffs()
hasBuffs(
removePositive,removeNegative,magic,physical,timedLife,aura,autoDispel):boolean
Defined in: handles/unit.ts:1775
Checks whether the unit has any buff that matches the filters.
Parameters
removePositive
boolean
Matches positive buffs; with removeNegative, both
false matches positive and negative buffs.
removeNegative
boolean
Matches negative buffs.
magic
boolean
Matches only magical buffs, unless physical is true too, which
matches none; both false matches magical and physical buffs.
physical
boolean
Matches only physical buffs, unless magic is true too.
timedLife
boolean
Includes timed-life buffs; false leaves them out.
aura
boolean
Includes aura buffs; false leaves them out.
autoDispel
boolean
Matches only the buffs that dispelling removes.
Returns
boolean
True when a buff matches.
Remarks
The filters combine as in countBuffs.
Native
hasEmptySlot()
hasEmptySlot(
slot):boolean
Defined in: handles/unit.ts:1803
Checks whether one of the unit's loadout slots is empty.
Parameters
slot
The loadout slot.
Returns
boolean
True when the slot is empty.
Native
UnitHasLoadoutSlotEmpty (jassbot)
Native
hasEquipmentOfType()
hasEquipmentOfType(
equipmentType):boolean
Defined in: handles/unit.ts:1814
Checks whether the unit has an item of an equipment type equipped.
Parameters
equipmentType
The equipment type.
Returns
boolean
True when such an item is equipped.
Native
UnitHasItemEquipmentOfType (jassbot)
Native
ConvertEquipmentType (jassbot)
hasEquipped()
hasEquipped(
whichItem):boolean
Defined in: handles/unit.ts:1827
Checks whether the unit has an item equipped.
Parameters
whichItem
The item to look for among the equipped ones.
Returns
boolean
True when the item is equipped.
Native
hasItem()
hasItem(
whichItem):boolean
Defined in: handles/unit.ts:1837
Checks whether an item is in the unit's inventory.
Parameters
whichItem
The item to look for in the inventory's slots.
Returns
boolean
True when the unit carries the item.
Native
hideAbility()
hideAbility(
abilId,flag):void
Defined in: handles/unit.ts:1849
Hides or shows the icon of one of the unit's abilities.
Parameters
abilId
number
The ability's rawcode.
flag
boolean
True to hide the icon, false to show it.
Returns
void
Native
Bug
The game counts the calls instead of storing the flag: after hiding an icon several times, as many calls are needed to show it again.
incAbilityLevel()
incAbilityLevel(
abilCode):number
Defined in: handles/unit.ts:1863
Raises one of the unit's abilities by one level.
Parameters
abilCode
number
The ability's rawcode, such as FourCC("AHbz").
Returns
number
The new ability level.
Remarks
It can take an ability one level past its maximum, where every field of the ability is 0. Sources: http://www.wc3c.net/showthread.php?p=1029039#post1029039 and http://www.hiveworkshop.com/forums/lab-715/silenceex-everything-you-dont-know-about-silence-274351/.
Native
inForce()
inForce(
whichForce):boolean
Defined in: handles/unit.ts:1873
Checks whether the unit's owner is in a force.
Parameters
whichForce
The force to look for the unit's owner in.
Returns
boolean
True when the unit's owner belongs to the force.
Native
inGroup()
inGroup(
whichGroup):boolean
Defined in: handles/unit.ts:1883
Checks whether the unit is in a group.
Parameters
whichGroup
The group to look for the unit in.
Returns
boolean
True when the group holds the unit.
Native
inRange()
inRange(
x,y,distance):boolean
Defined in: handles/unit.ts:1895
Checks whether the unit is within a distance of a point, counting its collision size.
Parameters
x
number
The point's x-coordinate, in world units.
y
number
The point's y-coordinate, in world units.
distance
number
The distance, in world units.
Returns
boolean
True when the unit is in range.
Native
inRangeOfPoint()
inRangeOfPoint(
whichPoint,distance):boolean
Defined in: handles/unit.ts:1906
Checks whether the unit is within a distance of a point, counting its collision size.
Parameters
whichPoint
The point to measure the distance from.
distance
number
The distance, in world units.
Returns
boolean
True when the unit is in range.
Native
inRangeOfUnit()
inRangeOfUnit(
otherUnit,distance):boolean
Defined in: handles/unit.ts:1917
Checks whether the unit is within a distance of another unit, counting its collision size.
Parameters
otherUnit
Unit
The unit to measure the distance from.
distance
number
The distance, in world units.
Returns
boolean
True when the unit is in range.
Native
interruptAttack()
interruptAttack():
void
Defined in: handles/unit.ts:1925
Interrupts the attack the unit is winding up.
Returns
void
Native
BlzUnitInterruptAttack (jassbot)
inTransport()
inTransport(
whichTransport):boolean
Defined in: handles/unit.ts:1936
Checks whether the unit is loaded into a transport.
Parameters
whichTransport
Unit
The transport to look in, such as a Goblin Zeppelin.
Returns
boolean
True when the unit is loaded into that transport.
Native
isAlive()
isAlive():
boolean
Defined in: handles/unit.ts:1945
Checks whether the unit is alive.
Returns
boolean
True when the unit is alive; false once it died or was removed.
Native
isAlly()
isAlly(
whichPlayer):boolean
Defined in: handles/unit.ts:1955
Checks whether the unit's owner is an ally of a player.
Parameters
whichPlayer
The player to compare the unit's owner with.
Returns
boolean
True when the unit is the player's ally.
Native
isDetected()
isDetected(
whichPlayer):boolean
Defined in: handles/unit.ts:3407
Checks whether a player detects the unit, as a detector reveals an invisible unit.
Parameters
whichPlayer
The player whose detection decides.
Returns
boolean
True when the player detects the unit.
Native
isEnemy()
isEnemy(
whichPlayer):boolean
Defined in: handles/unit.ts:1965
Checks whether the unit's owner is an enemy of a player.
Parameters
whichPlayer
The player to compare the unit's owner with.
Returns
boolean
True when the unit is the player's enemy.
Native
isExperienceSuspended()
isExperienceSuspended():
boolean
Defined in: handles/unit.ts:1974
Checks whether the hero gains no experience, as suspendExperience sets.
Returns
boolean
True when the hero's experience is suspended.
Native
isFogged()
isFogged(
whichPlayer):boolean
Defined in: handles/unit.ts:1984
Checks whether the unit stands in the fog of war for a player.
Parameters
whichPlayer
The player whose view of the map decides.
Returns
boolean
True when the unit is fogged for the player.
Native
isHero()
isHero():
boolean
Defined in: handles/unit.ts:1994
Checks whether the unit's type is a hero type.
Returns
boolean
True when the unit is a hero.
Native
Native
isIllusion()
isIllusion():
boolean
Defined in: handles/unit.ts:2003
Checks whether the unit is an illusion.
Returns
boolean
True when the unit is an illusion.
Native
isInvisible()
isInvisible(
whichPlayer):boolean
Defined in: handles/unit.ts:3417
Checks whether the unit is invisible to a player.
Parameters
whichPlayer
The player whose view of the map decides.
Returns
boolean
True when the unit is invisible to the player.
Native
isLoaded()
isLoaded():
boolean
Defined in: handles/unit.ts:2012
Checks whether the unit is loaded into a transport.
Returns
boolean
True when the unit is loaded.
Native
isMasked()
isMasked(
whichPlayer):boolean
Defined in: handles/unit.ts:2023
Checks whether the unit stands under the black mask for a player, in the part of the map that player has never explored.
Parameters
whichPlayer
The player whose view of the map decides.
Returns
boolean
True when the unit is masked for the player.
Native
isOwnedByPlayer()
isOwnedByPlayer(
whichPlayer):boolean
Defined in: handles/unit.ts:3427
Checks whether a player owns the unit.
Parameters
whichPlayer
The player to compare with the unit's owner.
Returns
boolean
True when the player owns the unit.
Native
isRace()
isRace(
whichRace):boolean
Defined in: handles/unit.ts:3437
Checks whether the unit's type is of a race.
Parameters
whichRace
race
The race, such as RACE_HUMAN.
Returns
boolean
True when the unit is of the race.
Native
isSelected()
isSelected(
whichPlayer):boolean
Defined in: handles/unit.ts:2033
Checks whether a player has the unit selected.
Parameters
whichPlayer
The player whose selection is read.
Returns
boolean
True when the unit is in the player's selection.
Native
issueBuildOrder()
issueBuildOrder(
unit,x,y):boolean
Defined in: handles/unit.ts:2048
Orders the unit to build a structure at a point.
Parameters
unit
string | number
The structure's order name, or its unit type's rawcode.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
boolean
True when the unit took the order.
Native
Native
Bug
It returns true for a structure the unit can build on a free spot, even when the player cannot afford it.
issueImmediateOrder()
issueImmediateOrder(
order):boolean
Defined in: handles/unit.ts:2061
Orders the unit to carry out an order that takes no target, such as "stop".
Parameters
order
string | OrderId
The order's name, or its id.
Returns
boolean
True when the unit took the order.
Native
Native
IssueImmediateOrderById (jassbot)
issueInstantOrderAt()
issueInstantOrderAt(
order,x,y,instantTargetWidget):boolean
Defined in: handles/unit.ts:2077
Orders the unit to carry out an order at a point, with a widget as its instant target.
Parameters
order
string | OrderId
The order's name, or its id.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
instantTargetWidget
The instant target.
Returns
boolean
True when the unit took the order.
Native
IssueInstantPointOrder (jassbot)
Native
IssueInstantPointOrderById (jassbot)
issueInstantTargetOrder()
issueInstantTargetOrder(
order,targetWidget,instantTargetWidget):boolean
Defined in: handles/unit.ts:2109
Orders the unit to carry out an order on a target, with another widget as its instant target.
Parameters
order
string | OrderId
The order's name, or its id.
targetWidget
The order's target.
instantTargetWidget
The instant target.
Returns
boolean
True when the unit took the order.
Native
IssueInstantTargetOrder (jassbot)
Native
IssueInstantTargetOrderById (jassbot)
issueNeutralImmediateOrder()
issueNeutralImmediateOrder(
forPlayer,unit):boolean
Defined in: handles/unit.ts:2138
Orders this neutral structure (a shop, a tavern) to sell or train unit for
forPlayer.
Parameters
forPlayer
The player who buys.
unit
string | number
The order name of what is bought, or its rawcode.
Returns
boolean
True when the structure took the order.
Native
IssueNeutralImmediateOrder (jassbot)
Native
IssueNeutralImmediateOrderById (jassbot)
issueNeutralPointOrder()
issueNeutralPointOrder(
forPlayer,unit,x,y):boolean
Defined in: handles/unit.ts:2157
Orders this neutral structure to use unit for forPlayer at a point.
Parameters
forPlayer
The player the structure acts for.
unit
string | number
The order's name, or its id.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
boolean
True when the structure took the order.
Native
IssueNeutralPointOrder (jassbot)
Native
IssueNeutralPointOrderById (jassbot)
issueNeutralTargetOrder()
issueNeutralTargetOrder(
forPlayer,unit,target):boolean
Defined in: handles/unit.ts:2177
Orders this neutral structure to use unit for forPlayer on target.
Parameters
forPlayer
The player the structure acts for.
unit
string | number
The order's name, or its id.
target
The order's target.
Returns
boolean
True when the structure took the order.
Native
IssueNeutralTargetOrder (jassbot)
Native
IssueNeutralTargetOrderById (jassbot)
issueOrderAt()
issueOrderAt(
order,x,y):boolean
Defined in: handles/unit.ts:2207
Orders the unit to carry out an order at a point, such as "move".
Parameters
order
string | OrderId
The order's name, or its id.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
boolean
True when the unit took the order.
Native
Native
Bug
For a build order it returns false, whether or not the unit obeys.
issuePointOrder()
issuePointOrder(
order,whichPoint):boolean
Defined in: handles/unit.ts:2222
Orders the unit to carry out an order at a point, such as "move".
Parameters
order
string | OrderId
The order's name, or its id.
whichPoint
The point the order targets.
Returns
boolean
True when the unit took the order.
Native
Native
IssuePointOrderByIdLoc (jassbot)
Bug
For a build order it returns false, whether or not the unit obeys.
issueTargetOrder()
issueTargetOrder(
order,targetWidget):boolean
Defined in: handles/unit.ts:2236
Orders the unit to carry out an order on a target, such as "attack".
Parameters
order
string | OrderId
The order's name, or its id.
targetWidget
The order's target.
Returns
boolean
True when the unit took the order.
Native
Native
IssueTargetOrderById (jassbot)
isUnit()
isUnit(
whichSpecifiedUnit):boolean
Defined in: handles/unit.ts:2249
Checks whether another Wrapper wraps the same unit.
Parameters
whichSpecifiedUnit
Unit
The other unit.
Returns
boolean
True when both are the same unit.
Remarks
Useless. Use operator == instead.
Native
isUnitType()
isUnitType(
whichUnitType):boolean
Defined in: handles/unit.ts:2265
Checks whether the unit has a classification, such as UNIT_TYPE_STRUCTURE.
Parameters
whichUnitType
unittype
The classification.
Returns
boolean
True when the unit has it.
Remarks
- Read as an integer, the boolean the Native returns can be above 1, likely because the game keeps the classifications in a bit set.
- On older patches it misbehaved inside condition functions, which a
comparison with
trueworked around; the fault does not reproduce on patch 1.27.
Native
isVisible()
isVisible(
whichPlayer):boolean
Defined in: handles/unit.ts:2275
Checks whether a player can see the unit.
Parameters
whichPlayer
The player whose view of the map decides.
Returns
boolean
True when the unit is visible to the player.
Native
kill()
kill():
void
Defined in: handles/unit.ts:2284
Kills the unit with no killer: it plays its death animation and fires the death events, as a unit killed in combat does.
Returns
void
Native
lookAt()
lookAt(
whichBone,lookAtTarget,offsetX,offsetY,offsetZ):void
Defined in: handles/unit.ts:2314
Turns one of the unit's bones to face a point offset from another unit,
until resetLookAt releases it.
Parameters
whichBone
string
Which bone turns: a string starting with
"bone_chest" picks the chest, any other string that is not null the
head. Leading spaces are skipped, case does not matter, and the string
ends at its first space after them.
lookAtTarget
Unit
The unit the bone faces.
offsetX
number
The x-offset of the point faced, from the target's origin.
offsetY
number
The y-offset of the point faced, from the target's origin.
offsetZ
number
The z-offset of the point faced, from the target's origin; the terrain's height is already counted in.
Returns
void
Remarks
- One bone at a time faces the target: the head or the chest, never both.
- Only the head and chest bones turn; any other choice turns the head.
The game finds them by the helpers named
"Bone_Head"and"Bone_Chest"in the model, so a helper renamed to one of those turns its own set of bones instead. - The animation speed and the blend time affect the turn.
- Setting a unit's facing at once, on wc3c: http://www.wc3c.net/showthread.php?t=105830
Native
makeAbilityPermanent()
makeAbilityPermanent(
permanent,abilityId):void
Defined in: handles/unit.ts:2338
Makes one of the unit's abilities survive a morph, or lets a morph remove it.
Parameters
permanent
boolean
True to keep the ability through a morph, false to let the morph remove it.
abilityId
number
The ability's rawcode.
Returns
void
Native
UnitMakeAbilityPermanent (jassbot)
modifySkillPoints()
modifySkillPoints(
skillPointDelta):boolean
Defined in: handles/unit.ts:2351
Adds skill points to the hero, or removes them with a negative delta, down to 0.
Parameters
skillPointDelta
number
The points to add; negative to remove.
Returns
boolean
False when nothing could change: a delta of 0, a unit that is not a hero, or points to remove from a hero that has none; true otherwise.
Remarks
The hero never gets more points than it can still spend on its abilities.
Native
UnitModifySkillPoints (jassbot)
moveItemToSlot()
moveItemToSlot(
whichItem,slot):boolean
Defined in: handles/unit.ts:2366
Moves one of the unit's items to another slot of its inventory, swapping it with the item already there.
Parameters
whichItem
The item, in the unit's inventory.
slot
number
The slot to move it to, from 0 to 5.
Returns
boolean
True when the item was moved, or was already in that slot.
Remarks
In w3ts 3.x it was named dropItemFromSlot, though it drops nothing on the
ground; it takes the same arguments.
Native
pauseEx()
pauseEx(
flag):void
Defined in: handles/unit.ts:2376
Pauses or unpauses the unit as the paused setter does, but keeps its command
card visible and leaves the paused getter false.
Parameters
flag
boolean
True to pause the unit, false to unpause it.
Returns
void
Native
pauseTimedLife()
pauseTimedLife(
flag):void
Defined in: handles/unit.ts:2385
Pauses or resumes the countdown of the unit's timed life.
Parameters
flag
boolean
True to pause the countdown, false to resume it.
Returns
void
Native
queueAnimation()
queueAnimation(
whichAnimation):void
Defined in: handles/unit.ts:2394
Queues an animation to play once the current one ends, for a smooth transition.
Parameters
whichAnimation
string
The animation's name, such as "stand", in any case.
Returns
void
Native
queueBuildOrder()
queueBuildOrder(
unitId,x,y):boolean
Defined in: handles/unit.ts:3451
Queues an order to build a structure at a point, after the unit's current orders.
Parameters
unitId
number
The structure's unit type rawcode.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
boolean
True when the unit took the order.
Native
BlzQueueBuildOrderById (jassbot)
Bug
It returns true for a structure the unit can build on a free spot, even when the player cannot afford it.
queueImmediateOrder()
queueImmediateOrder(
order):boolean
Defined in: handles/unit.ts:3461
Queues an order that takes no target, after the unit's current orders.
Parameters
order
The order's id.
Returns
boolean
True when the unit took the order.
Native
BlzQueueImmediateOrderById (jassbot)
queueInstantOrderAt()
queueInstantOrderAt(
order,x,y,instantTargetWidget):boolean
Defined in: handles/unit.ts:3474
Queues an order at a point, with a widget as its instant target, after the unit's current orders.
Parameters
order
The order's id.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
instantTargetWidget
The instant target.
Returns
boolean
True when the unit took the order.
Native
BlzQueueInstantPointOrderById (jassbot)
queueInstantTargetOrder()
queueInstantTargetOrder(
order,targetWidget,instantTargetWidget):boolean
Defined in: handles/unit.ts:3498
Queues an order on a target, with another widget as its instant target, after the unit's current orders.
Parameters
order
The order's id.
targetWidget
The order's target.
instantTargetWidget
The instant target.
Returns
boolean
True when the unit took the order.
Native
BlzQueueInstantTargetOrderById (jassbot)
queueNeutralImmediateOrder()
queueNeutralImmediateOrder(
forPlayer,unitId):boolean
Defined in: handles/unit.ts:2406
Queues an order on this neutral structure to sell or train unitId for
forPlayer, after its current orders.
Parameters
forPlayer
The player who buys.
unitId
number
The rawcode of what is bought.
Returns
boolean
True when the structure took the order.
Native
BlzQueueNeutralImmediateOrderById (jassbot)
queueNeutralPointOrder()
queueNeutralPointOrder(
forPlayer,unitId,x,y):boolean
Defined in: handles/unit.ts:2424
Queues an order on this neutral structure to use unitId for
forPlayer at a point, after its current orders.
Parameters
forPlayer
The player the structure acts for.
unitId
number
The order's id.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
boolean
True when the structure took the order.
Native
BlzQueueNeutralPointOrderById (jassbot)
queueNeutralTargetOrder()
queueNeutralTargetOrder(
forPlayer,unitId,target):boolean
Defined in: handles/unit.ts:2448
Queues an order on this neutral structure to use unitId for
forPlayer on target, after its current orders.
Parameters
forPlayer
The player the structure acts for.
unitId
number
The order's id.
target
The order's target.
Returns
boolean
True when the structure took the order.
Native
BlzQueueNeutralTargetOrderById (jassbot)
queueOrderAt()
queueOrderAt(
order,x,y):boolean
Defined in: handles/unit.ts:3520
Queues an order at a point, after the unit's current orders.
Parameters
order
The order's id.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
boolean
True when the unit took the order.
Native
BlzQueuePointOrderById (jassbot)
Bug
For a build order it returns false, whether or not the unit obeys.
queueTargetOrder()
queueTargetOrder(
order,targetWidget):boolean
Defined in: handles/unit.ts:3531
Queues an order on a target, after the unit's current orders.
Parameters
order
The order's id.
targetWidget
The order's target.
Returns
boolean
True when the unit took the order.
Native
BlzQueueTargetOrderById (jassbot)
recycleGuardPosition()
recycleGuardPosition():
void
Defined in: handles/unit.ts:2465
Releases the unit's guard position, the spot the computer player's AI keeps it at, for the AI to reuse.
Returns
void
Native
RecycleGuardPosition (jassbot)
removeAbility()
removeAbility(
abilityId):boolean
Defined in: handles/unit.ts:2475
Removes an ability from the unit.
Parameters
abilityId
number
The ability's rawcode.
Returns
boolean
True when the ability was removed, false when the unit lacks it.
Native
removeBuffs()
removeBuffs(
removePositive,removeNegative):void
Defined in: handles/unit.ts:2485
Removes the unit's positive buffs, negative buffs or both, timed-life and aura buffs included.
Parameters
removePositive
boolean
Removes the positive buffs.
removeNegative
boolean
Removes the negative buffs.
Returns
void
Native
removeBuffsEx()
removeBuffsEx(
removePositive,removeNegative,magic,physical,timedLife,aura,autoDispel):void
Defined in: handles/unit.ts:2504
Removes the buffs on the unit that match the filters.
Parameters
removePositive
boolean
Removes positive buffs.
removeNegative
boolean
Removes negative buffs.
magic
boolean
Removes only magical buffs, unless physical is true too, which
matches none; both false removes magical, physical and other buffs.
physical
boolean
Removes only physical buffs, unless magic is true too.
timedLife
boolean
Includes timed-life buffs; false leaves them out.
aura
boolean
Includes aura buffs; false leaves them out.
autoDispel
boolean
Removes only the buffs that dispelling removes.
Returns
void
Remarks
The filters combine differently here than in countBuffs: see
the Native's reference.
Native
removeGuardPosition()
removeGuardPosition():
void
Defined in: handles/unit.ts:2529
Makes the computer player's AI ignore the unit's guard position, the spot the unit returns to.
Returns
void
Native
removeItem()
removeItem(
whichItem):void
Defined in: handles/unit.ts:2538
Drops an item the unit carries onto the ground where the unit stands.
Parameters
whichItem
The item, in the unit's inventory.
Returns
void
Native
removeItemFromSlot()
removeItemFromSlot(
itemSlot):Item|undefined
Defined in: handles/unit.ts:2549
Drops the item in one of the unit's inventory slots onto the ground where the unit stands.
Parameters
itemSlot
number
The slot, from 0 to 5.
Returns
Item | undefined
The dropped item, or undefined when the slot is empty or does not exist.
Native
UnitRemoveItemFromSlot (jassbot)
removeItemFromStock()
removeItemFromStock(
itemId):void
Defined in: handles/unit.ts:2558
Removes an item type from the stock of the shop.
Parameters
itemId
number
The item type's rawcode.
Returns
void
Native
removeType()
removeType(
whichUnitType):boolean
Defined in: handles/unit.ts:2568
Removes a classification from the unit, such as UNIT_TYPE_UNDEAD.
Parameters
whichUnitType
unittype
The classification to remove.
Returns
boolean
True when the game removed it.
Native
removeUnitFromStock()
removeUnitFromStock(
unitId):void
Defined in: handles/unit.ts:2578
Removes a unit type from the stock of the shop.
Parameters
unitId
number
The rawcode of the unit type to remove, such as
FourCC("hfoo").
Returns
void
Native
resetAttack()
resetAttack(
weaponIndex):void
Defined in: handles/unit.ts:2587
Resets one of the unit's attacks.
Parameters
weaponIndex
number
The attack, 0 or 1.
Returns
void
Native
resetCooldown()
resetCooldown():
void
Defined in: handles/unit.ts:2595
Ends the cooldowns of all of the unit's abilities.
Returns
void
Native
resetLookAt()
resetLookAt():
void
Defined in: handles/unit.ts:2604
Releases the bone that lookAt turned, so that the unit's animations
move it again.
Returns
void
Native
revive()
revive(
x,y,doEyecandy):boolean
Defined in: handles/unit.ts:2618
Revives the dead hero at a point.
Parameters
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
doEyecandy
boolean
True to play the revival effect and sound.
Returns
boolean
True when the hero was dead and revived.
Remarks
A hero with a food cost revives only when its owner has the food for it.
Native
reviveAtPoint()
reviveAtPoint(
whichPoint,doEyecandy):boolean
Defined in: handles/unit.ts:2631
Revives the dead hero at a point.
Parameters
whichPoint
Where the hero revives.
doEyecandy
boolean
True to play the revival effect and sound.
Returns
boolean
True when the hero was dead and revived.
Remarks
A hero with a food cost revives only when its owner has the food for it.
Native
select()
select(
flag):void
Defined in: handles/unit.ts:2641
Adds the unit to the selection, or removes it, on every client: to change one player's selection, call it for that player's client only.
Parameters
flag
boolean
True to select the unit, false to deselect it.
Returns
void
Native
selectSkill()
selectSkill(
abilCode):void
Defined in: handles/unit.ts:2651
Spends one of the hero's skill points to learn or level an ability; does nothing when the hero has no point or cannot learn it yet.
Parameters
abilCode
number
The ability's rawcode.
Returns
void
Native
setAbilityCooldown()
setAbilityCooldown(
abilId,level,cooldown):void
Defined in: handles/unit.ts:2664
Sets the full cooldown of one of the unit's abilities at a level.
Parameters
abilId
number
The ability's rawcode.
level
number
The ability level, counted from 0 (level 1 is 0).
cooldown
number
The cooldown, in seconds.
Returns
void
Remarks
A cooldown that is running keeps its length: the new one applies from the next use.
Native
BlzSetUnitAbilityCooldown (jassbot)
setAbilityCooldownPercent()
setAbilityCooldownPercent(
abilId,percent):void
Defined in: handles/unit.ts:2674
Sets the remaining cooldown of one of the unit's abilities as a share of its full cooldown.
Parameters
abilId
number
The ability's rawcode.
percent
number
The share of the full cooldown left.
Returns
void
Native
BlzSetUnitAbilityCooldownPercent (jassbot)
setAbilityCooldownRemaining()
setAbilityCooldownRemaining(
abilId,seconds):void
Defined in: handles/unit.ts:2684
Sets the remaining cooldown of one of the unit's abilities.
Parameters
abilId
number
The ability's rawcode.
seconds
number
The time left, in seconds.
Returns
void
Native
BlzSetUnitAbilityCooldownRemaining (jassbot)
setAbilityLevel()
setAbilityLevel(
abilCode,level):number
Defined in: handles/unit.ts:2697
Sets the level of an ability the unit has, without spending or refunding skill points.
Parameters
abilCode
number
The ability's rawcode.
level
number
The new level, from 1.
Returns
number
The new level, or 0 when the unit lacks the ability.
Remarks
A level below 1 sets level 1, and one above the ability's highest sets the highest.
Native
setAbilityManaCost()
setAbilityManaCost(
abilId,level,manaCost):void
Defined in: handles/unit.ts:2709
Sets the mana cost of one of the unit's abilities at a level.
Parameters
abilId
number
The ability's rawcode.
level
number
The ability level, counted from 0 (level 1 is 0).
manaCost
number
The mana the ability costs to cast at that level, a whole number.
Returns
void
Native
BlzSetUnitAbilityManaCost (jassbot)
setAgility()
setAgility(
value,permanent):void
Defined in: handles/unit.ts:2720
Sets the hero's base agility.
Parameters
value
number
The new base agility, without the bonuses of items and buffs.
permanent
boolean
True for a permanent change, as the agility setter makes.
Returns
void
Native
setAnimation()
setAnimation(
whichAnimation):void
Defined in: handles/unit.ts:2731
Plays one of the animations of the unit's model at once, cutting the current one.
Parameters
whichAnimation
string | number
The animation's name, such as "attack slam", in any
case; or its index in the model.
Returns
void
Native
Native
SetUnitAnimationByIndex (jassbot)
setAnimationWithRarity()
setAnimationWithRarity(
whichAnimation,rarity):void
Defined in: handles/unit.ts:2745
Plays one of the animations of the unit's model, picking among its variations by rarity.
Parameters
whichAnimation
string
The animation's name, in any case.
rarity
raritycontrol
The variations to pick from, RARITY_FREQUENT or RARITY_RARE.
Returns
void
Native
SetUnitAnimationWithRarity (jassbot)
setAttackCooldown()
setAttackCooldown(
cooldown,weaponIndex):void
Defined in: handles/unit.ts:2757
Sets the base cooldown of one of the unit's attacks.
Parameters
cooldown
number
The cooldown, in seconds.
weaponIndex
number
The attack, 0 or 1.
Returns
void
Remarks
w3ts 3.x also had setUnitAttackCooldown, a duplicate of this member.
Native
BlzSetUnitAttackCooldown (jassbot)
setBaseDamage()
setBaseDamage(
baseDamage,weaponIndex):void
Defined in: handles/unit.ts:2767
Sets the base damage of one of the unit's attacks, added to the dice roll.
Parameters
baseDamage
number
The damage added to every roll, a whole number.
weaponIndex
number
The attack, 0 or 1.
Returns
void
Native
BlzSetUnitBaseDamage (jassbot)
setBlendTime()
setBlendTime(
timeScale):void
Defined in: handles/unit.ts:2776
Sets the time the unit's model takes to blend from one animation into the next.
Parameters
timeScale
number
The blend time, in seconds.
Returns
void
Native
setConstructionProgress()
setConstructionProgress(
constructionPercentage):void
Defined in: handles/unit.ts:2785
Sets how far the construction of the structure has progressed.
Parameters
constructionPercentage
number
The progress, from 0 to 100.
Returns
void
Native
UnitSetConstructionProgress (jassbot)
setCreepGuard()
setCreepGuard(
creepGuard):void
Defined in: handles/unit.ts:2794
Sets whether the unit keeps to its guard position, as creeps do.
Parameters
creepGuard
boolean
True to keep the unit at its guard position.
Returns
void
Native
setDiceNumber()
setDiceNumber(
diceNumber,weaponIndex):void
Defined in: handles/unit.ts:2805
Sets the number of dice one of the unit's attacks rolls for its damage.
Parameters
diceNumber
number
The number of dice rolled on each hit, a whole number.
weaponIndex
number
The attack, 0 or 1.
Returns
void
Native
BlzSetUnitDiceNumber (jassbot)
setDiceSides()
setDiceSides(
diceSides,weaponIndex):void
Defined in: handles/unit.ts:2816
Sets the number of sides of the dice one of the unit's attacks rolls for its damage.
Parameters
diceSides
number
The number of sides of each die: a die rolls from 1 to this number.
weaponIndex
number
The attack, 0 or 1.
Returns
void
Native
setExperience()
setExperience(
newXpVal,showEyeCandy):void
Defined in: handles/unit.ts:2827
Sets the hero's experience points; reaching the experience a level needs gains that level.
Parameters
newXpVal
number
The new experience total, a whole number.
showEyeCandy
boolean
True to show the effects of a level gained this way.
Returns
void
Native
setExploded()
setExploded(
exploded):void
Defined in: handles/unit.ts:2836
Sets whether the unit explodes when it dies, leaving no corpse.
Parameters
exploded
boolean
True to make the unit explode on death.
Returns
void
Native
setFacingEx()
setFacingEx(
facingAngle):void
Defined in: handles/unit.ts:2845
Turns the unit to face an angle at once, where the facing setter turns it gradually.
Parameters
facingAngle
number
The facing, in degrees (0 east, 90 north).
Returns
void
Native
setFacingTimed()
setFacingTimed(
facingAngle,duration):void
Defined in: handles/unit.ts:3544
Turns the unit to face an angle, at a speed that duration can slow down.
Parameters
facingAngle
number
The facing, in degrees (0 east, 90 north).
duration
number
Below 1, the usual turn speed; from 1, a factor that slows the turn down.
Returns
void
Remarks
The turn ignores the unit's turn rate (turnSpeed).
Native
Bug
With a duration other than 0, the unit ends a few degrees off the angle asked for.
setField()
setField(
field,value):boolean
Defined in: handles/unit.ts:2862
Writes one of the unit's fields, through the Native of the field's type.
Parameters
field
unitbooleanfield | unitintegerfield | unitrealfield | unitstringfield
A field constant of any of the four types, such as UNIT_RF_SELECTION_SCALE.
value
string | number | boolean
The value, of the field's type: a boolean, a number or a string.
Returns
boolean
True when the game wrote the field; false when the value is not of the field's type.
Remarks
Many fields do not work: the game can report a write that changes nothing.
Native
BlzSetUnitBooleanField (jassbot)
Native
BlzSetUnitIntegerField (jassbot)
Native
Native
BlzSetUnitStringField (jassbot)
setFlyHeight()
setFlyHeight(
value,rate):void
Defined in: handles/unit.ts:2906
Changes the unit's flying height above the ground.
Parameters
value
number
The height, in world units.
rate
number
The speed of the change, in world units per second; 0 changes it at once.
Returns
void
Remarks
In w3ts 3.x it was named setflyHeight, with a lowercase f; it takes the
same arguments.
Native
setHeroLevel()
setHeroLevel(
level,showEyeCandy):void
Defined in: handles/unit.ts:2918
Raises the hero to a level; a lower level than the current one does nothing.
Parameters
level
number
The level to raise the hero to.
showEyeCandy
boolean
True to show the level-up text, sound and effect.
Returns
void
Remarks
The level stops at the hero's maximum level.
Native
setIgnoreAlarm()
setIgnoreAlarm(
flag):boolean
Defined in: handles/unit.ts:2932
Sets whether the unit raises no alarm, the "under attack" warning, when it is
attacked; ignoreAlarmToggled reads the setting.
Parameters
flag
boolean
True for no alarm, false for the usual one.
Returns
boolean
The boolean the game returns for the call.
Remarks
In w3ts 3.x it was named getIgnoreAlarm, though it changes the setting and
reads nothing; it takes the same argument.
Native
setIntelligence()
setIntelligence(
value,permanent):void
Defined in: handles/unit.ts:2943
Sets the hero's base intelligence.
Parameters
value
number
The new base intelligence, without the bonuses of items and buffs.
permanent
boolean
True for a permanent change, as the intelligence setter makes.
Returns
void
Native
setItemTypeSlots()
setItemTypeSlots(
slots):void
Defined in: handles/unit.ts:2952
Sets the number of item types the shop can offer.
Parameters
slots
number
How many different item types the shop lists at once.
Returns
void
Native
setOwner()
setOwner(
whichPlayer,changeColor?):void
Defined in: handles/unit.ts:2963
Gives the unit to another player.
Parameters
whichPlayer
The new owner.
changeColor?
boolean = true
True to give the unit the new owner's colour, when the owner changes; true when left out.
Returns
void
Native
setPathing()
setPathing(
flag):void
Defined in: handles/unit.ts:3010
Sets whether the unit follows pathing, or walks through anything.
Parameters
flag
boolean
True to follow pathing, false to ignore it.
Returns
void
Native
setPoint()
setPoint(
point):void
Defined in: handles/unit.ts:2987
Moves the unit to a point, to the nearest spot its pathing allows, cancelling its orders.
Parameters
point
The point to move the unit to.
Returns
void
Native
setPosition()
setPosition(
x,y):void
Defined in: handles/unit.ts:3022
Moves the unit to a point, to the nearest spot its pathing allows.
Parameters
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
void
Remarks
It cancels the unit's orders; setting x and y moves the unit
and keeps them.
Native
setRescuable()
setRescuable(
byWhichPlayer,flag):void
Defined in: handles/unit.ts:3033
Sets whether a player can rescue the unit, taking it over by coming near it.
Parameters
byWhichPlayer
The player who can, or no longer can, rescue the unit.
flag
boolean
True to make the unit rescuable by that player.
Returns
void
Native
setRescueRange()
setRescueRange(
range):void
Defined in: handles/unit.ts:3042
Sets how near a rescuing unit must come to rescue the unit.
Parameters
range
number
The range, in world units.
Returns
void
Native
setScale()
setScale(
scaleX,scaleY,scaleZ):void
Defined in: handles/unit.ts:3054
Scales the unit's model.
Parameters
scaleX
number
The scale, which the game applies on all three axes.
scaleY
number
Ignored.
scaleZ
number
Ignored.
Returns
void
Native
Bug
The game reads scaleX alone and scales every axis by it.
setState()
setState(
whichUnitState,newVal):void
Defined in: handles/unit.ts:3065
Sets one of the unit's states, such as its life or mana.
Parameters
whichUnitState
unitstate
The state, such as UNIT_STATE_LIFE or UNIT_STATE_MAX_MANA.
newVal
number
The new value, in the state's own unit: hit points for
UNIT_STATE_LIFE, mana for UNIT_STATE_MANA.
Returns
void
Native
setStrength()
setStrength(
value,permanent):void
Defined in: handles/unit.ts:3076
Sets the hero's base strength; lowering it lowers the hero's life.
Parameters
value
number
The new base strength, without the bonuses of items and buffs.
permanent
boolean
True for a permanent change, as the strength setter makes.
Returns
void
Native
setTimeScale()
setTimeScale(
timeScale):void
Defined in: handles/unit.ts:3085
Sets the speed of the unit's animations.
Parameters
timeScale
number
The speed factor: 1 for the normal speed, 2 for twice as fast.
Returns
void
Native
setUnitTypeSlots()
setUnitTypeSlots(
slots):void
Defined in: handles/unit.ts:3094
Sets the number of unit types the shop can offer.
Parameters
slots
number
How many different unit types the shop lists at once.
Returns
void
Native
setUpgradeProgress()
setUpgradeProgress(
upgradePercentage):void
Defined in: handles/unit.ts:3103
Sets how far the upgrade of the structure has progressed.
Parameters
upgradePercentage
number
The progress, from 0 to 100.
Returns
void
Native
UnitSetUpgradeProgress (jassbot)
setUseAltIcon()
setUseAltIcon(
flag):void
Defined in: handles/unit.ts:3112
Sets whether the minimap shows the unit with the alternate icon.
Parameters
flag
boolean
True to use the alternate icon.
Returns
void
Native
setUseFood()
setUseFood(
useFood):void
Defined in: handles/unit.ts:3121
Sets whether the unit counts in its owner's food.
Parameters
useFood
boolean
True to count the unit's food.
Returns
void
Native
setVertexColor()
setVertexColor(
red,green,blue,alpha):void
Defined in: handles/unit.ts:3133
Tints the unit's model with a colour and sets its transparency.
Parameters
red
number
The red channel, from 0 to 255.
green
number
The green channel, from 0 to 255.
blue
number
The blue channel, from 0 to 255.
alpha
number
The alpha channel, from 0 to 255.
Returns
void
Native
setWeaponField()
setWeaponField(
field,index,value):boolean
Defined in: handles/unit.ts:3563
Writes a field of one of the unit's weapons, through the
BlzSetUnitWeapon*Field Native of the field's type.
Parameters
field
unitweaponbooleanfield | unitweaponintegerfield | unitweaponrealfield | unitweaponstringfield
A weapon field constant of any of the four field types.
index
number
The weapon's index.
value
string | number | boolean
The value, of the field's type: a boolean, a number or a string.
Returns
boolean
True when the game wrote the field; false when the value is not of the field's type.
Remarks
Some fields do not work: the game can report a write that changes nothing.
Native
BlzSetUnitWeaponBooleanField (jassbot)
Native
BlzSetUnitWeaponIntegerField (jassbot)
Native
BlzSetUnitWeaponRealField (jassbot)
Native
BlzSetUnitWeaponStringField (jassbot)
shareVision()
shareVision(
whichPlayer,share):void
Defined in: handles/unit.ts:3149
Shares, or stops sharing, the unit's vision with a player.
Parameters
whichPlayer
The player who sees, or stops seeing, what the unit sees.
share
boolean
True to share the vision, false to stop.
Returns
void
Native
showTeamGlow()
showTeamGlow(
show):void
Defined in: handles/unit.ts:3158
Shows or hides the team-coloured glow of the unit, a hero's glow included.
Parameters
show
boolean
True to show the glow, false to hide it.
Returns
void
Native
startAbilityCooldown()
startAbilityCooldown(
abilCode,cooldown):void
Defined in: handles/unit.ts:3168
Starts the cooldown of one of the unit's abilities.
Parameters
abilCode
number
The ability's rawcode.
cooldown
number
The cooldown, in seconds.
Returns
void
Native
BlzStartUnitAbilityCooldown (jassbot)
stripLevels()
stripLevels(
howManyLevels):boolean
Defined in: handles/unit.ts:3179
Takes levels away from the hero, down to level 1, with the attributes and skill points they gave.
Parameters
howManyLevels
number
The number of levels to take away.
Returns
boolean
True when a level was taken away.
Native
suspendDecay()
suspendDecay(
suspend):void
Defined in: handles/unit.ts:3188
Stops, or resumes, the decay of the unit's corpse.
Parameters
suspend
boolean
True to stop the decay.
Returns
void
Native
suspendExperience()
suspendExperience(
flag):void
Defined in: handles/unit.ts:3197
Stops, or resumes, the hero's experience gain.
Parameters
flag
boolean
True to stop the gain.
Returns
void
Native
unequip()
unequip(
whichItem):void
Defined in: handles/unit.ts:3206
Unequips an item from the unit.
Parameters
whichItem
The item to unequip.
Returns
void
Native
unequipSlot()
unequipSlot(
slot):Item|undefined
Defined in: handles/unit.ts:3217
Unequips the item in one of the unit's loadout slots.
Parameters
slot
The loadout slot.
Returns
Item | undefined
The unequipped item, or undefined when the slot is empty.
Native
UnitUnequipItemFromSlot (jassbot)
Native
useItem()
useItem(
whichItem):boolean
Defined in: handles/unit.ts:3229
Orders the unit to use one of its items, as a click on it in the inventory does.
Parameters
whichItem
The item, in the unit's inventory.
Returns
boolean
True when the unit took the order.
Native
useItemAt()
useItemAt(
whichItem,x,y):boolean
Defined in: handles/unit.ts:3242
Orders the unit to use one of its items at a point.
Parameters
whichItem
The item, in the unit's inventory.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
boolean
The boolean the game returns.
Native
Bug
The game returns false even when the unit uses the item.
useItemTarget()
useItemTarget(
whichItem,target):boolean
Defined in: handles/unit.ts:3253
Orders the unit to use one of its items on a target.
Parameters
whichItem
The item, in the unit's inventory.
target
The widget the item is used on.
Returns
boolean
True when the unit took the order.
Native
wakeUp()
wakeUp():
void
Defined in: handles/unit.ts:3261
Wakes the unit up.
Returns
void
Native
waygateGetDestinationX()
waygateGetDestinationX():
number
Defined in: handles/unit.ts:3270
Gets the x-coordinate the waygate sends units to.
Returns
number
The x-coordinate, in world units; 0 for a unit without the Waygate ability.
Native
WaygateGetDestinationX (jassbot)
waygateGetDestinationY()
waygateGetDestinationY():
number
Defined in: handles/unit.ts:3279
Gets the y-coordinate the waygate sends units to.
Returns
number
The y-coordinate, in world units; 0 for a unit without the Waygate ability.
Native
WaygateGetDestinationY (jassbot)
waygateSetDestination()
waygateSetDestination(
x,y):void
Defined in: handles/unit.ts:3292
Sets the point the waygate sends units to; the unit needs the Waygate ability ('Awrp').
Parameters
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
Returns
void
Remarks
The game rounds each coordinate to the grid of 64 offset by 32: 0 becomes 32, 64 becomes 96.
Native
WaygateSetDestination (jassbot)
create()
staticcreate(owner,unitId,x,y,face?,skinId?):Unit
Defined in: handles/unit.ts:49
Creates a unit for owner at the given point, facing face.
Parameters
owner
The player who owns the unit.
unitId
number
The unit type's rawcode, such as FourCC("hfoo").
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
face?
number = bj_UNIT_FACING
The facing, in degrees; 270 (bj_UNIT_FACING) when left out.
skinId?
number
The skin's rawcode; the unit type's own model when left out.
Returns
Unit
The new unit.
Throws
When the game returns no handle, for example an unknown rawcode:
reforged-ts: failed to create Unit (<rawcode>), at the calling line. In Dev
mode, also before the globals Init stage and inside MapPlayer.runLocal.
Native
Native
BlzCreateUnitWithSkin (jassbot)
createAtPoint()
staticcreateAtPoint(owner,unitId,where,face?):Unit
Defined in: handles/unit.ts:77
Creates a unit for owner at a point, facing face.
Parameters
owner
The player who owns the unit.
unitId
number
The unit type's rawcode, such as FourCC("hfoo").
where
Where the unit stands.
face?
number = bj_UNIT_FACING
The facing, in degrees; 270 (bj_UNIT_FACING) when left out.
Returns
Unit
The new unit.
Throws
When the game returns no handle, for example an unknown rawcode:
reforged-ts: failed to create Unit (<rawcode>), at the calling line. In Dev
mode, also before the globals Init stage and inside MapPlayer.runLocal.
Native
createAtPointByName()
staticcreateAtPointByName(owner,unitName,where,face?):Unit
Defined in: handles/unit.ts:101
Creates a unit for owner at a point from the unit type's order name.
Parameters
owner
The player who owns the unit.
unitName
string
The unit type's order name, such as "footman".
where
Where the unit stands.
face?
number = bj_UNIT_FACING
The facing, in degrees; 270 (bj_UNIT_FACING) when left out.
Returns
Unit
The new unit.
Throws
When the game returns no handle, for example an unknown name:
reforged-ts: failed to create Unit (<unitName>), at the calling line. In Dev
mode, also before the globals Init stage and inside MapPlayer.runLocal.
Native
CreateUnitAtLocByName (jassbot)
createBlightedGoldmine()
staticcreateBlightedGoldmine(owner,x,y,face?):Unit
Defined in: handles/unit.ts:128
Creates an undead haunted gold mine, which spreads blight around it.
Parameters
owner
The player who owns the gold mine.
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
face?
number = bj_UNIT_FACING
The facing, in degrees; 270 (bj_UNIT_FACING) when left out.
Returns
Unit
The new gold mine.
Remarks
The mine holds the gold that the Gold Mine ability ('Agld') sets, and it
turns back into a normal gold mine when it is destroyed.
Throws
When the game returns no handle: reforged-ts: failed to create Unit,
at the calling line. In Dev mode, also before the globals Init stage and
inside MapPlayer.runLocal.
Native
CreateBlightedGoldmine (jassbot)
createByName()
staticcreateByName(owner,unitName,x,y,face?):Unit
Defined in: handles/unit.ts:150
Creates a unit for owner from the unit type's order name.
Parameters
owner
The player who owns the unit.
unitName
string
The unit type's order name, such as "footman".
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
face?
number = bj_UNIT_FACING
The facing, in degrees; 270 (bj_UNIT_FACING) when left out.
Returns
Unit
The new unit.
Throws
When the game returns no handle, for example an unknown name:
reforged-ts: failed to create Unit (<unitName>), at the calling line. In Dev
mode, also before the globals Init stage and inside MapPlayer.runLocal.
Native
createCorpse()
staticcreateCorpse(owner,unitId,x,y,face?):Unit
Defined in: handles/unit.ts:180
Creates the corpse of a unit type for owner.
Parameters
owner
The player who owns the corpse.
unitId
number
The unit type's rawcode, such as FourCC("hfoo").
x
number
The x-coordinate, in world units.
y
number
The y-coordinate, in world units.
face?
number = bj_UNIT_FACING
The facing, in degrees; 270 (bj_UNIT_FACING) when left out.
Returns
Unit
The new corpse.
Remarks
The unit dies as it spawns and plays its decay animation, so it becomes a corpse only once that animation has run.
Throws
When the game returns no handle, for example an unknown rawcode or a
unit type that leaves no corpse: reforged-ts: failed to create Unit (<rawcode>),
at the calling line. In Dev mode, also before the globals Init stage and inside
MapPlayer.runLocal.
Native
foodMadeByType()
staticfoodMadeByType(unitId):number
Defined in: handles/unit.ts:3616
Gets the food a unit type provides to its owner, such as a farm's.
Parameters
unitId
number
The unit type's rawcode.
Returns
number
The food provided.
Native
foodUsedByType()
staticfoodUsedByType(unitId):number
Defined in: handles/unit.ts:3626
Gets the food a unit type costs its owner.
Parameters
unitId
number
The unit type's rawcode.
Returns
number
The food used.
Native
fromAttacker()
staticfromAttacker():Unit|undefined
Defined in: handles/unit.ts:3635
Gets the attacking unit of an attacked event.
Returns
Unit | undefined
The attacker, or undefined outside an attacked event.
Native
fromBuying()
staticfromBuying():Unit|undefined
Defined in: handles/unit.ts:3817
Gets the unit buying from a shop in a sell event.
Returns
Unit | undefined
The buyer, or undefined outside a sell event.
Native
fromCancelled()
staticfromCancelled():Unit|undefined
Defined in: handles/unit.ts:3826
Gets the structure whose construction is cancelled in a construction cancel event.
Returns
Unit | undefined
The structure, or undefined outside a construction cancel.
Native
GetCancelledStructure (jassbot)
fromChanging()
staticfromChanging():Unit|undefined
Defined in: handles/unit.ts:3644
Gets the unit changing owner in an ownership change event.
Returns
Unit | undefined
The unit, or undefined outside an ownership change.
Native
fromConstructed()
staticfromConstructed():Unit|undefined
Defined in: handles/unit.ts:3653
Gets the finished structure of a construction finish event.
Returns
Unit | undefined
The structure, or undefined outside a construction finish.
Native
GetConstructedStructure (jassbot)
fromConstructing()
staticfromConstructing():Unit|undefined
Defined in: handles/unit.ts:3835
Gets the structure being built in a construction start event.
Returns
Unit | undefined
The structure, or undefined outside a construction start.
Native
GetConstructingStructure (jassbot)
fromDamageSource()
staticfromDamageSource():Unit|undefined
Defined in: handles/unit.ts:3662
Gets the unit dealing the damage in a damage event.
Returns
Unit | undefined
The source, or undefined outside a damage event or when no unit deals the damage.
Native
GetEventDamageSource (jassbot)
fromDamageTarget()
staticfromDamageTarget():Unit|undefined
Defined in: handles/unit.ts:3671
Gets the unit taking the damage in a damage event.
Returns
Unit | undefined
The target, or undefined outside a damage event.
Native
BlzGetEventDamageTarget (jassbot)
fromDecaying()
staticfromDecaying():Unit|undefined
Defined in: handles/unit.ts:3844
Gets the decaying unit of a decay event.
Returns
Unit | undefined
The unit, or undefined outside a decay event.
Native
fromDetected()
staticfromDetected():Unit|undefined
Defined in: handles/unit.ts:3853
Gets the detected unit of a detection event.
Returns
Unit | undefined
The unit, or undefined outside a detection event.
Native
fromDying()
staticfromDying():Unit|undefined
Defined in: handles/unit.ts:3862
Gets the dying unit of a death event.
Returns
Unit | undefined
The unit, or undefined outside a death event.
Native
fromEntering()
staticfromEntering():Unit|undefined
Defined in: handles/unit.ts:3680
Gets the unit entering the region in a region event.
Returns
Unit | undefined
The unit, or undefined outside a region event.
Native
fromEnum()
staticfromEnum():Unit|undefined
Defined in: handles/unit.ts:3689
Gets the unit a group loop is at, inside the callback of Group.for.
Returns
Unit | undefined
The unit, or undefined outside a group loop.
Native
fromEvent()
staticfromEvent():Unit|undefined
Defined in: handles/unit.ts:3698
Gets the unit of the unit event that fired the running Trigger.
Returns
Unit | undefined
The unit, or undefined outside a unit event.
Native
Overrides
fromEventTarget()
staticfromEventTarget():Unit|undefined
Defined in: handles/unit.ts:3871
Gets the target unit of a target acquired or target in range event.
Returns
Unit | undefined
The target, or undefined when the event has none.
Native
fromFilter()
staticfromFilter():Unit|undefined
Defined in: handles/unit.ts:3707
Gets the unit a group enumeration is testing, inside its filter.
Returns
Unit | undefined
The unit, or undefined outside an enumeration filter.
Native
fromHandle()
staticfromHandle<C>(this,handle):C|undefined
Defined in: handles/handle.ts:195
Gets the Wrapper for handle, making it on first use. The same Handle
always gives the same object; when the object cached for it is of a less
specific class than the one asked for (a Timer cached,
MyTimer.fromHandle asked), a new object of the class asked for replaces
it. Unit.fromHandle(h) is typed Unit | undefined.
Type Parameters
C
C extends Handle<handle>
The Wrapper of the class it is called on.
Parameters
this
WrapperClass<C>
handle
C["handle"] | undefined
A Handle of the class's Native type.
Returns
C | undefined
The Wrapper, or undefined when handle is undefined.
Remarks
It creates no Handle, so none of the creation Guards of Dev mode apply: wrap a Handle that Native code outside the library returned.
Inherited from
fromKilling()
staticfromKilling():Unit|undefined
Defined in: handles/unit.ts:3716
Gets the unit that killed the dying unit in a death event.
Returns
Unit | undefined
The killer, or undefined outside a death event or when no unit killed it.
Native
fromLearning()
staticfromLearning():Unit|undefined
Defined in: handles/unit.ts:3880
Gets the hero learning a skill in a skill event.
Returns
Unit | undefined
The hero, or undefined outside a skill event.
Native
fromLeaving()
staticfromLeaving():Unit|undefined
Defined in: handles/unit.ts:3725
Gets the unit leaving the region in a region event.
Returns
Unit | undefined
The unit, or undefined outside a region event.
Native
fromLeveling()
staticfromLeveling():Unit|undefined
Defined in: handles/unit.ts:3734
Gets the hero gaining a level in a hero level event.
Returns
Unit | undefined
The hero, or undefined outside a hero level event.
Native
fromLoaded()
staticfromLoaded():Unit|undefined
Defined in: handles/unit.ts:3743
Gets the unit loaded into a transport in a load event.
Returns
Unit | undefined
The unit, or undefined outside a load event.
Native
fromManipulating()
staticfromManipulating():Unit|undefined
Defined in: handles/unit.ts:3889
Gets the unit picking up, dropping or using an item in an item event.
Returns
Unit | undefined
The unit, or undefined outside an item event.
Native
fromMouseFocus()
staticfromMouseFocus():Unit|undefined
Defined in: handles/unit.ts:3903
Async
Gets the unit under the local player's mouse cursor.
Returns
Unit | undefined
The unit, or undefined when the cursor is over none.
Remarks
The value differs between clients: never let it decide game state.
Example
A tooltip following the local mouse
// A tooltip that follows the mouse and names the unit under it. The cursor,
// the unit it points at and the screen's size in pixels are each client's
// own, so every client moves its own tooltip and nothing here reaches game
// state: a click that must change the game goes through an event, such as a
// selection or an order, which every client receives.
import { Frame, Init, Input, Timer, Unit } from "reforged-ts";
Init.onGameStart(() => {
const gameUi = Frame.fromOrigin(ORIGIN_FRAME_GAME_UI, 0);
if (gameUi === undefined) {
return;
}
const tooltip = Frame.createType("CursorTooltip", gameUi, 0, "TEXT", "");
Timer.every(0.03, () => {
const unit = Unit.fromMouseFocus();
tooltip.visible = unit !== undefined;
if (unit === undefined) {
return;
}
tooltip.text = Input.isMouseButtonPressed(MOUSE_BUTTON_TYPE_LEFT)
? `|cffffcc00${unit.name}|r`
: unit.name;
// The cursor comes in pixels and the anchor goes in frame units. Past
// the middle of the screen, 0.4 in frame units, the tooltip flips to the
// cursor's left side.
const rightHalf = Input.mouseScreenX > Frame.frameToPixelX(0.4);
tooltip.clearPoints();
tooltip.setAbsPoint(
rightHalf ? FRAMEPOINT_BOTTOMRIGHT : FRAMEPOINT_BOTTOMLEFT,
Frame.pixelToFrameX(Input.mouseScreenX),
Frame.pixelToFrameY(Input.mouseScreenY),
);
});
});
Native
BlzGetMouseFocusUnit (jassbot)
fromOrdered()
staticfromOrdered():Unit|undefined
Defined in: handles/unit.ts:3752
Gets the unit given an order in an order event.
Returns
Unit | undefined
The unit, or undefined outside an order event.
Native
fromOrderTarget()
staticfromOrderTarget():Unit|undefined
Defined in: handles/unit.ts:3762
Gets the unit a target order targets in an order event.
Returns
Unit | undefined
The target, or undefined outside a target order or when the target
is not a unit.
Native
Overrides
fromRescuer()
staticfromRescuer():Unit|undefined
Defined in: handles/unit.ts:3921
Gets the unit rescuing in a rescue event.
Returns
Unit | undefined
The rescuer, or undefined outside a rescue event.
Native
fromResearching()
staticfromResearching():Unit|undefined
Defined in: handles/unit.ts:3912
Gets the unit researching in a research event.
Returns
Unit | undefined
The unit, or undefined outside a research event.
Native
fromRevivable()
staticfromRevivable():Unit|undefined
Defined in: handles/unit.ts:3930
Gets the hero that became revivable in a revivable event.
Returns
Unit | undefined
The hero, or undefined outside a revivable event.
Native
fromReviving()
staticfromReviving():Unit|undefined
Defined in: handles/unit.ts:3939
Gets the reviving hero of a revive event.
Returns
Unit | undefined
The hero, or undefined outside a revive event.
Native
fromSelling()
staticfromSelling():Unit|undefined
Defined in: handles/unit.ts:3948
Gets the shop selling in a sell event.
Returns
Unit | undefined
The shop, or undefined outside a sell event.
Native
fromSold()
staticfromSold():Unit|undefined
Defined in: handles/unit.ts:3957
Gets the unit sold in a unit sell event.
Returns
Unit | undefined
The unit, or undefined outside a unit sell event.
Native
fromSpellAbility()
staticfromSpellAbility():Unit|undefined
Defined in: handles/unit.ts:3966
Gets the unit casting the spell in a spell event.
Returns
Unit | undefined
The caster, or undefined outside a spell event.
Native
fromSpellTarget()
staticfromSpellTarget():Unit|undefined
Defined in: handles/unit.ts:3772
Gets the target unit of the spell in a spell event.
Returns
Unit | undefined
The target, or undefined outside a spell event or when the spell
targets no unit.
Native
fromSummoned()
staticfromSummoned():Unit|undefined
Defined in: handles/unit.ts:3781
Gets the summoned unit of a summon event.
Returns
Unit | undefined
The summoned unit, or undefined outside a summon event.
Native
fromSummoning()
staticfromSummoning():Unit|undefined
Defined in: handles/unit.ts:3790
Gets the unit that summons in a summon event.
Returns
Unit | undefined
The summoner, or undefined outside a summon event.
Native
fromTrained()
staticfromTrained():Unit|undefined
Defined in: handles/unit.ts:3799
Gets the trained unit of a training finish event.
Returns
Unit | undefined
The unit, or undefined outside a training finish.
Native
fromTransport()
staticfromTransport():Unit|undefined
Defined in: handles/unit.ts:3808
Gets the transport a unit is loaded into in a load event.
Returns
Unit | undefined
The transport, or undefined outside a load event.
Native
getPointValueByType()
staticgetPointValueByType(unitType):number
Defined in: handles/unit.ts:3976
Gets the point value a unit type defines, which the score screen counts.
Parameters
unitType
number
The unit type's rawcode.
Returns
number
The point value.
Native
GetUnitPointValueByType (jassbot)
isUnitIdHero()
staticisUnitIdHero(unitId):boolean
Defined in: handles/unit.ts:3986
Checks whether a unit type is a hero type.
Parameters
unitId
number
The unit type's rawcode.
Returns
boolean
True when the type is a hero type.
Native
isUnitIdType()
staticisUnitIdType(unitId,whichUnitType):boolean
Defined in: handles/unit.ts:3997
Checks whether a unit type has a classification, such as UNIT_TYPE_STRUCTURE.
Parameters
unitId
number
The unit type's rawcode.
whichUnitType
unittype
The classification.
Returns
boolean
True when the type has it.