TO GUI USERS:
PROBLEM: How to check or change certain properties of a unit
Can mix multiple values:
PROBLEM: How to convert one of these constants into an integer (e.g. MOVE_TYPE_FLY -> 2)
PROBLEM: How to convert an integer into one of these constants (e.g. 2 -> MOVE_TYPE_FLY)
PROBLEM: How to use these values with a hashtable
Addendum
Be aware that not all of these operations are guaranteed to work!
In some instances, such as changing a unit's defense type, it may be necessary to reselect the unit to update its UI.
List of Constants
- The solutions use the functions And/Or/Xor which can be found in GUI when comparing integers.
- Use the numbers corresponding to certain unit properties (e.g. 2 = MOVE_TYPE_FLY) in your triggers (list is at the bottom of the tutorial)
- (Recommended) Use an integer variable to get the value from their name (list is at the bottom of the tutorial)
PROBLEM: How to check or change certain properties of a unit
Can mix multiple values:
- Movement type (Foot, Fly, etc.) -- Apparently a unit can have any combination of move types... I don't know what the purpose is though
- Targeted as (Ground, Air, Structure, etc.)
- Unit category (Undead, Peon, Ward, Tauren, etc.)
- Pathing prevented by (Unwalkable, Unflyable, etc.)
- Armor type (Flesh, Metal, Wood, etc.)
- Defense type (Hero, Fortified, Heavy, etc.)
- Regeneration type (None, Always, Blight, Day, Night)
- Primary hero stat (Strength, Agility, Intelligence)
To CHECK if a unit is classified as "Undead":
To ADD the unit category "Undead" to a unit (does nothing if it already has it):
To REMOVE the "Undead" category from a unit (does nothing if it already does not have it):
To TOGGLE the "Undead" category of a unit (switch it to the opposite of its current value):
JASS:
if (BlzBitAnd(BlzGetUnitIntegerField(myUnit, UNIT_IF_UNIT_CLASSIFICATION), GetHandleId(UNIT_CATEGORY_UNDEAD)) != 0) then
// Unit is undead
else
// Unit is not undead
endif
To ADD the unit category "Undead" to a unit (does nothing if it already has it):
JASS:
call BlzSetUnitIntegerField(myUnit, UNIT_IF_UNIT_CLASSIFICATION, BlzBitOr(BlzGetUnitIntegerField(myUnit, UNIT_IF_UNIT_CLASSIFICATION), GetHandleId(UNIT_CATEGORY_UNDEAD)))
To REMOVE the "Undead" category from a unit (does nothing if it already does not have it):
JASS:
call BlzSetUnitIntegerField(myUnit, UNIT_IF_UNIT_CLASSIFICATION, BlzBitAnd(BlzGetUnitIntegerField(myUnit, UNIT_IF_UNIT_CLASSIFICATION), -1 - GetHandleId(UNIT_CATEGORY_UNDEAD)))
To TOGGLE the "Undead" category of a unit (switch it to the opposite of its current value):
JASS:
call BlzSetUnitIntegerField(myUnit, UNIT_IF_UNIT_CLASSIFICATION, BlzBitXor(BlzGetUnitIntegerField(myUnit, UNIT_IF_UNIT_CLASSIFICATION), GetHandleId(UNIT_CATEGORY_UNDEAD)))
To CHECK if a unit is classified as "Undead":
To ADD the unit category "Undead" to a unit (does nothing if it already has it):
To REMOVE the "Undead" category from a unit (does nothing if it already does not have it):
Make sure you get the final expression right: -1 - TempInt (negative one minus TempInt)
To TOGGLE the "Undead" category of a unit (switch it to the opposite of its current value):
To ADD the unit category "Undead" to a unit (does nothing if it already has it):
To REMOVE the "Undead" category from a unit (does nothing if it already does not have it):
Make sure you get the final expression right: -1 - TempInt (negative one minus TempInt)
To TOGGLE the "Undead" category of a unit (switch it to the opposite of its current value):
PROBLEM: How to convert one of these constants into an integer (e.g. MOVE_TYPE_FLY -> 2)
JASS:
local integer i = GetHandleId(MOVE_TYPE_FLY)
PROBLEM: How to convert an integer into one of these constants (e.g. 2 -> MOVE_TYPE_FLY)
JASS:
local movetype mt = ConvertMoveType(2)
PROBLEM: How to use these values with a hashtable
Use the two methods above to store the constant as an integer and then convert it back
For example,
For example,
JASS:
// Save the value
call SaveInteger(myHashtable, parentKey, childKey, GetHandleId(MOVE_TYPE_FLY))
// Load the value
local movetype mt = ConvertMoveType(LoadInteger(myHashtable, parentKey, childKey))
Addendum
Be aware that not all of these operations are guaranteed to work!
In some instances, such as changing a unit's defense type, it may be necessary to reselect the unit to update its UI.
List of Constants
JASS:
UNIT_IF_MOVE_TYPE
constant movetype MOVE_TYPE_UNKNOWN = ConvertMoveType(0)
constant movetype MOVE_TYPE_FOOT = ConvertMoveType(1)
constant movetype MOVE_TYPE_FLY = ConvertMoveType(2)
constant movetype MOVE_TYPE_HORSE = ConvertMoveType(4)
constant movetype MOVE_TYPE_HOVER = ConvertMoveType(8)
constant movetype MOVE_TYPE_FLOAT = ConvertMoveType(16)
constant movetype MOVE_TYPE_AMPHIBIOUS = ConvertMoveType(32)
constant movetype MOVE_TYPE_UNBUILDABLE = ConvertMoveType(64)
UNIT_IF_TARGETED_AS
constant targetflag TARGET_FLAG_NONE = ConvertTargetFlag(1)
constant targetflag TARGET_FLAG_GROUND = ConvertTargetFlag(2)
constant targetflag TARGET_FLAG_AIR = ConvertTargetFlag(4)
constant targetflag TARGET_FLAG_STRUCTURE = ConvertTargetFlag(8)
constant targetflag TARGET_FLAG_WARD = ConvertTargetFlag(16)
constant targetflag TARGET_FLAG_ITEM = ConvertTargetFlag(32)
constant targetflag TARGET_FLAG_TREE = ConvertTargetFlag(64)
constant targetflag TARGET_FLAG_WALL = ConvertTargetFlag(128)
constant targetflag TARGET_FLAG_DEBRIS = ConvertTargetFlag(256)
constant targetflag TARGET_FLAG_DECORATION = ConvertTargetFlag(512)
constant targetflag TARGET_FLAG_BRIDGE = ConvertTargetFlag(1024)
UNIT_IF_DEFENSE_TYPE
constant defensetype DEFENSE_TYPE_LIGHT = ConvertDefenseType(0)
constant defensetype DEFENSE_TYPE_MEDIUM = ConvertDefenseType(1)
constant defensetype DEFENSE_TYPE_LARGE = ConvertDefenseType(2)
constant defensetype DEFENSE_TYPE_FORT = ConvertDefenseType(3)
constant defensetype DEFENSE_TYPE_NORMAL = ConvertDefenseType(4)
constant defensetype DEFENSE_TYPE_HERO = ConvertDefenseType(5)
constant defensetype DEFENSE_TYPE_DIVINE = ConvertDefenseType(6)
constant defensetype DEFENSE_TYPE_NONE = ConvertDefenseType(7)
UNIT_IF_PRIMARY_ATTRIBUTE
constant heroattribute HERO_ATTRIBUTE_STR = ConvertHeroAttribute(1)
constant heroattribute HERO_ATTRIBUTE_INT = ConvertHeroAttribute(2)
constant heroattribute HERO_ATTRIBUTE_AGI = ConvertHeroAttribute(3)
UNIT_IF_ARMOR_TYPE
constant armortype ARMOR_TYPE_WHOKNOWS = ConvertArmorType(0)
constant armortype ARMOR_TYPE_FLESH = ConvertArmorType(1)
constant armortype ARMOR_TYPE_METAL = ConvertArmorType(2)
constant armortype ARMOR_TYPE_WOOD = ConvertArmorType(3)
constant armortype ARMOR_TYPE_ETHREAL = ConvertArmorType(4)
constant armortype ARMOR_TYPE_STONE = ConvertArmorType(5)
UNIT_IF_HIT_POINTS_REGENERATION_TYPE
constant regentype REGENERATION_TYPE_NONE = ConvertRegenType(0)
constant regentype REGENERATION_TYPE_ALWAYS = ConvertRegenType(1)
constant regentype REGENERATION_TYPE_BLIGHT = ConvertRegenType(2)
constant regentype REGENERATION_TYPE_DAY = ConvertRegenType(3)
constant regentype REGENERATION_TYPE_NIGHT = ConvertRegenType(4)
UNIT_IF_UNIT_CLASSIFICATION
constant unitcategory UNIT_CATEGORY_GIANT = ConvertUnitCategory(1)
constant unitcategory UNIT_CATEGORY_UNDEAD = ConvertUnitCategory(2)
constant unitcategory UNIT_CATEGORY_SUMMONED = ConvertUnitCategory(4)
constant unitcategory UNIT_CATEGORY_MECHANICAL = ConvertUnitCategory(8)
constant unitcategory UNIT_CATEGORY_PEON = ConvertUnitCategory(16)
constant unitcategory UNIT_CATEGORY_SAPPER = ConvertUnitCategory(32)
constant unitcategory UNIT_CATEGORY_TOWNHALL = ConvertUnitCategory(64)
constant unitcategory UNIT_CATEGORY_ANCIENT = ConvertUnitCategory(128)
constant unitcategory UNIT_CATEGORY_NEUTRAL = ConvertUnitCategory(256)
constant unitcategory UNIT_CATEGORY_WARD = ConvertUnitCategory(512)
constant unitcategory UNIT_CATEGORY_STANDON = ConvertUnitCategory(1024)
constant unitcategory UNIT_CATEGORY_TAUREN = ConvertUnitCategory(2048)
UNIT_IF_PLACEMENT_PREVENTED_BY
constant pathingflag PATHING_FLAG_UNWALKABLE = ConvertPathingFlag(2)
constant pathingflag PATHING_FLAG_UNFLYABLE = ConvertPathingFlag(4)
constant pathingflag PATHING_FLAG_UNBUILDABLE = ConvertPathingFlag(8)
constant pathingflag PATHING_FLAG_UNPEONHARVEST = ConvertPathingFlag(16)
constant pathingflag PATHING_FLAG_BLIGHTED = ConvertPathingFlag(32)
constant pathingflag PATHING_FLAG_UNFLOATABLE = ConvertPathingFlag(64)
constant pathingflag PATHING_FLAG_UNAMPHIBIOUS = ConvertPathingFlag(128)
constant pathingflag PATHING_FLAG_UNITEMPLACABLE = ConvertPathingFlag(256)
Attachments
Last edited: