/
unit.j
1725 lines (1144 loc) · 59.1 KB
/
unit.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Unit API
/**
Creates a unit of type `unitid` for player `id`, facing a certain direction at the provided coordinates.
Returns handle to unit.
**Example:** Create a human footman for first player (red) at map coordinates -30, 0, facing north:
```
// Jass
call CreateUnit(Player(0), 'hfoo', -30, 0, 90)
```
```{.lua}
-- Lua
CreateUnit(Player(0), FourCC("hfoo"), -30, 0, 90)
```
@note See: `bj_UNIT_FACING` constant for default facing direction of units in BJ scripts and GUI.
@param id The owner of the unit.
@param unitid The rawcode of the unit.
@param x The x-coordinate of the unit.
@param y The y-coordinate of the unit.
@param face Unit facing in degrees.
* 0 = East
* 90 = North
* 180 = West
* 270 = South
* -90 = South (wraps around)
*/
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit
/**
@param face Unit facing in degrees.
*/
native CreateUnitByName takes player whichPlayer, string unitname, real x, real y, real face returns unit
/**
@param id The owner of the unit.
@param unitid The rawcode of the unit.
@param whichLocation The position of the unit.
@param face Unit facing in degrees.
*/
native CreateUnitAtLoc takes player id, integer unitid, location whichLocation, real face returns unit
/**
@param face Unit facing in degrees.
*/
native CreateUnitAtLocByName takes player id, string unitname, location whichLocation, real face returns unit
/**
Creates the corpse of a specific unit for a player at the coordinates ( x , y ).
The unit will die upon spawning and play their decay animation, therefore they
will not necessarily be a corpse immediately after this function call. If the
unit corresponding to the rawcode cannot have a corpse, then the returned value is null.
@param whichPlayer The owner of the corpse.
@param unitid The rawcode of the unit for the corpse.
@param x The x-coordinate of the corpse.
@param y The y-coordinate of the corpse.
@param face Unit facing in degrees.
*/
native CreateCorpse takes player whichPlayer, integer unitid, real x, real y, real face returns unit
native KillUnit takes unit whichUnit returns nothing
native RemoveUnit takes unit whichUnit returns nothing
native ShowUnit takes unit whichUnit, boolean show returns nothing
/**
Set unit's unit state to a new absolute value.
**Example:** Set unit's max mana to 105 MP.
call SetUnitState(myUnit, UNIT_STATE_MAX_MANA, 105.0)
@note See: `GetUnitState`.
*/
native SetUnitState takes unit whichUnit, unitstate whichUnitState, real newVal returns nothing
/**
@note If the unit has movementspeed of zero the unit will be moved but the model
of the unit will not move.
@note This does not cancel orders of the unit. `SetUnitPosition` does cancel orders.
*/
native SetUnitX takes unit whichUnit, real newX returns nothing
/**
@note If the unit has movementspeed of zero the unit will be moved but the model
of the unit will not move.
@note This does not cancel orders of the unit. `SetUnitPosition` does cancel orders.
*/
native SetUnitY takes unit whichUnit, real newY returns nothing
/**
@note This cancels the orders of the unit. If you want to move a unit without
canceling its orders use `SetUnitX`/`SetUnitY`.
*/
native SetUnitPosition takes unit whichUnit, real newX, real newY returns nothing
native SetUnitPositionLoc takes unit whichUnit, location whichLocation returns nothing
native SetUnitFacing takes unit whichUnit, real facingAngle returns nothing
native SetUnitFacingTimed takes unit whichUnit, real facingAngle, real duration returns nothing
native SetUnitMoveSpeed takes unit whichUnit, real newSpeed returns nothing
native SetUnitFlyHeight takes unit whichUnit, real newHeight, real rate returns nothing
native SetUnitTurnSpeed takes unit whichUnit, real newTurnSpeed returns nothing
/**
Sets a unit's propulsion window to the specified angle (in radians).
The propulsion window determines at which facing angle difference to the target
command's location (move, attack, patrol, smart) a unit will begin to move if
movement is required to fulfil the command, or if it will turn without movement.
A propulsion window of 0 makes the unit unable to move at all.
A propulsion window of 180 will force it to start moving as soon as the command
is given (if movement is required). In practice, this means that setting a
unit's prop window to 0 will prevent it from attacking.
<http://www.hiveworkshop.com/forums/2391397-post20.html>
@param whichUnit The function will modify this unit's propulsion window.
@param newPropWindowAngle The propulsion window angle to assign. Should be in radians.
*/
native SetUnitPropWindow takes unit whichUnit, real newPropWindowAngle returns nothing
/**
Sets a unit's acquire range. This is the value that a unit uses to choose targets to
engage with. Note that this is not the attack range. When acquisition range is
greater than attack range, the unit will attempt to move towards acquired targets, and
then attack.
Setting acquisition range lower than attack range in the object editor limits the
unit's attack range to the acquisition range, but changing a unit's acquisition range
with this native does not change its attack range, nor the value displayed in the UI.
@note It is a myth that reducing acquire range with this native can limit a unit's
attack range.
*/
native SetUnitAcquireRange takes unit whichUnit, real newAcquireRange returns nothing
native SetUnitCreepGuard takes unit whichUnit, boolean creepGuard returns nothing
native GetUnitAcquireRange takes unit whichUnit returns real
native GetUnitTurnSpeed takes unit whichUnit returns real
/**
Returns a unit's propulsion window angle in radians.
@param whichUnit The function will return this unit's propulsion window angle.
*/
native GetUnitPropWindow takes unit whichUnit returns real
native GetUnitFlyHeight takes unit whichUnit returns real
native GetUnitDefaultAcquireRange takes unit whichUnit returns real
native GetUnitDefaultTurnSpeed takes unit whichUnit returns real
/**
Returns a unit's default propulsion window angle in degrees.
@param whichUnit
The unit of which to return the default prop window.
@note This native is the odd case in the asymmetric prop window API, since the
other prop window natives use radians. Therefore, to reset a unit's prop window
you need the explicit conversion, i.e.
`SetUnitPropWindow(u, GetUnitDefaultPropWindow(u) * bj_DEGTORAD)`.
*/
native GetUnitDefaultPropWindow takes unit whichUnit returns real
native GetUnitDefaultFlyHeight takes unit whichUnit returns real
/**
Changes ownership of a unit.
@param whichUnit Unit to modify.
@param whichPlayer The unit's new owner.
@param changeColor True to change unit's accent color to new owner's color, false to leave old color.
@note Reforged: The HP bar will always have the color of its owner player, regardless of `changeColor`.
@note See: `GetOwningPlayer`, `Player`.
*/
native SetUnitOwner takes unit whichUnit, player whichPlayer, boolean changeColor returns nothing
/**
Sets a unit's player color accent.
@param whichUnit Unit to modify.
@param whichColor Set to this player's color.
@bug Visual bug (tested v1.32.10): if you create two units of the same type (Normal and Colored)
and set Colored's color to a different color, then clicking between the two units
will not change the portrait color. The portrait will only update correctly if you
deselect the unit.
*/
native SetUnitColor takes unit whichUnit, playercolor whichColor returns nothing
/**
@bug Only takes scaleX into account and uses scaleX for all three dimensions.
@param scaleX This is actually the scale for *all* dimensions.
@param scaleY This parameter is not taken into account.
@param scaleZ This parameter is not taken into account.
*/
native SetUnitScale takes unit whichUnit, real scaleX, real scaleY, real scaleZ returns nothing
native SetUnitTimeScale takes unit whichUnit, real timeScale returns nothing
native SetUnitBlendTime takes unit whichUnit, real blendTime returns nothing
/**
Sets the unit's entire model color to the color defined by (red, green, blue, alpha).
The vertex color changes how the model is rendered. For example, setting all r,g,b=0 will make the model entirely black; no colors will be visible (like Illidan's demon form).
To imagine the final result of changing vertex colors, it is helpful to think of individual RGB layers in a color image, if you disable the Red channel, only Green & Blue channels will be shown.
@param whichUnit The unit to modify.
@param red visibility of red channel (clamped to 0-255).
@param green visibility of green channel (clamped to 0-255).
@param blue visibility of blue channel (clamped to 0-255).
@param alpha opacity (clamped to 0-255). A value of 255 is total opacity (fully visible). A value of 0 is total transparency; the model will be invisible, but you'll still see the shadow, HP bar etc.
@note Not to be confused with `SetUnitColor` which changes a unit's player accent color.
*/
native SetUnitVertexColor takes unit whichUnit, integer red, integer green, integer blue, integer alpha returns nothing
native QueueUnitAnimation takes unit whichUnit, string whichAnimation returns nothing
native SetUnitAnimation takes unit whichUnit, string whichAnimation returns nothing
native SetUnitAnimationByIndex takes unit whichUnit, integer whichAnimation returns nothing
native SetUnitAnimationWithRarity takes unit whichUnit, string whichAnimation, raritycontrol rarity returns nothing
native AddUnitAnimationProperties takes unit whichUnit, string animProperties, boolean add returns nothing
/**
Locks a unit's bone to face the target until ResetUnitLookAt is called.
The offset coordinates ( X, Y, Z ) are taken from the target's origin.
The bones will lock to the lookAtTarget, offset by those coordinates. You can't
have both the head and the chest locked to the target at the same time.
@param whichUnit The unit that will have its bone locked to face the target.
@param whichBone The bone to lock onto the target. The engine only supports
locking the head and the chest. To lock the head, you can put in any input
except a null string. To lock the chest, the string must start with `"bone_chest"`.
All leading spaces are ignored, it is case insensitive, and anything after the
first non-leading space will be ignored.
@param lookAtTarget The bone will be locked to face this unit.
@param offsetX The x-offset from lookAtTarget's origin point.
@param offsetY The y-offset from lookAtTarget's origin point.
@param offsetZ The z-offset from lookAtTarget's origin point (this already factors in the terrain Z).
@note The parameter `whichBone` can only move the head bones and the chest bones.
All other input will default to the head bone. However, the function only looks
for the helper named `"Bone_Head"` (or `"Bone_Chest"`) in the MDL, so you can just
rename a helper so that it will move that set of bones instead.
@note SetUnitLookAt is affected by animation speed and blend time.
@note [How to instantly set a unit's facing](http://www.wc3c.net/showthread.php?t=105830).
*/
native SetUnitLookAt takes unit whichUnit, string whichBone, unit lookAtTarget, real offsetX, real offsetY, real offsetZ returns nothing
/**
Unlocks the bone oriented by `SetUnitLookAt`, allowing it to move in accordance
to the unit's regular animations.
@param whichUnit The unit that will have its bone unlocked.
*/
native ResetUnitLookAt takes unit whichUnit returns nothing
native SetUnitRescuable takes unit whichUnit, player byWhichPlayer, boolean flag returns nothing
native SetUnitRescueRange takes unit whichUnit, real range returns nothing
/**
Sets the hero's strength property. If the new strength property is less than current value, the hero will lose HP.
@note Hero cannot lose HP below 1.0, which means that removing X strength and then adding X strength back can result in healing.
*/
native SetHeroStr takes unit whichHero, integer newStr, boolean permanent returns nothing
native SetHeroAgi takes unit whichHero, integer newAgi, boolean permanent returns nothing
native SetHeroInt takes unit whichHero, integer newInt, boolean permanent returns nothing
native GetHeroStr takes unit whichHero, boolean includeBonuses returns integer
native GetHeroAgi takes unit whichHero, boolean includeBonuses returns integer
native GetHeroInt takes unit whichHero, boolean includeBonuses returns integer
native UnitStripHeroLevel takes unit whichHero, integer howManyLevels returns boolean
native GetHeroXP takes unit whichHero returns integer
native SetHeroXP takes unit whichHero, integer newXpVal, boolean showEyeCandy returns nothing
/**
Returns the units available skill points.
*/
native GetHeroSkillPoints takes unit whichHero returns integer
/**
Adds the amount to the units available skill points. Calling with a negative
number reduces the skill points by that amount.
Returns false if the amount of available skill points is already zero and
if it's called with any non-positive number.
Returns true in any other case.
@note If `skillPointDelta` is greater than the amount of skillpoints the hero
actually can spend (like 9 for three 3-level abilities) only that amount will
be added. Negative `skillPointDelta` works as expected.
*/
native UnitModifySkillPoints takes unit whichHero, integer skillPointDelta returns boolean
/**
Adds the input value of experience to the hero unit specified.
If the experience added exceeds the amount required for the hero to gain a level,
then it will force the unit to gain a level and the remaining experience will
spill over for the next level.
@bug Adding negative value to experience will decrease it
by the stated value, but won't lower the level even if the experience value
after deduction is lower than the lower bound of the experience required to get
the stated level.
@bug If the value will become lower than zero, the experience won't
be negative, instead of it it'll be equal
to `4294967296+(supposed_negative_experience_value)` which actually proves
that WarCraft III uses unsigned int type for storing experience points.
@param whichHero The hero unit to add experience to.
@param xpToAdd The amount of experience to add to the hero unit.
@param showEyeCandy If the boolean input is true, then the hero-level-gain
effect will be shown if the hero gains a level from the added experience.
*/
native AddHeroXP takes unit whichHero, integer xpToAdd, boolean showEyeCandy returns nothing
/**
Sets the hero to chosen level.
The level can only be increased; lowering the level does nothing.
Further, the level will not exceed the hero's maximum level set in WorldEditor.
@param whichHero The target hero unit.
@param level New level of the hero.
@param showEyeCandy False to hide level-up effects, true to show.
The level-up effects include: floating experience gain text, sound and a visual effect.
*/
native SetHeroLevel takes unit whichHero, integer level, boolean showEyeCandy returns nothing
constant native GetHeroLevel takes unit whichHero returns integer
constant native GetUnitLevel takes unit whichUnit returns integer
/**
Returns the hero's "Proper Name", which is the name displayed above the level bar.
@note Will return 'null' on non-hero units.
*/
native GetHeroProperName takes unit whichHero returns string
native SuspendHeroXP takes unit whichHero, boolean flag returns nothing
native IsSuspendedXP takes unit whichHero returns boolean
/**
Spends a skill point of the hero to learn a skill.
If the requirements are not met, does nothing.
This is equivalent to clicking the red plus button in game and choosing a skill.
Requirements:
1. The hero has an unspent skill point
2. The skill is available for learning (not level-locked etc.)
@param whichHero Target hero.
@param abilcode Abilities' raw code identifier.
*/
native SelectHeroSkill takes unit whichHero, integer abilcode returns nothing
/**
Returns the level of the ability for the unit.
@param whichUnit Target unit.
@param abilcode Abilities' raw code identifier.
*/
native GetUnitAbilityLevel takes unit whichUnit, integer abilcode returns integer
/**
Decreases the level of a unit's ability by 1. The level will not go below 1.
Returns the new ability level.
@param whichUnit The unit with the ability.
@param abilcode The four digit rawcode representation of the ability.
*/
native DecUnitAbilityLevel takes unit whichUnit, integer abilcode returns integer
/**
Increases the level of a unit's ability by 1.
Returns the new ability level.
@param whichUnit The unit with the ability.
@param abilcode The four digit rawcode representation of the ability.
@note `IncUnitAbilityLevel` can increase an abilities level to maxlevel+1.
On maxlevel+1 all ability fields are 0.
See <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 IncUnitAbilityLevel takes unit whichUnit, integer abilcode returns integer
/**
Sets the new level of unit's ability.
@param whichUnit Target unit.
@param abilcode Abilities' raw code identifier.
@param level New ability level.
@note You can only set levels which are defined for the current ability.
For example, most WC3 abilities have levels 1-3.
Setting level <=0 will instead set it to level 1.
Setting level >maximum will instead set it to abilities' highest level defined in WorldEditor.
*/
native SetUnitAbilityLevel takes unit whichUnit, integer abilcode, integer level returns integer
/**
Revives a dead hero at target coordinates, with or without special effects.
Returns true if hero was dead and revived.
Returns false otherwise (hero alive, unit isn't a hero/doesn't exist etc.).
@param whichHero Target dead hero.
@param x X map coordinate.
@param y Y map coordinate.
@param doEyecandy True to revive with revival special effects, false without.
Special effects include: sound, visual effect.
@note See: `ReviveHeroLoc`.
*/
native ReviveHero takes unit whichHero, real x, real y, boolean doEyecandy returns boolean
/**
Revives a dead hero at target location, with or without special effects.
Returns true if hero was dead and revived.
Returns false otherwise (hero alive, unit isn't a hero/doesn't exist etc.)
@param loc Location on map.
@param doEyecandy True to revive with revival special effects, false without.
Special effects include: sound, visual effect.
@note See: `ReviveHero`.
*/
native ReviveHeroLoc takes unit whichHero, location loc, boolean doEyecandy returns boolean
native SetUnitExploded takes unit whichUnit, boolean exploded returns nothing
/**
Renders a unit invulnerable/lifts that specific invulnerability.
@note The native seems to employ the `'Avul'` ability, which is defined in the
default AbilityData.slk.
If there is no `'Avul'` defined, this will crash the game.
*/
native SetUnitInvulnerable takes unit whichUnit, boolean flag returns nothing
/**
Pauses a unit. A paused unit has the following properties:
* Buffs/effects are suspended
* Orders are stored when paused and fired on unpause
* The paused unit does not accept powerups. `UnitAddItem` returns true but
the item is not picked up
*/
native PauseUnit takes unit whichUnit, boolean flag returns nothing
native IsUnitPaused takes unit whichHero returns boolean
native SetUnitPathing takes unit whichUnit, boolean flag returns nothing
/**
Clears all widget selections for all players.
@note Use `ClearSelectionForPlayer` to clear selection for only one player.
*/
native ClearSelection takes nothing returns nothing
/**
@bug If you use this function to select a unit after calling `ClearSelection` (like `SelectUnitSingle`
does) and you have a unit sub-menu opened (like spellbook or build structure), the command buttons
of the selected unit won't show until you select another unit.
*/
native SelectUnit takes unit whichUnit, boolean flag returns nothing
native GetUnitPointValue takes unit whichUnit returns integer
native GetUnitPointValueByType takes integer unitType returns integer
//native SetUnitPointValueByType takes integer unitType, integer newPointValue returns nothing
/**
Puts specific item in target unit's inventory.
Returns:
- true if this exact item is already in unit's inventory or if it was put there successfully
- false if unit has no inventory or space, or invalid item/unit
@param whichUnit Target unit.
@param whichItem Handle to item instance.
*/
native UnitAddItem takes unit whichUnit, item whichItem returns boolean
/**
Creates a new item of type `itemId` and puts it in unit's inventory.
If the inventory is full, it is dropped on the ground at unit's position instead.
This function works in two steps:
1. Spawn the item if both `whichUnit` and `itemId` are valid and exist
2. Attempt to put the item in unit's inventory. If inventory is full or unit is
dead then the item is dropped on the ground at unit position.
Returns:
- item handle if the item was successfully placed in unit's inventory
- null if inventory is full, unit cannot carry items, itemId/unit invalid etc.
@param whichUnit Target unit.
@param itemId Item's raw code identifier.
@note See: `UnitAddItemToSlotById`.
*/
native UnitAddItemById takes unit whichUnit, integer itemId returns item
/**
Creates a new item of type `itemId`
and puts it in unit's inventory in slot specified by `itemSlot`.
If the slot is occupied or invalid (<0 or >6, or higher than unit's max slots),
it is dropped on the ground at unit's position instead.
This function works in two steps:
1. Spawn the item if both `whichUnit` and `itemId` are valid and exist
2. Attempt to put the item in unit's inventory at specified slot.
If the slot is occupied or unit is dead then the item is dropped on the ground
at unit position.
Returns:
- true if the item was successfully placed in unit's inventory
- false otherwise: slot occupied, unit cannot carry items, itemId/unit/itemSlot invalid etc.
@param whichUnit Target unit.
@param itemId Item's raw code identifier.
@param itemSlot Slot number (zero-based, i.e. 0 to 5).
@note See: `UnitAddItemById`.
*/
native UnitAddItemToSlotById takes unit whichUnit, integer itemId, integer itemSlot returns boolean
/**
If the target unit carries the item, it is removed from the inventory and dropped at unit's position.
Nothing happens if unit or item instance is invalid.
@param whichUnit Target unit.
@param whichItem Handle to item instance.
@note See `UnitRemoveItemFromSlot` to drop an item from a specific slot.
*/
native UnitRemoveItem takes unit whichUnit, item whichItem returns nothing
/**
If an item exists in the given slot, it is removed from the inventory and dropped at unit's position.
Returns the handle of dropped item when successful.
Returns null on failure (no item, invalid slot/unit).
@param whichUnit Target unit.
@param itemSlot Slot number (zero-based, i.e. 0 to 5).
@note See `UnitRemoveItem` to drop an item by handle.
*/
native UnitRemoveItemFromSlot takes unit whichUnit, integer itemSlot returns item
/**
Returns true if unit has this specific instance of item somewhere in inventory.
Returns false otherwise (null unit, item not found in inventory, null item etc).
@param whichUnit Target unit.
@param whichItem Handle to item instance.
*/
native UnitHasItem takes unit whichUnit, item whichItem returns boolean
/**
Returns a handle to item in slot number `itemSlot` of the specified unit.
Returns null otherwise:
when there's no item in slot, no slot (less than 6 slots), invalid slot number, invalid unit.
@param whichUnit Target unit.
@param itemSlot Slot number (zero-based, i.e. 0 to 5).
*/
native UnitItemInSlot takes unit whichUnit, integer itemSlot returns item
/**
Returns amount of inventory slots for unit (0 to `bj_MAX_INVENTORY` inclusive).
Returns zero if unit is invalid or has no inventory.
@param whichUnit Target unit.
*/
native UnitInventorySize takes unit whichUnit returns integer
/**
Issues an immediate order for the unit to go to point (x,y) and drop the item there.
If the unit cannot reach the point, it will run up to closest location and stop there,
without dropping the item.
Returns:
- true if item was found in inventory of unit and an order was issued.
- false if unit/item invalid, unit is paused and cannot take orders etc.
@param whichUnit Target unit.
@param whichItem Handle to item instance.
@param x X map coordinate.
@param y Y map coordinate.
@note See: `UnitDropItemSlot`, `UnitDropItemTarget`.
*/
native UnitDropItemPoint takes unit whichUnit, item whichItem, real x, real y returns boolean
/**
Moves an item inside unit's inventory to specified slot.
If this slot contains an item, their positions are swapped.
This is the same as if you'd right-click an item in game to move it to a different slot.
Returns:
- true if the move was successful, even if moving an item to its current slot (no change)
- false if unit/item invalid, item not in inventory, invalid item slot specified
@param whichUnit Target unit.
@param whichItem Handle to item instance.
@param slot Move to this slot.
*/
native UnitDropItemSlot takes unit whichUnit, item whichItem, integer slot returns boolean
/**
Issues an immediate order for the `whichUnit` to go to `target` (usually another unit)
and give the item to target. If the target has no inventory slots/full inventory,
the item is dropped at target's feet.
If the `whichUnit` cannot reach the target, it will run up to closest location and stop there,
without giving the item. If the target is a running unit, `whichUnit` will follow it
to give the item.
Returns:
- true if item was found in inventory of `whichUnit` and an order was issued.
- false if `whichUnit`/item/widget invalid, `whichUnit` is paused and cannot take orders etc.
Target widget can be a paused unit and will receive the item.
@param whichUnit Target unit.
@param whichItem Handle to item instance.
@param target Target unit or widget.
@note See: `UnitDropItemSlot`, `UnitDropItemPoint`.
*/
native UnitDropItemTarget takes unit whichUnit, item whichItem, widget target returns boolean
/**
Issues an immediate order for the unit to use the specified item.
This is the same as left-clicking and using an item in inventory.
Units that cannot use items will not do anything.
Returns:
- true if item was successfully used / an order was issued
- false otherwise, because an order was not issued:
unit doesn't have item, item on cooldown, invalid unit/item etc.
Examples:
- Potion of Healing `'phea'`:
- Unit on patrol, but has full HP: does nothing, unit continues running
- Unit on patrol, but has low HP: Uses potion to restore HP, stops patrolling
- Dagger of Escape `'desc'`:
is not casted, because requires a position as a target.
However, an order is issued, hence returns true.
- Inferno Stone `'infs'`: same as with dagger above.
@note See: `UnitUseItemPoint`, `UnitUseItemTarget`.
*/
native UnitUseItem takes unit whichUnit, item whichItem returns boolean
/**
Issues an immediate order for the unit to use item pointed at position (x,y).
This is the same as left-clicking and using an item in inventory.
Units that cannot use items will not do anything.
Examples:
- Potion of Healing `'phea'`:
Restores HP
- Dagger of Escape `'desc'`:
Casts immediately towards (x,y), even if too far, item on cooldown.
Does not cast if position is already reached (no cooldown).
- Inferno Stone `'infs'`:
runs towards (x,y) and once in range, casts to spawn an Infernal.
If already in range, casts immediately.
@param whichUnit Target unit.
@param whichItem Handle to item instance.
@param x Point at X map coordinate to use the item.
@param y Point at Y map coordinate to use the item.
@bug Seems to always return false (tested v1.32.10).
@note See: `UnitUseItem`, `UnitUseItemTarget`.
*/
native UnitUseItemPoint takes unit whichUnit, item whichItem, real x, real y returns boolean
/**
Issues an immediate order for the unit to use item pointed `target` (widget or unit).
This is the similar to left-clicking and using an item in inventory.
Units that cannot use items will not do anything.
Returns:
- true if item was successfully used / an order was issued
- false otherwise, because an order was not issued:
unit doesn't have item, item on cooldown, invalid unit/item/target etc.
Examples:
- Dagger of Escape `'desc'`: does not cast.
Explanation: when you click a dagger on a building in game, the target is not
actually the building, but the map position you're pointing at, even though you
see the building being highlighted on cursor hover.
- Inferno Stone `'infs'`: does not cast, same as above.
@param whichUnit Target unit.
@param whichItem Handle to item instance.
@param target Target unit or widget.
@note See: `UnitUseItem`, `UnitUseItemPoint`.
*/
native UnitUseItemTarget takes unit whichUnit, item whichItem, widget target returns boolean
/**
Returns X map coordinate of whichUnit (alive or dead). Returns 0.0 if unit was removed or is null.
@bug If the unit is loaded into a zeppelin this will not return the position
of the zeppelin but the last position of the unit before it was loaded into
the zeppelin.
@note Since unit extends from `widget`, you can use widget-related functions too.
See: `GetUnitY`, `BlzGetLocalUnitZ`, `BlzGetUnitZ`, `GetWidgetX`, `GetWidgetY`.
*/
constant native GetUnitX takes unit whichUnit returns real
/**
Returns Y map coordinate of whichUnit (alive or dead). Returns 0.0 if unit was removed or is null.
@bug If the unit is loaded into a zeppelin this will not return the position
of the zeppelin but the last position of the unit before it was loaded into
the zeppelin.
@note Since unit extends from `widget`, you can use widget-related functions too.
See: `GetUnitX`, `BlzGetLocalUnitZ`, `BlzGetUnitZ`, GetWidgetX`, `GetWidgetY`.
*/
constant native GetUnitY takes unit whichUnit returns real
/**
@bug If the unit is loaded into a zeppelin this will not return the position
of the zeppelin but the last position of the unit before it was loaded into
the zeppelin.
*/
constant native GetUnitLoc takes unit whichUnit returns location
/**
Returns the units facing in degrees.
*/
constant native GetUnitFacing takes unit whichUnit returns real
constant native GetUnitMoveSpeed takes unit whichUnit returns real
constant native GetUnitDefaultMoveSpeed takes unit whichUnit returns real
/**
Returns unit's current unit state as an absolute value.
**Example:** Retrieve a unit's current/max HP and mana:
call GetUnitState(myUnit, UNIT_STATE_MAX_MANA) // returns 285.0
@note See: `SetUnitState`.
*/
constant native GetUnitState takes unit whichUnit, unitstate whichUnitState returns real
/**
Returns the owner player of the unit.
@param whichUnit Target unit.
@note See: `SetUnitOwner`.
*/
constant native GetOwningPlayer takes unit whichUnit returns player
constant native GetUnitTypeId takes unit whichUnit returns integer
constant native GetUnitRace takes unit whichUnit returns race
/**
Returns localized name for unit.
**Example (Lua)**:
```{.lua}
u = CreateUnit(Player(0), FourCC("hfoo"), -30, 0, 90)
print(GetUnitName(u)) --> "Footman"
```
@param whichUnit Target unit.
@async
*/
constant native GetUnitName takes unit whichUnit returns string
constant native GetUnitFoodUsed takes unit whichUnit returns integer
constant native GetUnitFoodMade takes unit whichUnit returns integer
constant native GetFoodMade takes integer unitId returns integer
constant native GetFoodUsed takes integer unitId returns integer
native SetUnitUseFood takes unit whichUnit, boolean useFood returns nothing
constant native GetUnitRallyPoint takes unit whichUnit returns location
constant native GetUnitRallyUnit takes unit whichUnit returns unit
constant native GetUnitRallyDestructable takes unit whichUnit returns destructable
constant native IsUnitInGroup takes unit whichUnit, group whichGroup returns boolean
constant native IsUnitInForce takes unit whichUnit, force whichForce returns boolean
constant native IsUnitOwnedByPlayer takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitAlly takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitEnemy takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitVisible takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitDetected takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitInvisible takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitFogged takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitMasked takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitSelected takes unit whichUnit, player whichPlayer returns boolean
constant native IsUnitRace takes unit whichUnit, race whichRace returns boolean
/**
@note This native returns a boolean, which when typecasted to integer might
be greater than 1. It's probably implemented via a bitset.
@note In past patches this native bugged when used in `conditionfunc`s.
The fix back then was to compare with true (`==true`).
I cannot reproduce the faulty behaviour in patch 1.27 so this is only a note.
*/
constant native IsUnitType takes unit whichUnit, unittype whichUnitType returns boolean
/**
@note Useless. Use operator== instead.
@pure
*/
constant native IsUnit takes unit whichUnit, unit whichSpecifiedUnit returns boolean
constant native IsUnitInRange takes unit whichUnit, unit otherUnit, real distance returns boolean
constant native IsUnitInRangeXY takes unit whichUnit, real x, real y, real distance returns boolean
constant native IsUnitInRangeLoc takes unit whichUnit, location whichLocation, real distance returns boolean
/**
Returns `true` if `whichUnit` is hidden, for example by means of `ShowUnit`.
*/
constant native IsUnitHidden takes unit whichUnit returns boolean
constant native IsUnitIllusion takes unit whichUnit returns boolean
constant native IsUnitInTransport takes unit whichUnit, unit whichTransport returns boolean
constant native IsUnitLoaded takes unit whichUnit returns boolean
constant native IsHeroUnitId takes integer unitId returns boolean
constant native IsUnitIdType takes integer unitId, unittype whichUnitType returns boolean
native UnitShareVision takes unit whichUnit, player whichPlayer, boolean share returns nothing
native UnitSuspendDecay takes unit whichUnit, boolean suspend returns nothing
native UnitAddType takes unit whichUnit, unittype whichUnitType returns boolean