Romek
Super Moderator
- Reaction score
- 963
Unit States
By Romek
By Romek
Introduction:
A short, simple little library of method operators to make setting a units life, mana, strength, agility, intelligence and UserData much easier.
All the functions are inlined by JassHelper, so this doesn't add any code to your final script. It just makes it much easier to code in the first place.
How to Use:
Make a trigger (name doesn't matter), and go to Edit -> Convert to Custom Text.
Then paste the entire library into the trigger.
To utilize the system while making a map, simply use:
JASS:
set WhichUnit:WhichState = Value
And
JASS:
set <var> = WhichUnit:WhichState
You can also use WhichState[WhichUnit] everywhere. Although using the colon looks cleaner.
You can change the following:
- Life (Health, HP)
- Mana (MP)
- Strength (Str)
- Agility (Agi)
- Intelligence (Intel, Int)
- User Data (Value, Data)
- X Position
- Y Position
- Z Position (Height)
- Unit Facing
- Animation (Returns "")
- Owner
- Move Speed
Examples:
JASS:
set GetTriggerUnit():Life = 600.
set someUnit:Str = 666
local integer val = Unit<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />ata
set WhichUnit:Owner = Player(6)
The Code:
JASS:
// +------------------------------------------+
// | -= U N I T S T A T E S =- |
// | By Romek (v1.5) |
// +---------+------------------------------------------+---------+
// | A simple library which makes setting unit states much easier |
// | than it has ever been, in a simple efficient manner. |
// +--------------------------------------------------------------+
// | Instead of using GetUnitState(..) or SetUnitState(..) use: |
// | set unit:State = value or State[unit] = value |
// | For example: |
// | - set GetTriggerUnit():Life = 700. |
// | - set whichUnit:Mana = 300. |
// | - local integer i = Unit:Strength |
// | - set SomeUnit:Owner = Player(5) |
// +--------------------------------------------------------------+
// | You can use the following 'States': (Name | Alt. Name) |
// | - Life - Health - HP |
// | - Mana - MP |
// | - Strength - Str |
// | - Agility - Agi |
// | - Intelligence - Intel - Int |
// | - Data - Value (UnitUserData) |
// | - X (X Position) |
// | - Y (Y Position) |
// | - Loc - Location |
// | - Z - Height (Z Position) |
// | - Face - Facing - Degrees |
// | - Radians (Facing in Radians) |
// | - Animation - Anim (Returns "") |
// | - Owner |
// | - MoveSpeed - Speed |
// +--------------------------------------------------------------+
// | All functions are inlined by JassHelper. |
// +--------------------------------------------------------------+
library UnitStates
//! textmacro State__UState takes name, type, in, out
struct $name$ extends array
static method operator []= takes unit u, $type$ val returns nothing
call $in$
endmethod
static method operator [] takes unit u returns $type$
return $out$
endmethod
endstruct
//! endtextmacro
//! runtextmacro State__UState("Life", "real", "SetWidgetLife(u, val)", "GetWidgetLife(u)")
//! runtextmacro State__UState("Health", "real", "SetWidgetLife(u, val)", "GetWidgetLife(u)")
//! runtextmacro State__UState("HP", "real", "SetWidgetLife(u, val)", "GetWidgetLife(u)")
//! runtextmacro State__UState("Mana", "real", "SetUnitState(u, UNIT_STATE_MANA, val)", "GetUnitState(u, UNIT_STATE_MANA)")
//! runtextmacro State__UState("MP", "real", "SetUnitState(u, UNIT_STATE_MANA, val)", "GetUnitState(u, UNIT_STATE_MANA)")
//! runtextmacro State__UState("Strength", "integer", "SetHeroStr(u, val, false)", "GetHeroStr(u, true)")
//! runtextmacro State__UState("Str", "integer", "SetHeroStr(u, val, false)", "GetHeroStr(u, true)")
//! runtextmacro State__UState("Agilty", "integer", "SetHeroAgi(u, val, false)", "GetHeroAgi(u, true)")
//! runtextmacro State__UState("Agi", "integer", "SetHeroAgi(u, val, false)", "GetHeroAgi(u, true)")
//! runtextmacro State__UState("Intelligence", "integer", "SetHeroInt(u, val, false)", "GetHeroInt(u, true)")
//! runtextmacro State__UState("Intel", "integer", "SetHeroInt(u, val, false)", "GetHeroInt(u, true)")
//! runtextmacro State__UState("Int", "integer", "SetHeroInt(u, val, false)", "GetHeroInt(u, true)")
//! runtextmacro State__UState("Data", "integer", "SetUnitUserData(u, val)", "GetUnitUserData(u)")
//! runtextmacro State__UState("Value", "integer", "SetUnitUserData(u, val)", "GetUnitUserData(u)")
//! runtextmacro State__UState("X", "real", "SetUnitX(u, val)", "GetUnitX(u)")
//! runtextmacro State__UState("Y", "real", "SetUnitY(u, val)", "GetUnitY(u)")
//! runtextmacro State__UState("Location", "location", "SetUnitPositionLoc(u, val)", "GetUnitLoc(u)")
//! runtextmacro State__UState("Loc", "location", "SetUnitPositionLoc(u, val)", "GetUnitLoc(u)")
//! runtextmacro State__UState("Z", "real", "SetUnitFlyHeight(u, val, 0.)", "GetUnitFlyHeight(u)")
//! runtextmacro State__UState("Height", "real", "SetUnitFlyHeight(u, val, 0.)", "GetUnitFlyHeight(u)")
//! runtextmacro State__UState("Face", "real", "SetUnitFacing(u, val)", "GetUnitFacing(u)")
//! runtextmacro State__UState("Facing", "real", "SetUnitFacing(u, val)", "GetUnitFacing(u)")
//! runtextmacro State__UState("Degrees", "real", "SetUnitFacing(u, val)", "GetUnitFacing(u)")
//! runtextmacro State__UState("Radians", "real", "SetUnitFacing(u, val)", "GetUnitFacing(u)*bj_DEGTORAD")
//! runtextmacro State__UState("Anim", "string", "SetUnitAnimation(u, val)", "\"\"")
//! runtextmacro State__UState("Animation", "string", "SetUnitAnimation(u, val)", "\"\"")
//! runtextmacro State__UState("Owner", "player", "SetUnitOwner(u, val, true)", "GetOwningPlayer(u)")
//! runtextmacro State__UState("Speed", "real", "SetUnitMoveSpeed(u, val)", "GetUnitMoveSpeed(u)")
//! runtextmacro State__UState("MoveSpeed", "real", "SetUnitMoveSpeed(u, val)", "GetUnitMoveSpeed(u)")
endlibrary
Capital Names Edition:
JASS:
// +------------------------------------------+
// | -= U N I T S T A T E S =- |
// | By Romek (v1.5) |
// | -> CAPITAL Edition <- |
// +---------+------------------------------------------+---------+
// | A simple library which makes setting unit states much easier |
// | than it has ever been, in a simple efficient manner. |
// +--------------------------------------------------------------+
// | Instead of using GetUnitState(..) or SetUnitState(..) use: |
// | set unit:State = value or State[unit] = value |
// | For example: |
// | - set GetTriggerUnit():LIFE = 700. |
// | - set whichUnit:MANA = 300. |
// | - local integer i = Unit:STRENGTH |
// | - set SomeUnit:OWNER = Player(5) |
// +--------------------------------------------------------------+
// | You can use the following 'States': (Name | Alt. Name) |
// | - LIFE - HEALTH - HP |
// | - MANA - MP |
// | - STRENGTH - STR |
// | - AGILITY - AGI |
// | - INTELLIGENCE - INTEL - INT |
// | - DATA - VALUE (UnitUserData) |
// | - X (X Position) |
// | - Y (Y Position) |
// | - LOC - LOCATION |
// | - Z - HEIGHT (Z Position) |
// | - FACE - FACING - DEGREES |
// | - RADIANS (Facing in Radians) |
// | - ANIMATION - ANIM (Returns "") |
// | - OWNER |
// | - MOVESPEED - SPEED |
// +--------------------------------------------------------------+
// | All functions are inlined by JassHelper. |
// +--------------------------------------------------------------+
library UnitStatesCaps
//! textmacro State__UCState takes name, type, in, out
struct $name$ extends array
static method operator []= takes unit u, $type$ val returns nothing
call $in$
endmethod
static method operator [] takes unit u returns $type$
return $out$
endmethod
endstruct
//! endtextmacro
//! runtextmacro State__UCState("LIFE", "real", "SetWidgetLife(u, val)", "GetWidgetLife(u)")
//! runtextmacro State__UCState("HEALTH", "real", "SetWidgetLife(u, val)", "GetWidgetLife(u)")
//! runtextmacro State__UCState("HP", "real", "SetWidgetLife(u, val)", "GetWidgetLife(u)")
//! runtextmacro State__UCState("MANA", "real", "SetUnitState(u, UNIT_STATE_MANA, val)", "GetUnitState(u, UNIT_STATE_MANA)")
//! runtextmacro State__UCState("MP", "real", "SetUnitState(u, UNIT_STATE_MANA, val)", "GetUnitState(u, UNIT_STATE_MANA)")
//! runtextmacro State__UCState("STRENGTH", "integer", "SetHeroStr(u, val, false)", "GetHeroStr(u, true)")
//! runtextmacro State__UCState("STR", "integer", "SetHeroStr(u, val, false)", "GetHeroStr(u, true)")
//! runtextmacro State__UCState("AGILITY", "integer", "SetHeroAgi(u, val, false)", "GetHeroAgi(u, true)")
//! runtextmacro State__UCState("AGI", "integer", "SetHeroAgi(u, val, false)", "GetHeroAgi(u, true)")
//! runtextmacro State__UCState("INTELLIGENCE", "integer", "SetHeroInt(u, val, false)", "GetHeroInt(u, true)")
//! runtextmacro State__UCState("INTEL", "integer", "SetHeroInt(u, val, false)", "GetHeroInt(u, true)")
//! runtextmacro State__UCState("INT", "integer", "SetHeroInt(u, val, false)", "GetHeroInt(u, true)")
//! runtextmacro State__UCState("DATA", "integer", "SetUnitUserData(u, val)", "GetUnitUserData(u)")
//! runtextmacro State__UCState("VALUE", "integer", "SetUnitUserData(u, val)", "GetUnitUserData(u)")
//! runtextmacro State__UCState("X", "real", "SetUnitX(u, val)", "GetUnitX(u)")
//! runtextmacro State__UCState("Y", "real", "SetUnitY(u, val)", "GetUnitY(u)")
//! runtextmacro State__UCState("LOCATION", "location", "SetUnitPositionLoc(u, val)", "GetUnitLoc(u)")
//! runtextmacro State__UCState("LOC", "location", "SetUnitPositionLoc(u, val)", "GetUnitLoc(u)")
//! runtextmacro State__UCState("Z", "real", "SetUnitFlyHeight(u, val, 0.)", "GetUnitFlyHeight(u)")
//! runtextmacro State__UCState("HEIGHT", "real", "SetUnitFlyHeight(u, val, 0.)", "GetUnitFlyHeight(u)")
//! runtextmacro State__UCState("FACE", "real", "SetUnitFacing(u, val)", "GetUnitFacing(u)")
//! runtextmacro State__UCState("FACING", "real", "SetUnitFacing(u, val)", "GetUnitFacing(u)")
//! runtextmacro State__UCState("DEGREES", "real", "SetUnitFacing(u, val)", "GetUnitFacing(u)")
//! runtextmacro State__UCState("RADIANS", "real", "SetUnitFacing(u, val)", "GetUnitFacing(u)*bj_DEGTORAD")
//! runtextmacro State__UCState("ANIM", "string", "SetUnitAnimation(u, val)", "\"\"")
//! runtextmacro State__UCState("ANIMATION", "string", "SetUnitAnimation(u, val)", "\"\"")
//! runtextmacro State__UCState("OWNER", "player", "SetUnitOwner(u, val, true)", "GetOwningPlayer(u)")
//! runtextmacro State__UCState("SPEED", "real", "SetUnitMoveSpeed(u, val)", "GetUnitMoveSpeed(u)")
//! runtextmacro State__UCState("MOVESPEED", "real", "SetUnitMoveSpeed(u, val)", "GetUnitMoveSpeed(u)")
endlibrary