//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
TempUnit | unit | No |
//TESH.scrollpos=343
//TESH.alwaysfold=0
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
//TESH.scrollpos=0
//TESH.alwaysfold=0
//create preloader
//! external ObjectMerger w3u nalb pUSS uabi Aloc ucbs 0 udtm 0 ushr 0 umdl "none.mdl" usca 0.1 ushu "None" util " " umvh 0 umvf 0 umvs 0 umas 0 umis 0 ucol 0 urac "human" unam "Unit State System Preloader" utip " " utub " " usid 0 usin 0
// create armor objects
//! textmacro CreateObj takes CODE, NAME, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN
//! external ObjectMerger w3a AId1 dEF$CODE$ aart "" anam "Unit State System" ansf "$NAME$" aite 0 alev 10 Idef 1 $ONE$ Idef 2 $TWO$ Idef 3 $THREE$ Idef 4 $FOUR$ Idef 5 $FIVE$ Idef 6 $SIX$ Idef 7 $SEVEN$ Idef 8 $EIGHT$ Idef 9 $NINE$ Idef 10 $TEN$
//! endtextmacro
//! runtextmacro CreateObj("0", "(Armor - 1's)", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
//! runtextmacro CreateObj("1", "(Armor - 10's)", "0", "10", "20", "30", "40", "50", "60", "70", "80", "90")
//! runtextmacro CreateObj("2", "(Armor - 100's)", "0", "100", "200", "300", "400", "500", "600", "700", "800", "900")
//! runtextmacro CreateObj("3", "(Armor - 1000's)", "0", "1000", "2000", "3000", "4000", "5000", "6000", "7000", "8000", "9000")
//! runtextmacro CreateObj("4", "(Armor - 10000's)", "0", "10000", "20000", "30000", "40000", "50000", "60000", "70000", "80000", "90000")
//! runtextmacro CreateObj("5", "(Armor - -1's)", "0", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9")
//! runtextmacro CreateObj("6", "(Armor - -10's)", "0", "-10", "-20", "-30", "-40", "-50", "-60", "-70", "-80", "-90")
//! runtextmacro CreateObj("7", "(Armor - -100's)", "0", "-100", "-200", "-300", "-400", "-500", "-600", "-700", "-800", "-900")
//! runtextmacro CreateObj("8", "(Armor - -1000's)", "0", "-1000", "-2000", "-3000", "-4000", "-5000", "-6000", "-7000", "-8000", "-9000")
//! runtextmacro CreateObj("9", "(Armor - -10000's)", "0", "-10000", "-20000", "-30000", "-40000", "-50000", "-60000", "-70000", "-80000", "-90000")
// create damage objects
//! textmacro CreateObj2 takes CODE, NAME, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN
//! external ObjectMerger w3a AItg dMG$CODE$ aart "" anam "Unit State System" ansf "$NAME$" aite 0 alev 10 Iatt 1 $ONE$ Iatt 2 $TWO$ Iatt 3 $THREE$ Iatt 4 $FOUR$ Iatt 5 $FIVE$ Iatt 6 $SIX$ Iatt 7 $SEVEN$ Iatt 8 $EIGHT$ Iatt 9 $NINE$ Iatt 10 $TEN$
//! endtextmacro
//! runtextmacro CreateObj2("0", "(Damage - 1's)", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
//! runtextmacro CreateObj2("1", "(Damage - 10's)", "0", "10", "20", "30", "40", "50", "60", "70", "80", "90")
//! runtextmacro CreateObj2("2", "(Damage - 100's)", "0", "100", "200", "300", "400", "500", "600", "700", "800", "900")
//! runtextmacro CreateObj2("3", "(Damage - 1000's)", "0", "1000", "2000", "3000", "4000", "5000", "6000", "7000", "8000", "9000")
//! runtextmacro CreateObj2("4", "(Damage - 10000's)", "0", "10000", "20000", "30000", "40000", "50000", "60000", "70000", "80000", "90000")
//! runtextmacro CreateObj2("5", "(Damage - -1's)", "0", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9")
//! runtextmacro CreateObj2("6", "(Damage - -10's)", "0", "-10", "-20", "-30", "-40", "-50", "-60", "-70", "-80", "-90")
//! runtextmacro CreateObj2("7", "(Damage - -100's)", "0", "-100", "-200", "-300", "-400", "-500", "-600", "-700", "-800", "-900")
//! runtextmacro CreateObj2("8", "(Damage - -1000's)", "0", "-1000", "-2000", "-3000", "-4000", "-5000", "-6000", "-7000", "-8000", "-9000")
//! runtextmacro CreateObj2("9", "(Damage - -10000's)", "0", "-10000", "-20000", "-30000", "-40000", "-50000", "-60000", "-70000", "-80000", "-90000")
// create health objects
//! external ObjectMerger w3a AIl1 uHPB aart "" anam "Unit State System" ansf "(Health)" aite 0 alev 11 Ilif 1 0 Ilif 2 -1 Ilif 3 -10 Ilif 4 -100 Ilif 5 -1000 Ilif 6 -10000 Ilif 7 1 Ilif 8 10 Ilif 9 100 Ilif 10 1000 Ilif 11 10000
// create mana objects
//! external ObjectMerger w3a AIbm uMPB aart "" anam "Unit State System" ansf "(Mana)" aite 0 alev 11 Iman 1 0 Iman 2 -1 Iman 3 -10 Iman 4 -100 Iman 5 -1000 Iman 6 -10000 Iman 7 1 Iman 8 10 Iman 9 100 Iman 10 1000 Iman 11 10000