library State initializer OnInit
//=================================================================
// Unit State System (USS)
// by
// Ayanami
//=================================================================
// Unit State System is a easy-to use system that modifies various
// unit properties, namely Armor, Damage, Max Health and Max Mana.
//
// Pros:
// - Easy to import (object merger creates all necessary objects)
// - Easy to use
// - Can be used in GUI via Custom script
//
// Cons:
// - Maximum of 99999 armor & damage bonus and reduction
//=================================================================
// Functions
//=================================================================
// State_SetArmor(target, value)
// - "target" is the unit that you want to give the armor bonus/reduction to
// - "value" is the integer amount of armor bonus/reduction
// - "value" being negative reduces armor, while "value" being positive increases armor
// - Support up to maximum of 99999 armor bonus/reduction
//
// State_SetDamage(target, value)
// - "target" is the unit that you want to give the damage bonus/reduction to
// - "value" is the integer amount of damage bonus/reduction
// - "value" being negative reduces damage, while "value" being positive increases damage
// - Support up to maximum of 99999 damage bonus/reduction
//
// State_ChangeMaxHealth(target, value, boolean)
// - "target" is the unit that you want to give the max health bonus/reduction to
// - "value" is the integer amount of max health bonus/reduction
// - "value" being negative reduces max health, while "value" being positive increases max health
// - "boolean" is true if you want to add/subtract current health according to increased/decreased
// max health
//
// State_SetMaxHealth(target, value, boolean)
// - "target" is the unit that you want to set its max health
// - "value" is the integer value of the max health that you want to set to
// - negative or zero "value" results in the max health to be set to 1
// - "boolean" is true if you want to add/subtract current health according to increased/decreased
// max health
//
// State_ChangeMaxMana(target, value, boolean)
// - "target" is the unit that you want to give the max mana bonus/reduction to
// - "value" is the integer amount of max mana bonus/reduction
// - "value" being negative reduces max mana, while "value" being positive increases max mana
// - "boolean" is true if you want to add/subtract current mana according to increased/decreased
// max mana
//
// State_SetMaxMana(target, value, boolean)
// - "target" is the unit that you want to set its max mana
// - "value" is the integer value of the max mana that you want to set to
// - negative or zero "value" results in the max mana to be set to 1
// - "boolean" is true if you want to add/subtract current mana according to increased/decreased
// max mana
//=================================================================
// Implementation
//=================================================================
// Requirements:
// - JNGP (JASS NewGen Pack)
//
// 1) Copy the whole "Unit State System" Trigger folder
// 2) Save the map, it will take longer than usual
// 3) Close the map and re-open it, then disable or delete the trigger "Objects"
//=================================================================
// Configurables
//=================================================================
// set to true if you want to preload those resources
globals
private constant boolean ARMORP = true // preloads all armor resources if true
private constant boolean DAMAGEP = true // preloads all damage resources if true
private constant boolean HEALTHP = true // preloads all max health resources if true
private constant boolean MANAP = true // preloads all max mana resources if true
endglobals
//=================================================================
// DO NOT TOUCH BELOW
//=================================================================
//! textmacro CreateFunc takes FUNCNAME, ID
public function $FUNCNAME$ takes unit target, integer value returns nothing
local integer i
local integer curamount = 0
local integer newvalue
local integer factor
local integer templevel
local integer array level
if value != 0 then
set i = 0
loop
set level[i] = GetUnitAbilityLevel(target, $ID$[i])
exitwhen i == 9
set i = i + 1
endloop
if level[0] == 0 then
set i = 0
loop
call UnitAddAbility(target, $ID$[i])
exitwhen i == 9
set i = i + 1
endloop
endif
// positive value check
set i = 4
set factor = 10000
loop
set curamount = curamount + (level[i] - 1) * factor
exitwhen i == 0
set factor = factor / 10
set i = i - 1
endloop
//negative value check
set i = 9
set factor = 10000
loop
set curamount = curamount - (level[i] - 1) * factor
exitwhen i == 5
set factor = factor / 10
set i = i - 1
endloop
set newvalue = curamount + value
if newvalue == 0 then
set i = 0
loop
call SetUnitAbilityLevel(target, $ID$[i], 1)
exitwhen i == 9
set i = i + 1
endloop
elseif newvalue > 0 then
set i = 4
set factor = 10000
loop
set templevel = newvalue / factor
call SetUnitAbilityLevel(target, $ID$[i], templevel + 1)
set newvalue = newvalue - (templevel * factor)
exitwhen i == 0
set factor = factor / 10
set i = i - 1
endloop
set i = 5
loop
call SetUnitAbilityLevel(target, $ID$[i], 1)
exitwhen i == 9
set i = i + 1
endloop
else
set newvalue = -newvalue
set i = 9
set factor = 10000
loop
set templevel = newvalue / factor
call SetUnitAbilityLevel(target, $ID$[i], templevel + 1)
set newvalue = newvalue - (templevel * factor)
exitwhen i == 5
set factor = factor / 10
set i = i - 1
endloop
set i = 0
loop
call SetUnitAbilityLevel(target, $ID$[i], 1)
exitwhen i == 4
set i = i + 1
endloop
endif
endif
endfunction
//! endtextmacro
//! textmacro CreateFunc2 takes FUNCNAME, ID, STATE
public function SetMax$FUNCNAME$ takes unit target, integer value, boolean change returns nothing
local integer i
local integer a
local integer newvalue
local integer factor
local integer templevel
local integer changeamount = value - R2I(GetUnitState(target, UNIT_STATE_MAX_$STATE$))
local integer array level
local real statevalue
if change then
set statevalue = GetUnitState(target, UNIT_STATE_$STATE$) + changeamount
if statevalue <= 0 then
set statevalue = 1
endif
else
set statevalue = GetUnitState(target, UNIT_STATE_$STATE$)
endif
if value <= 0 then
set newvalue = 1 - R2I(GetUnitState(target, UNIT_STATE_MAX_$STATE$))
else
set newvalue = changeamount
endif
if newvalue != 0 then
set factor = 10000
if newvalue > 0 then
set i = 6
loop
set templevel = newvalue / factor
set a = 0
loop
exitwhen a == templevel
call UnitAddAbility(target, $ID$)
call SetUnitAbilityLevel(target, $ID$, i)
call UnitRemoveAbility(target, $ID$)
set a = a + 1
endloop
set newvalue = newvalue - (templevel * factor)
exitwhen i == 1
set factor = factor / 10
set i = i - 1
endloop
else
set newvalue = -newvalue
set i = 11
loop
set templevel = newvalue / factor
set a = 0
loop
exitwhen a == templevel
call UnitAddAbility(target, $ID$)
call SetUnitAbilityLevel(target, $ID$, i)
call UnitRemoveAbility(target, $ID$)
set a = a + 1
endloop
set newvalue = newvalue - (templevel * factor)
exitwhen i == 7
set factor = factor / 10
set i = i - 1
endloop
endif
call SetUnitState(target, UNIT_STATE_$STATE$, statevalue)
endif
endfunction
public function ChangeMax$FUNCNAME$ takes unit target, integer value, boolean change returns nothing
call SetMax$FUNCNAME$(target, R2I(GetUnitState(target, UNIT_STATE_MAX_$STATE$)) + value, change)
endfunction
//! endtextmacro
//============================================================
// Armor
//============================================================
globals
private integer array ARMORID
endglobals
//! runtextmacro CreateFunc("SetArmor", "ARMORID")
//============================================================
// Damage
//============================================================
globals
private integer array DAMAGEID
endglobals
//! runtextmacro CreateFunc("SetDamage", "DAMAGEID")
//============================================================
// Health
//============================================================
globals
private integer HEALTHID
endglobals
//! runtextmacro CreateFunc2("Health", "HEALTHID", "LIFE")
//============================================================
// Mana
//============================================================
globals
private integer MANAID
endglobals
//! runtextmacro CreateFunc2("Mana", "MANAID", "MANA")
//============================================================
// Setup & Preload Objects
//============================================================
private function OnInit takes nothing returns nothing
local integer i
// create preloader
local unit u = CreateUnit(Player(13), 'pUSS', 0, 0, 0)
// setup armor
set ARMORID[0] = 'dEF0'
set ARMORID[1] = 'dEF1'
set ARMORID[2] = 'dEF2'
set ARMORID[3] = 'dEF3'
set ARMORID[4] = 'dEF4'
set ARMORID[5] = 'dEF5'
set ARMORID[6] = 'dEF6'
set ARMORID[7] = 'dEF7'
set ARMORID[8] = 'dEF8'
set ARMORID[9] = 'dEF9'
// setup damage
set DAMAGEID[0] = 'dMG0'
set DAMAGEID[1] = 'dMG1'
set DAMAGEID[2] = 'dMG2'
set DAMAGEID[3] = 'dMG3'
set DAMAGEID[4] = 'dMG4'
set DAMAGEID[5] = 'dMG5'
set DAMAGEID[6] = 'dMG6'
set DAMAGEID[7] = 'dMG7'
set DAMAGEID[8] = 'dMG8'
set DAMAGEID[9] = 'dMG9'
// setup health
set HEALTHID = 'uHPB'
// setup mana
set MANAID = 'uMPB'
//preload
set i = 0
loop
static if ARMORP then
call UnitAddAbility(u, ARMORID[i])
endif
static if DAMAGEP then
call UnitAddAbility(u, DAMAGEID[i])
endif
exitwhen i == 9
set i = i + 1
endloop
static if HEALTHP then
call UnitAddAbility(u, HEALTHID)
endif
static if MANAP then
call UnitAddAbility(u, MANAID)
endif
call RemoveUnit(u)
set u = null
endfunction
endlibrary