function chr takes integer i returns string
local string abc = "abcdefghijklmnopqrstuvwxyz"
local string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local string digits = "0123456789"
if i >= 65 and i <= 90 then
return SubString(ABC, i-65,i-64)
elseif i >= 97 and i <= 122 then
return SubString(abc, i-97,i-96)
elseif i >= 48 and i <= 57 then
return SubString(digits, i-48,i-47)
endif
return ""
endfunction
function CPos takes string StrData, string ToFind, integer From returns integer
local integer FromPos = From
loop
exitwhen (SubString(StrData, FromPos, FromPos+1) == ToFind) or (SubString(StrData, FromPos, FromPos+1) == "")
set FromPos = FromPos + 1
endloop
if (SubString(StrData, FromPos, FromPos+1) == ToFind) then
return FromPos
endif
return -1
endfunction
function int takes string Str returns integer
local integer Pos = CPos("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Str, 0) + 65
if Pos == 64 then
set Pos = CPos("0123456789", Str, 0) + 48
endif
if Pos == 47 then
set Pos = CPos("abcdefghijklmnopqrstuvwxyz", Str, 0) + 97
endif
if (Str == "") then
return 0
else
return Pos
endif
endfunction
function ID2String takes integer itemid returns string
return chr(itemid/256/256/256) + chr(ModuloInteger(itemid/256/256, 256)) + chr(ModuloInteger(itemid/256, 256)) + chr(ModuloInteger(itemid, 256))
endfunction
function String2ID takes string str returns integer
return int(SubString(str,0,1))*256*256*256 + int(SubString(str,1,2))*256*256 + int(SubString(str,2,3))*256 + int(SubString(str,3,4))
endfunction
function RunSkillCodeForUnit takes unit u returns nothing
local integer i = 1
local integer end = GetStoredInteger(udg_cache, "MaxHeroLevel", "") * 4
local string unitID = UnitId2String(GetUnitTypeId(u))
local string skillcode = GetStoredString(udg_cache, "SkillCodeFor", unitID)
loop
exitwhen i > end
call SelectHeroSkill(u, String2ID(SubStringBJ(skillcode, i, i + 4)))
set i = i + 4
endloop
set unitID = null
set skillcode = null
endfunction
Name | Type | is_array | initial_value |
cache | gamecache | No | |
Warden | unit | No |
//===========================================================================
function InitTrig_SCS_vars takes nothing returns nothing
set udg_cache = InitGameCache("WardenAiSystem.w3v") // Инициализация кэша
call StoreInteger (udg_cache, "MaxHeroLevel", "", 10) // Максимальный уровень героя
endfunction
function InitTrig_Human takes nothing returns nothing
//===========================================================================================================================
// ################################# Human #################################
//===========================================================================================================================
local string h = UnitId2String('Hpal') // Paladin
local string s1 = "AHhb" // Holy Light
local string s2 = "AHds" // Divine Shield
local string s3 = "AHad" // Devotion Aura
local string s4 = "AHre" // Resurrection
local string skillcode = s1+s2+s4+s1+s2+s4+s1+s2+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Hamg') // Archmage
set s1 = "AHbz" // Blizzard
set s2 = "AHwe" // Brilliance Aura
set s3 = "AHab" // Water Elemental
set s4 = "AHmt" // Mass Teleport
set skillcode = s1+s2+s3+s1+s2+s4+s3+s1+s2+s3
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Hmkg') // Mountain King
set s1 = "AHtb" // Storm Bolt
set s2 = "AHtc" // Thunder Clap
set s3 = "AHab" // Bash
set s4 = "AHav" // Avatar
set skillcode = s1+s2+s1+s2+s4+s3+s1+s2+s2+s3+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Hblm') // Blood Mage
set s1 = "AHfs" // Flame Strike
set s2 = "AHbn" // Banish
set s3 = "AHdr" // Siphon Mana
set s4 = "AHpx" // Phoenix
set skillcode = s3+s2+s1+s4+s3+s2+s1+s3+s2+s1
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
endfunction
function InitTrig_Orc takes nothing returns nothing
//===========================================================================================================================
// ################################# Orc #################################
//===========================================================================================================================
local string h = UnitId2String('Obla') // Blademaster
local string s1 = "AOwk" // Wind Walk
local string s2 = "AOmi" // Mirror Image
local string s3 = "AOcr" // Critical Strike
local string s4 = "AOww" // Bladestorm
local string skillcode = s1+s3+s1+s3+s2+s1+s3+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Ofar') // Far Seer
set s1 = "AOcl" // Chain Lighting
set s2 = "AOsf" // Feral Spirit
set s3 = "AOfs" // Far Sight
set s4 = "AOeq" // EarthQuake
set skillcode = s3+s1+s2+s1+s1+s4+s1+s1+s2
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Otch') // Tauren Chieftan
set s1 = "AOsh" // Shockwave
set s2 = "AOws" // War Stomp
set s3 = "AOae" // Endurance Aura
set s4 = "AOws" // Reincarnation
set skillcode = s1+s3+s2+s1+s1+s1+s4+s1+s3+s2+s1+s1+s1
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Oshd') // Shadow Hunter
set s1 = "AOhw" // Healing Wave
set s2 = "AOsw" // Serpent Ward
set s3 = "AOhx" // Hex
set s4 = "AOvd" // Big Bad Voodoo
set skillcode = s3+s2+s2+s3+s1+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
endfunction
function InitTrig_Undead takes nothing returns nothing
//===========================================================================================================================
// ################################# Undead #################################
//===========================================================================================================================
local string h = UnitId2String('Udea') // DeathKnight
local string s1 = "AUdc" // Death Coil
local string s2 = "AUdp" // Death Pact
local string s3 = "AUau" // Unholy Aura
local string s4 = "AUan" // Animate Dead
local string skillcode = s1+s2+s1+s2+s4+s1+s2+s1+s2+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Ulic') // Lich
set s1 = "AUfn" // Frost Nova
set s2 = "AUfu" // Frost Armor
set s3 = "AUdr" // Dark Ritual
set s4 = "AUdd" // Death and Decay
set skillcode = s1+s2+s3+s1+s2+s4+s3+s1+s2+s3
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Udre') // Dreadlord
set s1 = "AUav" // Vamp Aura
set s2 = "AUsl" // Sleep
set s3 = "AUcs" // Carrion Swarm
set s4 = "AUin" // Inferno
set skillcode = s2+s1+s1+s1+s4+s3+s2+s1+s1+s3
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Ucrl') // Crypt Lord
set s1 = "AUim" // Impale
set s2 = "AUcb" // Carrion Beetles
set s3 = "AUts" // Spicked Carapace
set s4 = "AUls" // Locust Swarm
set skillcode = s1+s2+s3+s1+s2+s4+s3+s2+s3+s1
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
endfunction
function InitTrig_Night_Elf takes nothing returns nothing
//===========================================================================================================================
// ################################# NightElf #################################
//===========================================================================================================================
local string h = UnitId2String('Ekee') // Keeper Of Grove
local string s1 = "AEer" // Entangling Roots
local string s2 = "AEfn" // Force of Nature
local string s3 = "AEah" // Thorns Aura
local string s4 = "AEtq" // Tranquility
local string skillcode = s1+s2+s3+s1+s3+s2+s4+s3+s1+s2
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Emoo') // Priestess of Moon
set s1 = "AHfa" // Searing Arrows
set s2 = "AEst" // Scout
set s3 = "AEar" // Trueshot Aura
set s4 = "AEsf" // Starfall
set skillcode = s2+s1+s1+s3+s1+s1+s1+s3+s1+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Edem') // Demon Hunter
set s1 = "AEmb" // Mana Burn
set s2 = "AEim" // Immolition
set s3 = "AEev" // Evasion
set s4 = "AEme" // Metamorphosis
set skillcode = s1+s2+s1+s3+s1+s1+s1+s4+s4+s4+s1
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Ewar') //Warden
set s1 = "AEfk" // Fan of knives
set s2 = "AEsh" // Shadow Strike
set s3 = "AEbl" // Blink
set s4 = "AEsv" // Vengence
set skillcode = s1+s2+s3+s1+s2+s4+s3+s1+s2+s3
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
endfunction
function InitTrig_Neutral takes nothing returns nothing
//===========================================================================================================================
// ################################# Neutral #################################
//===========================================================================================================================
local string h = UnitId2String('Nalc') //Alchemist
local string s1 = "ANhs" // Healing Spray
local string s2 = "ANab" // Acid Bomb
local string s3 = "ANcr" // Chemical Rage
local string s4 = "ANtm" // Transmute
local string skillcode = s3+s2+s2+s1+s1+s4+s2+s2+s1+s1+s3+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Nngs') //Naga Sea Witch
set s1 = "ANfl" // Forked Lighting
set s2 = "ANfa" // Frost Arrows
set s3 = "ANms" // Mana Shield
set s4 = "ANto" //Torando
set skillcode = s1+s2+s3+s1+s2+s4+s1+s2+s2+s1
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Ntin') //Tinker
set s1 = "ANsy" // Pocket Factory
set s2 = "ANcs" // Cluster Rockets
set s3 = "ANeg" // Engineering Upgrade
set s4 = "ANrg" // Robo-Goblin
set skillcode = s2+s1+s3+s2+s2+s1+s4+s1+s2+s1
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Nbst') //Beast Master
set s1 = "ANsg" // Summon Bear
set s2 = "ANsq" // Summon Quilbeast
set s3 = "ANsw" // Summon Hawk
set s4 = "ANst" // Stampede
set skillcode = s1+s2+s3+s1+s4+s1+s2+s3+s1+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Nbrn') //Dark Ranger
set s1 = "ANsi" // Silence
set s2 = "ANba" // Black Arrow
set s3 = "ANdr" // Life Drain
set s4 = "ANch" // Charm
set skillcode = s1+s2+s2+s3+s2+s1+s2+s3+s4+s3+s2+s1
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Nfir') //Firelord
set s1 = "ANic," // Incinerate
set s2 = "ANso," // Soul Burn
set s3 = "ANlm" // Summon Lava Spawn
set s4 = "ANvc" // Volcano
set skillcode = s2+s2+s2+s3+s3+s3+s4+s4+s2
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Npbm') //Panda Brewmaster
set s1 = "ANbf" // Breath of fire
set s2 = "ANdh" // Drunken Haze
set s3 = "ANdb" // Drunken Brawler
set s4 = "ANef" // Storm Earth Fire
set skillcode = s2+s3+s1+s2+s3+s1+s4
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
//===========================================================================================================================
set h = UnitId2String('Nplh') //Pit Lord
set s1 = "ANrf" // Rain of Fire
set s2 = "ANht" // Howl of Terror
set s3 = "ANca" // Cleaving Attack
set s4 = "ANdo" // Doom
set skillcode = s1+s1+s3+s3+s2+s4+s4+s2+s3+s1
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
endfunction
function InitTrig_Your_Hero takes nothing returns nothing
local string h = UnitId2String('Ewar') //Hero
local string s1 = "AEfk" // Skill 1
local string s2 = "AEsh" // Skill 2
local string s3 = "AEbl" // Skill 3
local string s4 = "AEsv" // Ultimate
local string skillcode = s1+s2+s3+s1+s2+s4+s3+s1+s2+s3 //Order skills are used in
call StoreString (udg_cache, "SkillCodeFor", h, skillcode)
endfunction
//TESH.scrollpos=332
//TESH.alwaysfold=0
///////////////////////////////////////////////////////
/// Strilanc's Spread Unit Event Library
/// Last Updated: April 2, 2008
/// Version: 1.01
///////////////////////////////////////////////////////
/// Summary:
/// - This library allows you to take any specific unit event and efficiently turn
/// it into an event for multiple units.
/// - The main advantage of this library is there is no overhead at all. Work is ONLY
/// done when units are added.
///
/// Explanation:
/// - A spread event is made up of three groups: [Inlet], [Filter], and [Buffer].
/// - When a unit is added, it is placed in the [Inlet] group and 2 units in the [Filter]
/// group are processed.
/// - When a unit is processed it goes to the [Buffer] group, unless it is decayed. Decayed
/// units are removed from the system.
/// - When the [Filter] group empties, the groups are rotated so [Inlet] becomes [Filter],
/// [Filter] becomes [Buffer], and [Buffer] becomes [Inlet].
/// - The rotation and processing guarantee that decayed units in the system are slowly
/// filtered out as more units are added.
///
/// Usage:
/// - Set the system settings just below this big comment block
/// - Create spread events using SpreadUnitEvent.create(unitevent)
/// - Add units to the event as necessary using .addUnit(unit)
/// - Add groups of units using .addGroup(group) or .addUnitsMatching(boolexpr)
/// - Add functions to call when the event fires using .register(code)
/// - Sit back and relax! Everything else is taken care of!
///
/// Notes:
/// - The code uses GetUnitTypeId(unit) == 0 to detect decayed units
/// - The code uses some acrobatics to store code variables in an integer array
///////////////////////////////////////////////////////
library SUEL initializer initSUEL
globals
//Should the system show debug messages? (only when in debug mode)
private constant boolean SHOW_DEBUG_MESSAGES = true
//Should the system show messages when things go obviously wrong?
private constant boolean SHOW_ERROR_MESSAGES = true
endglobals
//===================================================================================================
//===================================================================================================
//===================================================================================================
globals
//indirect argument for .addEnumUnit
private SpreadUnitEvent activeSUE = 0
endglobals
///Stores a stack of code variables
///also provides room to keep trigger actions
private struct CodeStack
private integer address
public CodeStack next
public triggeraction taFilter
public triggeraction taInlet
///Converts unsafe code to code
private static method UC2C takes code c returns code
return c
endmethod
///Converts an integer to unsafe code
private static method I2UC takes integer i returns code
return i
return null
endmethod
///Converts code to an integer
private static method C2I takes code c returns integer
return c
return 0
endmethod
///Returns the code stored in this node
public method getCode takes nothing returns code
return CodeStack.UC2C(CodeStack.I2UC(.address))
endmethod
///Creates a new stack node
public static method create takes code c, CodeStack next returns CodeStack
local CodeStack s = CodeStack.allocate()
if s == 0 then
if SHOW_ERROR_MESSAGES then
call BJDebugMsg("Map Error: Couldn't allocate a CodeStack node. (CodeStack.create)")
endif
return 0
endif
set s.address = CodeStack.C2I(c)
set s.next = next
return s
endmethod
private method onDestroy takes nothing returns nothing
set .taFilter = null
set .taInlet = null
endmethod
///Destroys the entire stack
public method recursiveDestroy takes nothing returns nothing
if this != 0 then
if .next != 0 then
call .next.recursiveDestroy()
endif
call .destroy()
endif
endmethod
endstruct
///Stores a stack of units
private struct UnitStack
readonly unit u
public UnitStack next
///Creates a new stack node
public static method create takes unit u, UnitStack next returns UnitStack
local UnitStack s = UnitStack.allocate()
if s == 0 then
if SHOW_ERROR_MESSAGES then
call BJDebugMsg("Map Error: Couldn't allocate a UnitStack node. (UnitStack.create)")
endif
return 0
endif
set s.u = u
set s.next = next
return s
endmethod
private method onDestroy takes nothing returns nothing
set .u = null
endmethod
///Destroys the entire stack
public method recursiveDestroy takes nothing returns nothing
if this != 0 then
if .next != 0 then
call .next.recursiveDestroy()
endif
call .destroy()
endif
endmethod
endstruct
///A structure which efficiently applies single unit events to many units
///[Inlet] == The group units are added into from outside the system
///[Filter] == The group where decayed units are removed from units going to [Buffer]
///[Buffer] == The group units are held in until [Filter] finishes
///The groups rotate when [Filter] empties
struct SpreadUnitEvent
private unitevent unitEventId
private UnitStack stackInlet = 0
private UnitStack stackFilter = 0
private UnitStack stackBuffer = 0
private trigger trigInlet = CreateTrigger()
private trigger trigFilter = CreateTrigger()
private trigger trigBuffer = CreateTrigger()
private integer numInlet = 0
private integer numFilter = 0
private integer numBuffer = 0
private CodeStack stackCode = 0
///Adds a callback function
public method register takes code c returns nothing
set .stackCode = CodeStack.create(c, .stackCode)
set .stackCode.taInlet = TriggerAddAction(.trigInlet, c)
set .stackCode.taFilter = TriggerAddAction(.trigFilter, c)
endmethod
///Summarizes the state of the groups
public method toString takes nothing returns string
local string s = ""
set s = s + "Inlet=|cFFFFCC00"+I2S(.numInlet)+"|r"
set s = s + ", Filter=|cFFFF8000"+I2S(.numFilter) + "|r"
set s = s + ", Buffer=|cFF00FF00"+I2S(.numBuffer)+"|r"
set s = s + ", Total="+I2S(.numBuffer+.numFilter+.numInlet)
return s
endmethod
///Rotates the groups
///[Inlet] -> [Filter] -> [Buffer] -> [Inlet]
private method rotate takes nothing returns nothing
local UnitStack stackTemp
local trigger trigTemp
local integer numTemp
local CodeStack s
if .numBuffer + .numInlet <= 0 then
return
endif
//Rotate trigger actions
//[Buffer] ends up with no actions after rotation, to avoid double-events
//(because [Filter] still has the unit event of any unit passed to [Buffer])
set s = .stackCode
loop
exitwhen s == 0
call TriggerRemoveAction(.trigFilter, s.taFilter)
set s.taFilter = s.taInlet
set s.taInlet = TriggerAddAction(.trigBuffer, s.getCode())
set s = s.next
endloop
//Clear unit events from [Filter] (since its empty)
call DestroyTrigger(.trigFilter)
set .trigFilter= CreateTrigger()
//Rotate triggers
set trigTemp = .trigFilter
set .trigFilter = .trigInlet
set .trigInlet = .trigBuffer
set .trigBuffer = trigTemp
set trigTemp = null
//Rotate counts
set numTemp = .numFilter
set .numFilter = .numInlet
set .numInlet = .numBuffer
set .numBuffer = numTemp
//Rotate units
set stackTemp = .stackFilter
set .stackFilter = .stackInlet
set .stackInlet = .stackBuffer
set .stackBuffer = stackTemp
endmethod
///Processes a unit in [Filter]
///Decayed units are removed, others go to [Buffer]
///Rotates the groups when [Filter] is empty
private method filter takes nothing returns nothing
local unit u
local UnitStack s
if .numFilter <= 0 then
call .rotate()
return
endif
//Process top unit
set s = .stackFilter
set u = s.u
set .stackFilter = .stackFilter.next
set .numFilter = .numFilter - 1
if GetUnitTypeId(u) != 0 then //only decayed units have an id of 0
//pass active units to [Buffer]
set s.next = .stackBuffer
set .stackBuffer = s
call TriggerRegisterUnitEvent(.trigBuffer, u, .unitEventId)
set .numBuffer = .numBuffer + 1
else
//removed decayed units
call s.destroy()
endif
set u = null
endmethod
///Adds a unit to [Inlet]
public method addUnit takes unit u returns nothing
if this == 0 then
return
endif
//add unit to [Inlet]
set .stackInlet = UnitStack.create(u, .stackInlet)
set .numInlet = .numInlet + 1
call TriggerRegisterUnitEvent(.trigInlet, u, .unitEventId)
//process two units in [Filter]
call .filter()
call .filter()
//debug status
debug if SHOW_DEBUG_MESSAGES then
debug call BJDebugMsg("Added to SpreadUnitEvent #" + I2S(this))
debug call BJDebugMsg(.toString())
debug endif
endmethod
///Adds a group of units to the system
private static method addEnumUnit takes nothing returns nothing
call activeSUE.addUnit(GetEnumUnit())
endmethod
public method addGroup takes group g returns nothing
if this == 0 then
return
endif
set activeSUE = this
call ForGroup(g, function SpreadUnitEvent.addEnumUnit)
endmethod
///Adds all units on the map matching the filter
public method addUnitsMatching takes boolexpr filter returns nothing
local group g
local rect r
if this == 0 then
return
endif
//add units
set g = CreateGroup()
set r = GetWorldBounds()
call GroupEnumUnitsInRect(g, r, filter)
call .addGroup(g)
//clean
call DestroyGroup(g)
call RemoveRect(r)
call DestroyBoolExpr(filter)
set g = null
set r = null
endmethod
///Creates a spreaded for the given event type
public static method create takes unitevent unitEventId returns SpreadUnitEvent
local SpreadUnitEvent e = SpreadUnitEvent.allocate()
if e == 0 then
if SHOW_ERROR_MESSAGES then
call BJDebugMsg("Map Error: Couldn't allocate a SpreadUnitEvent. (SpreadUnitEvent.create)")
endif
return 0
endif
set e.unitEventId = unitEventId
return e
endmethod
///Cleans up properly
private method onDestroy takes nothing returns nothing
//trigger actions
local CodeStack s = .stackCode
loop
exitwhen s == 0
call TriggerRemoveAction(.trigFilter, s.taFilter)
call TriggerRemoveAction(.trigInlet, s.taInlet)
set s = s.next
endloop
//code stack
call .stackCode.recursiveDestroy()
//unit stacks
call .stackInlet.recursiveDestroy()
call .stackFilter.recursiveDestroy()
call .stackBuffer.recursiveDestroy()
//triggers
call DestroyTrigger(.trigInlet)
call DestroyTrigger(.trigFilter)
call DestroyTrigger(.trigBuffer)
set .trigInlet = null
set .trigFilter = null
set .trigBuffer = null
endmethod
endstruct
///Initializes the library
private function initSUEL takes nothing returns nothing
debug if SHOW_DEBUG_MESSAGES then
debug call BJDebugMsg("Initialized SUEL with SHOW_DEBUG_MESSAGES")
debug endif
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library EasyDamage initializer initDamageSys requires SUEL
globals
private SpreadUnitEvent dmgSpreadEvent = 0
endglobals
function EasyDamage_Register takes code c returns nothing
call dmgSpreadEvent.register(c) ///Add a function to call when units take damage
endfunction
private function addNewUnit takes nothing returns nothing
call dmgSpreadEvent.addUnit(GetTriggerUnit()) //add the new unit to damage event sources
endfunction
private function initDamageSys takes nothing returns nothing
local trigger t = CreateTrigger() //trigger to add units as they are created
call TriggerRegisterEnterRectSimple(t, GetWorldBounds())
call TriggerAddAction(t, function addNewUnit)
set dmgSpreadEvent = SpreadUnitEvent.create(EVENT_UNIT_DAMAGED) //init event spreader
call dmgSpreadEvent.addUnitsMatching(null) //add starting units
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
///Shows red floating text when a unit takes damage
function catchDamage takes nothing returns nothing
local unit u = GetTriggerUnit()
local texttag t = CreateTextTag()
call SetTextTagText(t, "|cFFFF0000" + I2S(R2I(GetEventDamage())) + "|r", 0.023)
call SetTextTagPos(t, GetUnitX(u)+GetRandomReal(-25, 25), GetUnitY(u)+GetRandomReal(-25, 25), 0)
call SetTextTagLifespan(t, 3)
call SetTextTagPermanent(t, false)
call SetTextTagFadepoint(t, 1)
call SetTextTagVelocity(t, 0, 0.023)
set t = null
set u = null
endfunction
//===========================================================================
function InitTrig_Detect_Damage takes nothing returns nothing
call EasyDamage_Register(function catchDamage)
endfunction
function Cond takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction
function Act takes nothing returns nothing
local unit u = GetEnteringUnit()
call RunSkillCodeForUnit (u)
endfunction
//===========================================================================
function InitTrig_Hero_AI takes nothing returns nothing
local trigger HeroAI = CreateTrigger()
call TriggerRegisterEnterRectSimple( HeroAI, GetPlayableMapRect() )
call TriggerAddCondition( HeroAI, Condition( function Cond ) )
call TriggerAddAction( HeroAI, function Act )
endfunction