1. Are you planning to upload your awesome map to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  5. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  6. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  7. The 13th Music Contest Poll is up! Vote for the best tracks in this symphony of frost and flame.
    Dismiss Notice
  8. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Trigger Viewer

Hero Defense AZ v1u.w3x
Variables
Initialization
Initialization
Army Selection
Amy Selection Handler
Mode Selection
Mode Selection Handler
Difficulty Selection
Difficulty Selection Handler
Speed Selection
Speed Selection Handler
Starting Selection
Starting Selection Handler
General
Victory
Loss
Hero Select
Respawn
Gold Reward
Helper
Enemies
Waves
Order
Switch Target
Near
Enemy Cleanup
MAGs
Mag Level Up
Check Level
Feed Trimate
Feed Sol Atomizer
Feed Trifluid
Feed Moon Atomizer
PB Generate
Legends
Awaken
Dragon Stone
Leviathan Razor Armor
Phoenix Wing
Masashi Asuka Kills
Tsumikiri Kills
Archangel Kills
Perfect Rebirth Damage
Perfect Rebirth Raise
Forgotten Jewel Count
Obsidian
Spirit of Corruption Timer
Multiboard
Create
Kill Increment
Commands
Camera
Enable Wayward Purge
No Passwords
Cleanup Enemies
Free Play Next Wave
Secret Hero Command 1
Secret Hero Command 2
Secret Hero Command 4
Secret Hero Command 5
Camera Lock Command
Suicide Command
Clear Hero Area
A
Destroy MAG
Bot Utilities
Spawn
Control
Define
Abilities
Attrition
Backstab
Bear Attack Bonus
Charge
Consume Blight
Conjure Blight
Crimson
Crushing Blade
Death Nova
Demon Boost
Divine Intervention
Earth Nova
Eat Tree
Fel Grapple
Forgotten Power
Full Moon
Ghost Storm
Golem Control
Tornado Nerf
Hatsuendan
Headshot
Howl
Implode
INFINITE POWAH
INFINITE POWAH kill
Kunaidesu
Knockback
Launching Strike
Lightning Burst
Lightning Sword
Mana Burst
Metamorphosis
Meteor
Nightmare Annihilation
Nuclear Strike
One With Shadow
Rage
Revenge
Seal of Life
Seal of Power
Shadow Explode
Sleep
Total Corruption
Tsumikiri
Tribute
Tranquility
Vice
Unforgiveness
Wisp Explosion
Recipes
Special Effect
Chao Essence X
Night Essence X
Secret Essence X
Transform Dark
Transform Light
Upgrade Ring LVL2
Upgrade Ring LVL3
Upgrade Sword LVL2
Upgrade Sword LVL3
Upgrade Boots LVL2
Upgrade Boots LVL3
Upgrade Armor LVL2
Upgrade Armor LVL3
Craft Storm Blade
Craft Earth Blade
Craft Fire Blade
Craft Storm Armor
Craft Earth Armor
Craft Fire Armor
Craft Ring of Agility
Craft Ring of Strength
Craft Ring of Intelligence
Craft Ring of Chaos
Craft Heavenly Blade
Craft Hellish Blade
Craft Heavenly Armor
Craft Hellish Armor
Craft Sealed JSword
Craft Chaos Scythe
Craft Chaos Garment
Craft Chaos Chain
Craft Chaos Crown
Craft Zanglief
Craft Angel Blessing
Craft Gem Blade
Craft Nature Shield
Craft Tesla Frame
Craft Burning Plate
Craft Slayer Axe
Craft Hammer of Thor
Craft Sange Yasha
Craft Secret Boots
Craft Ring of Completion
Craft Ring of Corruption
Craft Divine Body
Craft Death Cloak
Craft Forbidden Jewel
Craft Darkness
Craft Brilliance
Craft Sacrificial Claws
Craft Tome of Eternity
Craft Tome of Midnight
Craft Blade of Midnight
Craft Branch
Craft Striker of Chao
Craft Secret Key
Craft Chao Mag
Craft Night Ess Mag
Minibosses
Self
Dragon
Items
Drops
Combine Charged Items
Drop Similar Items
Events
Conqueror
Genocide
Pack Horse
Botanist
Enter map-specific custom script code below. This text will be included in the map script after variables are declared and before any trigger code.
function NullCondition takes nothing returns boolean
    return true
endfunction

function Already_Picked takes integer id returns boolean
    local integer a = 1
    loop
        exitwhen a > 10
        if (id == GetUnitTypeId(udg_Hero[a])) then
            return true
        endif
        set a = a + 1
    endloop
    return false
endfunction

function Remove_Unit_From_Rect takes integer i, rect r returns nothing
    local group g = GetUnitsInRectMatching(r, Condition(function NullCondition))
    local unit e
    loop
        set e = FirstOfGroup(g)
        exitwhen (GetUnitTypeId(e) == i or CountUnitsInGroup(g) <= 0)
        call GroupRemoveUnit(g, e)
    endloop
    call RemoveUnit(e)
    set e = null
    call DestroyGroup(g)
    set g = null
    set r = null
endfunction

function Create_Random_Hero takes player p, real x, real y returns unit
    local group g = GetUnitsInRectMatching(gg_rct_Hero_Select, Condition(function NullCondition))
    local unit e = FirstOfGroup(g)
    local unit r
    local unitpool u = CreateUnitPool()
    loop
        exitwhen CountUnitsInGroup(g) <= 0
        set e = FirstOfGroup(g)
        if (not Already_Picked(GetUnitTypeId(e))) then
            call UnitPoolAddUnitType(u, GetUnitTypeId(e), 1)
        endif
        call GroupRemoveUnit(g, e)
    endloop
    set r = PlaceRandomUnit(u, p, x, y, 270)
    call Remove_Unit_From_Rect(GetUnitTypeId(r), gg_rct_Hero_Select)
    call DestroyGroup(g)
    set g = null
    call DestroyUnitPool(u)
    set u = null
    return r
endfunction

function CountLivingPlayerUnitsOfTypeId_Fixed takes integer unitId, player whichPlayer returns integer
    local group g
    local integer matchedCount
    set g = CreateGroup()
    set bj_livingPlayerUnitsTypeId = unitId
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterLivingPlayerUnitsOfTypeId)
    set matchedCount = CountUnitsInGroup(g)
    call DestroyGroup(g)
    set g = null
    return matchedCount
endfunction

function MStat takes string s returns integer
    if s == "lvl" then
        return 1
    elseif s == "pow" then
        return 2
    elseif s == "dex" then
        return 3
    elseif s == "mind" then
        return 4
    elseif s == "def" then
        return 5
    elseif s == "pb" then
        return 6
    elseif s == "defcycler" then
        return 7
    else
        return -1
    endif
endfunction

function MLevelUp takes integer id, integer a, integer b, integer c, integer d, unit u returns nothing
    local integer l = LoadInteger(udg_mag, id, MStat("lvl")) + 1
    local unit e
    local integer o = 0
    local integer dc = 0
    local item mag = LoadItemHandle(udg_mag, id, 0)
    local integer defcycler = LoadInteger(udg_mag, id, MStat("defcycler"))
    local integer pow = LoadInteger(udg_mag, id, MStat("pow"))
    local integer dex = LoadInteger(udg_mag, id, MStat("dex"))
    local integer mind = LoadInteger(udg_mag, id, MStat("mind"))
    local integer def = LoadInteger(udg_mag, id, MStat("def"))
    call SaveInteger(udg_mag, id, MStat("lvl"), l)
    call SaveInteger(udg_mag, id, MStat("pow"), LoadInteger(udg_mag, id, MStat("pow")) + a)
    call SaveInteger(udg_mag, id, MStat("dex"), LoadInteger(udg_mag, id, MStat("dex")) + b)
    call SaveInteger(udg_mag, id, MStat("mind"), LoadInteger(udg_mag, id, MStat("mind")) + c)
    call SaveInteger(udg_mag, id, MStat("def"), LoadInteger(udg_mag, id, MStat("def")) + d)
    call SetHeroStr(u, GetHeroStr(u, false) + a, true)
    call SetHeroAgi(u, GetHeroAgi(u, false) + b, true)
    call SetHeroInt(u, GetHeroInt(u, false) + c, true)
    if d > 0 then 
        set defcycler = defcycler + d
        if defcycler >= 3 then
            call SetHeroStr(u, GetHeroStr(u, false) + 1, true)
            call SetHeroAgi(u, GetHeroAgi(u, false) + 1, true)
            call SetHeroInt(u, GetHeroInt(u, false) + 1, true)
            set defcycler = 0
        endif
    endif
    call SaveInteger(udg_mag, id, MStat("defcycler"), defcycler)
    loop
        set e = udg_Hero[o]
        exitwhen o > 9 or UnitHasItem(e, mag)
        set o = o + 1
    endloop
    if l == 10 then
        if pow == 5 and dex == 5 and mind == 5 and def == 10 then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03D')
        else
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03R')
        endif
    elseif l == 35 then
        if pow + dex > mind + def then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03E')
        else
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03Q')
        endif
    elseif l == 50 then
        if pow > dex and pow > mind and pow > def then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03N')
        elseif dex > pow and dex > mind and dex > def then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03F')
        elseif mind > pow and mind > dex and mind > def then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03O')
        elseif def >= pow and def >= dex and def >= mind then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03P')
        endif
    endif
    if GetItemLevel(mag) != 3 then
        if pow == 100 and pow > dex and pow > mind and pow > def then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03J')
        elseif dex == 100 and dex > pow and dex > mind and dex > def then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03L')
        elseif mind == 100 and mind > pow and mind > dex and mind > def then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03K')
        elseif def == 100 and def > pow and def > dex and def > mind then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03M')
        elseif pow == 100 and dex == 100 and mind == 100 and def == 100 then
            call RemoveItem(mag)
            set mag = UnitAddItemById(e, 'I03H')
        endif
    endif
    call SaveItemHandle(udg_mag, id, 0, mag)
    set e = null
    set mag = null
endfunction

function Message takes string m, real d returns nothing
    local player p
    local integer i = 0
    loop
        exitwhen i > 11
        set p = Player(i)
        call DisplayTimedTextToPlayer(p, 0, 0, d, m)
        set i = i + 1
    endloop
    set p = null
endfunction

function Enemy_Check takes nothing returns boolean
    local unit u = GetFilterUnit()
    local player p1 = GetOwningPlayer(u)
    local player p2 = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local player p3 = Player(11)
    local boolean b = ((GetUnitState(u, UNIT_STATE_LIFE) > 0.405) and ((p1 == p2) or (p1 == p3)))
    set u = null
    set p1 = null
    set p2 = null
    set p3 = null
    return b
endfunction

function Enemy_Check_11 takes nothing returns boolean
    local unit u = GetFilterUnit()
    local player p1 = GetOwningPlayer(u)
    local player p2 = Player(11)
    local boolean b = (p1 == p2)
    set u = null
    set p1 = null
    set p2 = null
    return b
endfunction

function Hero_Check takes nothing returns boolean
    local unit u = GetFilterUnit()
    local boolean b = (u == udg_Hero[1] or u == udg_Hero[2] or u == udg_Hero[3] or u == udg_Hero[4] or u == udg_Hero[5] or u == udg_Hero[6] or u == udg_Hero[7] or u == udg_Hero[8] or u == udg_Hero[9] or u == udg_Hero[10])
    set u = null
    return b
endfunction

function Count_Held_Items_Of_Type takes unit u, integer id returns integer
    local integer count = 0
    local integer index = 0
    local item indexItem
    loop
        set indexItem = UnitItemInSlot(u, index)
        if indexItem != null and GetItemTypeId(indexItem) == id then
            set count = count + 1
        endif
        set index = index + 1
        exitwhen index >= 6
    endloop
    set indexItem = null
    return count
endfunction

function Count_Held_Items_Of_Level takes unit u, integer level, integer t returns integer
    local integer count = 0
    local integer index = 0
    local item indexItem
    loop
        set indexItem = UnitItemInSlot(u, index)
        if indexItem != null and GetItemLevel(indexItem) == level and GetItemType(indexItem) == ConvertItemType(t) then
            set count = count + 1
        endif
        set index = index + 1
        exitwhen index >= 6
    endloop
    set indexItem = null
    return count
endfunction

function Count_Players takes nothing returns integer
    local integer count = 0
    local integer i = 0
    local player p
    loop
        exitwhen i > 9
        set p = Player(i)
        if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then
            set count = count + 1
        endif
        set i = i + 1
    endloop
    set p = null
    return count
endfunction

function Count_Humans takes nothing returns integer
    local integer count = 0
    local integer i = 0
    local player p
    loop
        exitwhen i > 9
        set p = Player(i)
        if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
            set count = count + 1
        endif
        set i = i + 1
    endloop
    set p = null
    return count
endfunction

function Spawn_Computer_Heroes takes nothing returns integer
    local location l = GetRectCenter(gg_rct_Target)
    local player q = Player(0)
    local player p 
    local unit u
    local integer i = 0
    local integer r = 0
    loop
        exitwhen i > 9
        set p = Player(i)
        if GetPlayerController(p) == MAP_CONTROL_COMPUTER then
            if (udg_LoadHero[GetPlayerId(p)+1] != null) then 
                if (not Already_Picked(GetUnitTypeId(udg_LoadHero[GetPlayerId(p)+1]))) then
                    set u = CreateUnit(p, GetUnitTypeId(udg_LoadHero[GetPlayerId(p)+1]), GetLocationX(l), GetLocationY(l), 0)
                else
                    call Message("Bot " + I2S(i+1) + " could not be the hero selected with the |cff00ff00-d|r command because someone else chose that hero.", 10)
                    set u = Create_Random_Hero(p, GetLocationX(l), GetLocationY(l))
                endif
            else
                set u = Create_Random_Hero(p, GetLocationX(l), GetLocationY(l))
            endif
            call Remove_Unit_From_Rect(GetUnitTypeId(u), gg_rct_Hero_Select)
            set udg_Hero[i+1] = u
            call SetPlayerAlliance(q, p, ALLIANCE_SHARED_CONTROL, true)
            call SetPlayerAlliance(p, q, ALLIANCE_SHARED_CONTROL, true)
            if GetUnitTypeId(u) == 'N053' then
                call RemoveUnit(u)
                set u = CreateUnit(p, 'N03D', GetLocationX(l), GetLocationY(l), 0)
            endif
            if udg_mode == 4 then
                call SetHeroLevelBJ(u, 100, false)
            endif
            set r = r + 1
        endif
        set i = i + 1
    endloop
    call RemoveLocation(l)
    set l = null
    set p = null
    set q = null
    set u = null
    return r
endfunction

function Set_Computer_Controller takes integer whichplayer returns nothing
    local player q = Player(whichplayer)
    local player p
    local integer i = 0
    local integer r = 0
    loop
        exitwhen i > 9
        set p = Player(i)
        if GetPlayerController(p) == MAP_CONTROL_COMPUTER then
            call SetPlayerAlliance(q, p, ALLIANCE_SHARED_CONTROL, true)
            call SetPlayerAlliance(p, q, ALLIANCE_SHARED_CONTROL, true)
            set r = r + 1
        endif
        set i = i + 1
    endloop
    set p = null
    set q = null
endfunction

function Spawn_Boss takes nothing returns nothing
    local location l = GetRectCenter(gg_rct_WaveSpawn2)
    local location t = GetRectCenter(gg_rct_Target)
    local player p11 = Player(11)
    local unit v
    local force f = GetPlayersAll()
    local integer m = 1
    local integer p = Count_Players() - 1
    if udg_mode == 5 then
        set m = 4
    endif
    if udg_waveCount == 5 then
        set v = CreateUnitAtLoc(p11, udg_Bosses[0], l, 0)
        call SetHeroLevel(v, 49 + p * 7, false)
        call DisplayTextToForce(f, "A boss is coming!")
        call SetUnitMoveSpeed(v, 1.5 * GetUnitMoveSpeed(v) * m)
        call IssuePointOrderLoc(v, "patrol", t)
    elseif udg_waveCount == 10 then
        set v = CreateUnitAtLoc(p11, udg_Bosses[1], l, 0)
        call SetHeroLevel(v, 77 + p * 7, false)
        call DisplayTextToForce(f, "A boss is coming!")
        call SetUnitMoveSpeed(v, 1.5 * GetUnitMoveSpeed(v) * m)
        call IssuePointOrderLoc(v, "patrol", t)
    elseif udg_waveCount == 15 then
        set v = CreateUnitAtLoc(p11, udg_Bosses[2], l, 0)
        call SetHeroLevel(v, 105 + p * 7, false)
        call DisplayTextToForce(f, "A boss is coming!")
        call SetUnitMoveSpeed(v, 1.5 * GetUnitMoveSpeed(v) * m)
        call IssuePointOrderLoc(v, "patrol", t)
    elseif udg_waveCount == 20 then
        set v = CreateUnitAtLoc(p11, udg_Bosses[3], l, 0)
        call SetHeroLevel(v, 133 + p * 7, false)
        call DisplayTextToForce(f, "A boss is coming!")
        call SetUnitMoveSpeed(v, 1.5 * GetUnitMoveSpeed(v) * m)
        call IssuePointOrderLoc(v, "patrol", t)
    elseif udg_waveCount == 25 then
        set udg_FinalBoss = CreateUnitAtLoc(p11, udg_Bosses[4], l, 0)
        call SetHeroLevel(udg_FinalBoss, 200, false)
        call DisplayTextToForce(f, "|cffff0000The final boss is coming!|r")
        call IssuePointOrderLoc(udg_FinalBoss, "patrol", t)
    endif
    call RemoveLocation(l)
    set l = null
    set p11 = null
    set v = null
    call DestroyForce(f)
    set f = null
endfunction

function Spawn_Enemies takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer p = Count_Players() - 1
    local integer a = LoadInteger(udg_h, GetHandleId(t), 'a')
    local integer b = LoadInteger(udg_h, GetHandleId(t), 'b')
    local integer c = 1
    local integer m = 1
    local unit u
    local location array l
    local force f = GetPlayersAll()
    local player p11 = Player(11)
    set l[1] = GetRectCenter(gg_rct_WaveSpawn1)
    set l[2] = GetRectCenter(gg_rct_WaveSpawn2)
    set l[3] = GetRectCenter(gg_rct_WaveSpawn3)
    set l[4] = GetRectCenter(gg_rct_Target)
    if udg_mode == 5 then
        set m = 4
    endif
    if a < b then
        loop
            exitwhen c > 3
            set u = CreateUnitAtLoc(p11, udg_Wave[udg_waveCount], l[c], 0)
            call UnitApplyTimedLifeBJ( 180, 'BTLF', u )
            call SetUnitMoveSpeed(u, 1.5 * GetUnitMoveSpeed(u) * m)
            call IssuePointOrderLoc(u, "patrol", l[4])
            set u = null
            set c = c + 1
        endloop
    else
        call EnableTrigger(gg_trg_Enemy_Cleanup)
        call PauseTimer(t)
        call DestroyTimer(t)
        set udg_waveCount = udg_waveCount + 1
    endif
    call SaveInteger(udg_h, GetHandleId(t), 'a', a + 1)
    set t = null
    set u = null
    call RemoveLocation(l[1])
    call RemoveLocation(l[2])
    call RemoveLocation(l[3])
    call RemoveLocation(l[4])
    set l[1] = null
    set l[2] = null
    set l[3] = null
    set l[4] = null
    set p11 = null
    call DestroyForce(f)
    set f = null
endfunction

function FoShizzle takes nothing returns boolean
    return not Enemy_Check()
endfunction

function MaDrizzle takes nothing returns boolean //fixed thanks to Kobas!!
    call KillUnit(GetEnumUnit())
    return false
endfunction

function Next_Wave takes nothing returns nothing
    local timer t = CreateTimer()
    local integer m = 0
    local group g
    local player p = GetLocalPlayer()
    call DisableTrigger(gg_trg_Enemy_Cleanup)
    if udg_purge == true then
        set g = CreateGroup()
        call GroupEnumUnitsInRect(g, gg_rct_WaveSpawn1, Condition(function MaDrizzle))
        call GroupEnumUnitsInRect(g, gg_rct_WaveSpawn2, Condition(function MaDrizzle))
        call GroupEnumUnitsInRect(g, gg_rct_WaveSpawn3, Condition(function MaDrizzle))
        call ForGroup(g, function FoShizzle)
    endif
    if udg_mode != 2 and udg_mode != 4 then
        call TimerDialogSetTitle(udg_TimerDialog, "Wave " + I2S(udg_waveCount + 1) + " spawns in:")
        if udg_waveCount > 25 then
            call PauseTimer(udg_Timer)
            call DestroyTimer(udg_Timer)
            call DestroyTimerDialog(udg_TimerDialog)
            set udg_Timer = null
            set udg_TimerDialog = null
            return
        endif
    endif
    if udg_mode == 5 then
        set m = -2
    endif
    call PlaySoundBJ( gg_snd_QuestNew )
    call Message("Wave |cff00ff00" + I2S(udg_waveCount) + "|r is coming!", 12)
    if UnitHasItemOfTypeBJ(udg_Hero[GetPlayerId(p)+1], 'I03A') then
        if udg_waveCount < 25 then
            call Message("The current wave is |cffff00ff" + GetObjectName(udg_Wave[udg_waveCount]) + "|r.", 20)
        endif
        if udg_waveCount < 24 then
            call Message("The next wave will be |cffff00ff" + GetObjectName(udg_Wave[udg_waveCount+1]) + "|r.", 20)
        endif
    endif
    call SaveInteger(udg_h, GetHandleId(t), 'a', 0)
    call SaveInteger(udg_h, GetHandleId(t), 'b', 18 + m)
    call Spawn_Boss()
    call TimerStart(t, .75, true, function Spawn_Enemies)
    set p = null
endfunction

function Send_Wave takes integer wave_to_send, boolean return_to_old_wave_count returns nothing
    local integer old_waveCount = udg_waveCount
    set udg_waveCount = wave_to_send
    call Next_Wave()
    if return_to_old_wave_count == true then
        call TriggerSleepAction(10)
        set udg_waveCount = old_waveCount
    endif
endfunction

function SetWaveList takes integer i returns nothing
    local integer a = 1
    local string s
    if i == 1 then
        set udg_Wave[1] = 'o00F'
        set udg_Wave[2] = 'o00M'
        set udg_Wave[3] = 'o00Q'
        set udg_Wave[4] = 'o00Y'
        set udg_Wave[5] = 'o013'
        set udg_Wave[6] = 'o014'
        set udg_Wave[7] = 'o021'
        set udg_Wave[8] = 'o028'
        set udg_Wave[9] = 'o023'
        set udg_Wave[10] = 'o024'
        set udg_Wave[11] = 'o025'
        set udg_Wave[12] = 'o026'
        set udg_Wave[13] = 'o027'
        set udg_Wave[14] = 'o022'
        set udg_Wave[15] = 'o029'
        set udg_Wave[16] = 'o02A'
        set udg_Wave[17] = 'o02B'
        set udg_Wave[18] = 'o02C'
        set udg_Wave[19] = 'o02D'
        set udg_Wave[20] = 'o02E'
        set udg_Wave[21] = 'o02F'
        set udg_Wave[22] = 'o02G'
        set udg_Wave[23] = 'o017'
        set udg_Wave[24] = 'o02H'
        set udg_Wave[25] = 'o02I'
        set udg_Bosses[0] = 'N04S'
        set udg_Bosses[1] = 'N04T'
        set udg_Bosses[2] = 'N04U'
        set udg_Bosses[3] = 'N04V'
        set udg_Bosses[4] = 'N02B'
    elseif i == 2 then
        loop
            set udg_Wave[a] = 'o02I' + a
            exitwhen a == 16
            set a = a + 1
        endloop
        set udg_Wave[17] = 'o02Z'
        set udg_Wave[18] = 'o030'
        set udg_Wave[19] = 'o031'
        set udg_Wave[20] = 'o032'
        set udg_Wave[21] = 'o033'
        set udg_Wave[22] = 'o034'
        set udg_Wave[23] = 'o035'
        set udg_Wave[24] = 'o036'
        set udg_Wave[25] = 'o037'
        set udg_Bosses[0] = 'N00D'
        set udg_Bosses[1] = 'N04O'
        set udg_Bosses[2] = 'N04P'
        set udg_Bosses[3] = 'N04Q'
        set udg_Bosses[4] = 'N04R'
    elseif i == 3 then
        set udg_Wave[1] = 'o038'
        set udg_Wave[2] = 'o039'
        set udg_Wave[3] = 'o03A'
        set udg_Wave[4] = 'o03B'
        set udg_Wave[5] = 'o03C'
        set udg_Wave[6] = 'o03D'
        set udg_Wave[7] = 'o03E'
        set udg_Wave[8] = 'o03F'
        set udg_Wave[9] = 'o03G'
        set udg_Wave[10] = 'o03H'
        set udg_Wave[11] = 'o03I'
        set udg_Wave[12] = 'o03J'
        set udg_Wave[13] = 'o03K'
        set udg_Wave[14] = 'o03L'
        set udg_Wave[15] = 'o03M'
        set udg_Wave[16] = 'o03N'
        set udg_Wave[17] = 'o03O'
        set udg_Wave[18] = 'o03P'
        set udg_Wave[19] = 'o03Q'
        set udg_Wave[20] = 'o03R'
        set udg_Wave[21] = 'o03S'
        set udg_Wave[22] = 'o03T'
        set udg_Wave[23] = 'o03U'
        set udg_Wave[24] = 'o03V'
        set udg_Wave[25] = 'o03W'
        set udg_Bosses[0] = 'N04W'
        set udg_Bosses[1] = 'N04X'
        set udg_Bosses[2] = 'N04Y'
        set udg_Bosses[3] = 'N04Z'
        set udg_Bosses[4] = 'N050'
    elseif i == 4 then
        call SetWaveList(GetRandomInt(0, 3))
        set udg_vpts = udg_vpts + 5
        return
    else
        set udg_Wave[1] = 'o007'
        set udg_Wave[2] = 'o006'
        set udg_Wave[3] = 'o00E'
        set udg_Wave[4] = 'o00G'
        set udg_Wave[5] = 'o00H'
        set udg_Wave[6] = 'o00I'
        set udg_Wave[7] = 'o00J'
        set udg_Wave[8] = 'o00K'
        set udg_Wave[9] = 'o00L'
        set udg_Wave[10] = 'o00N'
        set udg_Wave[11] = 'o00R'
        set udg_Wave[12] = 'o00S'
        set udg_Wave[13] = 'o00T'
        set udg_Wave[14] = 'o00U'
        set udg_Wave[15] = 'o00V'
        set udg_Wave[16] = 'o00W'
        set udg_Wave[17] = 'o00X'
        set udg_Wave[18] = 'o00Z'
        set udg_Wave[19] = 'o031'
        set udg_Wave[20] = 'o011'
        set udg_Wave[21] = 'o033'
        set udg_Wave[22] = 'o016'
        set udg_Wave[23] = 'o017'
        set udg_Wave[24] = 'o018'
        set udg_Wave[25] = 'o019'
        set udg_Bosses[0] = 'N01J'
        set udg_Bosses[1] = 'N01K'
        set udg_Bosses[2] = 'N00H'
        set udg_Bosses[3] = 'N01T'
        set udg_Bosses[4] = 'N02B'
    endif
endfunction

function Check_Chaos takes nothing returns nothing
    local player p = Player(11)
    local rect array where
    local location there
    if udg_Chaos < 0 then
        call NullCondition()
    elseif udg_Chaos >= 10 then
        set where[0] = gg_rct_Region_041
        set where[1] = gg_rct_Region_036
        set where[2] = gg_rct_Region_042
        set where[3] = gg_rct_Region_043
        set where[4] = gg_rct_Region_046
        set there = GetRandomLocInRect(where[GetRandomInt(0, 4)])
        call CreateUnitAtLoc(p, 'n052', there, 270)
        call Message("--- |cff00ff00Event Report|r ---", 10)
        call Message("|cff00ff00Event:|r Chaos Incarnate", 10)
        call Message("A mysterious vendor has appeared somewhere.", 10)
        set udg_Chaos = -1
        set udg_vpts = udg_vpts + 5
        set where[0] = null
        set where[1] = null
        set where[2] = null
        set where[3] = null
        set where[4] = null
        set there = null
    endif
    call RemoveLocation(there)
    set there = null
    set p = null
endfunction
Name Type Is Array Initial Value
ac integer No
army integer No
armybutton button Yes
ArmySelect dialog No
asleep group No
Bosses unitcode Yes
botspawn integer No
CameraLocked boolean Yes
Chaos integer No
crpt hashtable No
Defenders force No
dif integer No
difbutton button Yes
DifSelect dialog No
FinalBoss unit No
flagbonus integer No 1
h hashtable No
helper boolean No true
Hero unit Yes UnitNull
insanity boolean No
insanityButton button No
kills integer Yes
LastCaveUnit unit No
LoadHero unit Yes
mag hashtable No
mgscale real No 0.50
mode integer No
modebutton button Yes
ModeSelect dialog No
multiboard multiboard No
PickedHero boolean Yes
playerorder integer Yes
prevbonus integer No
purge boolean No
rc integer Yes
singleplayerbutton button No
speed integer No
speedbutton button Yes
SpeedSelect dialog No
startingbutton button Yes
startingcondition integer No
StartingSelect dialog No
Timer timer No
TimerDialog timerdialog No
tips hashtable No
ven integer No
vpts integer No
Wave unitcode Yes
waveCount integer No 1
function SetHeroTips takes hashtable h returns nothing
    call SaveStr(h, 'U00C', 0, "All-Around\nAdept at healing, damaging, & tanking.")
    call SaveStr(h, 'N03V', 0, "Warrior\nAdept at killing foes and powering up.")
    call SaveStr(h, 'U004', 0, "Warrior\nAdept at killing foes and powering up.")
    call SaveStr(h, 'E007', 0, "Warrior\nA mysterious warrior adept at maneuvering in battle and dispatching bosses.")
    call SaveStr(h, 'O00O', 0, "Summoner\nCapable of holding back armies by summoning armies of his own. Good at holding back enemies, but slow to kill them.")
    call SaveStr(h, 'N00R', 0, "Ranger\n") //elite dark ranger
    call SaveStr(h, 'N00I', 0, "Support\nSpecializes in mana restoration rather than healing.")
    call SaveStr(h, 'N00V', 0, "Warrior\nUses gravitational magic to push and pull enemies.")
    call SaveStr(h, 'N053', 0, "Mage\nAdept at killing groups of foes.")
    call SaveStr(h, 'N03D', 0, "Mage\nAdept at killing groups of foes.")
    call SaveStr(h, 'N000', 0, "Ranger\nA ranger known for being able to hold her own in combat.")
    call SaveStr(h, 'N009', 0, "Tank\nThe keeper of the gates of hell. Legends say he can hold off entire armies.")
    call SaveStr(h, 'U000', 0, "Mage\nUses a summon to shield himself while he wields the power of the Earth to destroy enemies.")
    call SaveStr(h, 'U007', 0, "Mage\nAdept at avoiding damage and destroying groups of foes.")
    call SaveStr(h, 'U00D', 0, "Support\nAdept at both fighting and healing.")
    call SaveStr(h, 'H000', 0, "Warrior\nUses lightning to kill enemies as well as ehance himself.")
    call SaveStr(h, 'H006', 0, "Ranger\nA gunman who can fight from incredible distances, but also has extremely low HP.")
    call SaveStr(h, 'N01I', 0, "Unique\nMust consume the agony of living beings to sustain himself outside the dream world.") //nightmare
    call SaveStr(h, 'H008', 0, "Warrior\nTakes on groups of enemies by freezing them.")
    call SaveStr(h, 'H002', 0, "Warrior\nAdept at killing foes and powering up.")
    call SaveStr(h, 'N01Y', 0, "Warrior\n") //panderen battlemaster
    call SaveStr(h, 'N002', 0, "Mage\nA mechanically-ehanced goblin with no attack... in his current form.")
    call SaveStr(h, 'U001', 0, "Summoner\nSummons legions of insects to overwhelm foes.")
    call SaveStr(h, 'O00D', 0, "Warrior\n") //queen of ages
    call SaveStr(h, 'H004', 0, "Ranger\nAdept at weakening and killing groups of foes.")
    call SaveStr(h, 'O005', 0, "Warrior\nUses fire magic to destroy groups of foes.")
    call SaveStr(h, 'O003', 0, "Tank\nKnown to call upon his ancestors to aid him in battle.")
    call SaveStr(h, 'N016', 0, "Unique\nFights by disabling foes.") //temptress
    call SaveStr(h, 'H001', 0, "Mage, Summoner\nAdept at killing groups of foes as well as summoning minions.")
    call SaveStr(h, 'H003', 0, "Mage\nAdept at using storm magic to disable and kill groups of foes.")
    call SaveStr(h, 'E000', 0, "Warrior\nExceptional at enhancing itself; fights better at night.")
    call SaveStr(h, 'E00V', 0, "Unique\nFights by infecting enemies with a powerful disease.")
    call SaveStr(h, 'E006', 0, "Ranger\nAdept at taking out enemies in certain formations as well as eluding combat.")
    call SaveStr(h, 'E005', 0, "Mage\nUses summoned wisps to enhance offensive and support spells.")
    call SaveStr(h, 'U00R', 0, "Tank\nMakes use of trees as weapons and food. Extremely good at tanking.")
    call SaveStr(h, 'E00S', 0, "Ranger\n") //enchantress
    call SaveStr(h, 'E008', 0, "Summoner\nCalls upon trees to fight foes and to support allies.")
    call SaveStr(h, 'E00A', 0, "Ranger\n") //troll
    call SaveStr(h, 'E00O', 0, "Unique\nCapable of damaging single foes & groups of foes; spells become stronger after taking more damage.")
    call SaveStr(h, 'U00Q', 0, "Tank\nAdept and enduring great amounts of damage and holding off groups of foes.")
    call SaveStr(h, 'U00E', 0, "Summoner\nUses corpses to bring about the will of the Lich King.")
    call SaveStr(h, 'O01Z', 0, "Support, Summoner\nUses summons which support allies and take hits.")
    call SaveStr(h, 'U00A', 0, "Warrior\nSustains himself by damaging foes.")
    call SaveStr(h, 'H024', 0, "Unique\nSpreads the zombie virus to summon more zombies.")
    call SaveStr(h, 'O00A', 0, "Warrior\nA stealthy warrior who specializes in assinating enemies.") //assassin
    call SaveStr(h, 'O01A', 0, "Warrior\nA swift warrior who lives for the thrill of the battle.") //centaur
    call SaveStr(h, 'O00B', 0, "Warrior\nA cunning warrior who specializes in poison attacks.")
    call SaveStr(h, 'O008', 0, "Warrior\n") //draenei
    call SaveStr(h, 'O01F', 0, "Mage\n") //shadow caster
    call SaveStr(h, 'O01D', 0, "Warrior\nShe is unmatched in swordsmanship.")
    call SaveStr(h, 'O01B', 0, "Mage, Support\nAdept at supporting allies as well as fighting.")
    call SaveStr(h, 'H023', 0, "Warrior\nEliminates all who oppose him.")
    call SaveStr(h, 'H00V', 0, "Summoner\nUses his ingenious inventions to defeat his enemies.") //engineer
    call SaveStr(h, 'H00U', 0, "Mage\nAdept at damaging groups of foes.")
    call SaveStr(h, 'H01G', 0, "Tank, Warrior\nAdept at fighting against large groups of enemies.")
    call SaveStr(h, 'H015', 0, "Support\nAdept at healing allies, but can also use his heavenly powers to destroy the wicked.")
    call SaveStr(h, 'H00N', 0, "Warrior\n") //admiral
    call SaveStr(h, 'H00J', 0, "Mage\n") //alexis luna
    call SaveStr(h, 'H00C', 0, "Summoner\nFights exclusively with summons.")
    call SaveStr(h, 'H00B', 0, "Mage\nAdept at damaging groups of foes.")
    call SaveStr(h, 'H00Q', 0, "Mage\n") //sea witch
    call SaveStr(h, 'H025', 0, "Warrior\nHis mind is his greatest weapon.")
    call SaveStr(h, 'H026', 0, "Summoner\nFights by summoning hellish creatures.") //summoner
    call SaveStr(h, 'O020', 0, "Warrior\nA swift warrior of the night who is adept at impairing enemies and maneuvering in combat.")
    call SaveStr(h, 'U00V', 0, "Tank\nA powerful creature empowered by blight.")
endfunction

function RemoveHide takes nothing returns nothing
    local group g = CreateGroup()
    local unit u
    local integer i = 1
    call GroupEnumUnitsInRect(g, gg_rct_Hero_Select, Condition(function NullCondition))
    loop
        exitwhen i > 60
        set u = FirstOfGroup(g)
        if GetUnitAbilityLevel(u, 'Ashm') > 0 then
            call UnitRemoveAbility(u, 'Ashm')
        endif
        if GetUnitAbilityLevel(u, 'Sshm') > 0 then
            call UnitRemoveAbility(u, 'Sshm')
        endif
        call GroupRemoveUnit(g, u)
        set u = null
        set i = i + 1
    endloop
    call DestroyGroup(g)
    set g = null
    set u = null
endfunction

function Trig_Initialization_Actions takes nothing returns nothing
    local player p
    local player p2
    local integer a
    local location l
    local force f = GetPlayersAll()
    local timerdialog td
    call SetTimeOfDay(6)
    set udg_h = InitHashtable()    //used for generic operations and trigger-enhanced abilities
    set udg_mag = InitHashtable()  //used for mag stats only
    set udg_tips = InitHashtable() //used for hero selection tips only
    set udg_crpt = InitHashtable() //used for spirit of corruption only
    call SetHeroTips(udg_tips)
    call SetWaveList(udg_army)
    set udg_asleep = CreateGroup()
    call SaveBoolean(udg_h, 'w', 0, true)
    set l = GetRectCenter(gg_rct_Created_by_Teh_Crisis_and_Lord_Alastor)
    call CreateTextTagLocBJ("TRIGSTR_7933", l, 0, 10, 100, 100, 100, 0)
    set l = null
    call SetCreepCampFilterState(false)
    set p = Player(10)
    set p2 = Player(0)
    call SetPlayerTaxRateBJ( 100, PLAYER_STATE_RESOURCE_GOLD, p, p2 )
    set p = null
    set p2 = null
    call RemoveHide()
//  Commands: a, b, c, d, e, _, _, _, _, _, k, l, _, _, _, p, _, _, s, _, _, _, w, _, _, z; 42.3%
    call CreateQuestBJ(bj_QUESTTYPE_REQ_DISCOVERED, "Commands", "|cff00ff00-z|r Zooms out|n|cff00ff00-l|r Toggles camera lock to your hero|n|cff00ff00-k|r Kills your hero; hero respawns instantly with low health & no mana|n|cff00ff00-a|r Kills all units in the hero selection area (|cffff0000Player 1 only|r)|n|cff00ff00-w|r Calls the next wave (|cff00ff00Free Play|r and |cffff00ffLegendary|r only)|n|cff00ff00-c|r Cleans up straggling enemies by ordering them to attack the castle|n|cff00ff00-e|r Enables/disables wayward enemy purging, which kills enemies that have wandered back to the gates for some reason|n|cff00ff00-b|r Gives the calling player control of bots|n|cff00ff00-s|r Changes the spawn point of all bots|n|cff00ff00-d|r |cff33ff33X N|r Defines which hero the bot in player slot X will choose, where N is the name of the hero's class|n|cff00ff00-p|r Toggle password lock (unlocked by default), which prevents players from using password heroes", "ReplaceableTextures\\CommandButtons\\BTNEngineeringUpgrade.blp")
    call CreateQuestBJ( bj_QUESTTYPE_REQ_DISCOVERED, "Credits", "|cff00ffffHeroes|r Lord Alastor & Teh Crisis|n|cff00ffffAbilities|r Lord Alastor & Teh Crisis|n|cff00ffffEnemies|r Teh Crisis|n|cff00ffffTerrain|r Teh Crisis|n|cff00ffffItems|r Teh Crisis & Lord Alastor|n|cff00ffffTriggers|r Teh Crisis|n|cff00ffffCustom Resources|r Sellenisko, expresso, sPy, Cavman and Mr Goblin, CRAZYRUSSIAN, Tranquil, Suselishe, Trarrasque, WILLTHEALMIGHTY, zeshuri, dickxunder, HappyTauren, Lordan12, Ampharos_222, Fel Orc Crossbowman, Misha, Mainy, Dionesisst, Elenai, Dan van Ohllus, soulreaver6, jetfanginferno, Suselishe", "ReplaceableTextures\\CommandButtons\\BTNGem.blp" )
    call CreateQuestBJ(bj_QUESTTYPE_OPT_DISCOVERED, "MAGs", "MAGs are mechanical companions that boost their owner's stats when fed. They also accumulate Photon Blast (PB) energy; after the MAG has stored 100 PB it will use a powerful ability called a Photon Blast. These abilities can heal the owner, kill enemies, and more!\n\nA MAG will level up automatically when its master levels up and whenever the MAG is fed. A MAGs highest stat determines its Photon Blast as well as whether or not it qualifies for some evolutionary paths.\n\nTo destroy your MAG, use the \"|cff00ff00-destroymag|r\" command. |cffff0000There is no way to aquire a second MAG.|r", "ReplaceableTextures\\CommandButtons\\BTNEngineeringUpgrade.blp")
    call Message("\nThis map was created by |cff00ffffTeh Crisis|r and |cff00ffffLord Alastor|r.\n", 30)
    set p = Player(11)
    call SetPlayerFlagBJ(PLAYER_STATE_GIVES_BOUNTY, true, p)
    set p = null
    set a = 1
    loop
        exitwhen a > 10
        set p = ConvertedPlayer(a)
        call SetPlayerHandicap(p, 1)
        if udg_startingcondition == 1 then
            call SetPlayerStateBJ(p, PLAYER_STATE_RESOURCE_GOLD, 1700)
        else
            call SetPlayerStateBJ(p, PLAYER_STATE_RESOURCE_GOLD, 300)
            if udg_startingcondition == 4 then
                call SetPlayerStateBJ(p, PLAYER_STATE_RESOURCE_LUMBER, 7)
            endif
        endif
        if GetPlayerController(p) == MAP_CONTROL_USER or GetPlayerController(p) == MAP_CONTROL_COMPUTER then
            call ForceAddPlayerSimple(p, udg_Defenders)
        endif
        call SetCameraFieldForPlayer(p, CAMERA_FIELD_TARGET_DISTANCE, 2600, 2)
        set a = a + 1
    endloop
    call TriggerSleepAction(1)
    set l = GetRectCenter(gg_rct_Base)
    set a = 1
    loop
        exitwhen a > 10
        set p = ConvertedPlayer(a)
        call CreateFogModifierRadiusLocBJ(true, p, FOG_OF_WAR_VISIBLE, l, 2400)
        call CreateFogModifierRectBJ(true, p, FOG_OF_WAR_VISIBLE, gg_rct_Hero_Select)
        call CreateFogModifierRectBJ(true, p, FOG_OF_WAR_VISIBLE, gg_rct_SecretHero3)
        call RemoveLocation(l)
        set p = null
        set a = a + 1
    endloop
    set p = Player(11)
    call CreateFogModifierRadiusLocBJ(true, p, FOG_OF_WAR_VISIBLE, l, 1000)
    set p = null
    call CreateTimerDialogBJ( udg_Timer, "Wave 1 spawns in:" )
    call StartTimerBJ( udg_Timer, false, 90 )
    if udg_mode == 7 then
        call Message("\nIn this mode, you can capture |cff00ffffflags|r to increase gold income, reduce respawn time, and more!\n", 40)
    endif
    if udg_mode != 2 and udg_mode != 4 then
        call TriggerSleepAction( 90 )
    else
        call Message("\nAny player can use the |cff00ff00-w|r command to send the next wave. This command has a 15 second cooldown.\n", 40)
    endif
    set td = GetLastCreatedTimerDialogBJ()
    call DestroyTimerDialogBJ(td)
    set p = null
    set p2 = null
    call RemoveLocation(l)
    set l = null
    set p = null
    call DestroyForce(f)
    set f = null
    set td = null
    call Message("\nSpawned |cffff0000" + I2S(Spawn_Computer_Heroes()) + "|r computer-controlled heroes.\n", 10)
    call TriggerExecute(gg_trg_Waves)
    call DestroyTrigger(gg_trg_Initialization)
endfunction

//===========================================================================
function InitTrig_Initialization takes nothing returns nothing
    set gg_trg_Initialization = CreateTrigger(  )
    //call TriggerRegisterDialogEventBJ( gg_trg_Initialization, udg_StartingSelect )
    call TriggerAddAction( gg_trg_Initialization, function Trig_Initialization_Actions )
endfunction


 
function Trig_Army_Selection_Actions takes nothing returns nothing
    local player p = Player(0)
    call FogEnableOn()
    call Message("(1/5) |cffff0000" + GetPlayerName(p) + "|r is choosing the invader's army.", 5)
    call DialogSetMessageBJ(udg_ArmySelect, "Invading Army")
    set udg_armybutton[1] = DialogAddButtonBJ(udg_ArmySelect, "|cffffffffNormal|r")
    set udg_armybutton[2] = DialogAddButtonBJ(udg_ArmySelect, "|cffff00ffScourge|r")
    set udg_armybutton[3] = DialogAddButtonBJ(udg_ArmySelect, "|cffff9900Bandits|r")
    set udg_armybutton[4] = DialogAddButtonBJ(udg_ArmySelect, "|cff00ff00Ancients|r")
    set udg_armybutton[5] = DialogAddButtonBJ(udg_ArmySelect, "|cff999999Random|r")
    call DialogDisplayBJ(true, udg_ArmySelect, p)
    call DestroyTrigger(gg_trg_Army_Selection)
    set p = null
endfunction

//===========================================================================
function InitTrig_Army_Selection takes nothing returns nothing
    set gg_trg_Army_Selection = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Army_Selection, 1 )
    call TriggerAddAction( gg_trg_Army_Selection, function Trig_Army_Selection_Actions )
endfunction
function Trig_Army_Selection_Handler_Actions takes nothing returns nothing
    local button b = GetClickedButton()
    local integer a = 1
    set udg_army = 0
    loop
        exitwhen udg_armybutton[a] == null
        if (b == udg_armybutton[a]) then
            set udg_army = a-1
        endif
        set a = a + 1
    endloop
    set b = null
    call DestroyTrigger(gg_trg_Amy_Selection_Handler)
endfunction

//===========================================================================
function InitTrig_Amy_Selection_Handler takes nothing returns nothing
    set gg_trg_Amy_Selection_Handler = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Amy_Selection_Handler, udg_ArmySelect )
    call TriggerAddAction( gg_trg_Amy_Selection_Handler, function Trig_Army_Selection_Handler_Actions )
endfunction




 
function Trig_Mode_Selection_Actions takes nothing returns nothing
    call FogEnableOn()
    call TriggerSleepAction(1)
    call Message("(2/5) |cffff0000" + GetPlayerName(Player(0)) + "|r is choosing the game mode.", 5)
    call DialogSetMessageBJ(udg_ModeSelect, "Game Mode")
    set udg_modebutton[1] = DialogAddButtonBJ(udg_ModeSelect, "|cffffffffNormal|r")
    set udg_modebutton[2] = DialogAddButtonBJ(udg_ModeSelect, "|cff00ff00Free Play|r")
    set udg_modebutton[3] = DialogAddButtonBJ(udg_ModeSelect, "|cffff9900Challenge|r")
    set udg_modebutton[4] = DialogAddButtonBJ(udg_ModeSelect, "|cffff00ffLegendary|r")
    set udg_modebutton[5] = DialogAddButtonBJ(udg_ModeSelect, "|cff00ffffRush|r")
    set udg_modebutton[6] = DialogAddButtonBJ(udg_ModeSelect, "|cffffff00Territory|r |cff999999(new)|r")
    call DialogDisplayBJ(true, udg_ModeSelect, Player(0))
    call DestroyTrigger(gg_trg_Mode_Selection)
endfunction

//===========================================================================
function InitTrig_Mode_Selection takes nothing returns nothing
    set gg_trg_Mode_Selection = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Mode_Selection, udg_ArmySelect )
    call TriggerAddAction( gg_trg_Mode_Selection, function Trig_Mode_Selection_Actions )
endfunction
function Trig_Mode_Selection_Handler_Actions takes nothing returns nothing
    local button b = GetClickedButton()
    if ( b == udg_modebutton[1] ) then     //normal
        set udg_mode = 1
    elseif ( b == udg_modebutton[2] ) then //free play
        set udg_mode = 2
        set udg_vpts = udg_vpts - 25
    elseif ( b == udg_modebutton[3] ) then //challenge
        set udg_mode = 3
        set udg_vpts = udg_vpts + 25
    elseif ( b == udg_modebutton[4] ) then //legendary
        set udg_mode = 4
    elseif ( b == udg_modebutton[5] ) then //rush
        set udg_mode = 5
    elseif ( b == udg_modebutton[6] ) then //territory
        set udg_mode = 7 //keep as 7 to avoid clashes with old Relentless mode
    endif
    if udg_mode != 7 then
        call RemoveUnit(gg_unit_h01H_0124)
        call RemoveUnit(gg_unit_h01H_0125)
        call RemoveUnit(gg_unit_h01H_0127)
        call RemoveUnit(gg_unit_h01H_0128)
        call RemoveUnit(gg_unit_h01H_0129)
        call RemoveUnit(gg_unit_h01H_0130)
        call RemoveUnit(gg_unit_h01H_0131)
        call RemoveUnit(gg_unit_h01H_0132)
        call RemoveUnit(gg_unit_h01H_0133)
        call DestroyTrigger(gg_trg_Conqueror)
    endif
    set udg_speed = 0
    set b = null
    call DestroyTrigger( gg_trg_Mode_Selection_Handler )
endfunction

//===========================================================================
function InitTrig_Mode_Selection_Handler takes nothing returns nothing
    set gg_trg_Mode_Selection_Handler = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Mode_Selection_Handler, udg_ModeSelect )
    call TriggerAddAction( gg_trg_Mode_Selection_Handler, function Trig_Mode_Selection_Handler_Actions )
endfunction




 
function Trig_Difficulty_Selection_Actions takes nothing returns nothing
    call TriggerSleepAction(1)
    call Message("(3/5) |cffff0000" + GetPlayerName(Player(0)) + "|r is choosing the difficulty.", 5)
    call DialogSetMessageBJ( udg_DifSelect, "Difficulty" )
    if Count_Players() == 1 then
        set udg_singleplayerbutton = DialogAddButtonBJ(udg_DifSelect, "|cffff00ffNerfed|r")
    endif
    set udg_difbutton[1] = DialogAddButtonBJ(udg_DifSelect, "|cffffffffNormal|r")
    set udg_difbutton[2] = DialogAddButtonBJ(udg_DifSelect, "|cffffff00Hard|r")
    set udg_difbutton[3] = DialogAddButtonBJ(udg_DifSelect, "|cffff9900Very Hard|r")
    set udg_insanityButton = DialogAddButtonBJ(udg_DifSelect, "|cffff0000Ultimate|r")
    call DialogDisplayBJ(true, udg_DifSelect, Player(0))
    call DestroyTrigger(gg_trg_Difficulty_Selection)
endfunction

//===========================================================================
function InitTrig_Difficulty_Selection takes nothing returns nothing
    set gg_trg_Difficulty_Selection = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Difficulty_Selection, udg_ModeSelect )
    call TriggerAddAction( gg_trg_Difficulty_Selection, function Trig_Difficulty_Selection_Actions )
endfunction
function Trig_Difficulty_Selection_Handler_Actions takes nothing returns nothing
    local integer p = Count_Players()
    local real m = 0
    local player p11 = Player(11)
    local player pna = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local button b = GetClickedButton()
    if udg_mode == 4 then
        set m = 15
    elseif udg_mode == 5 and b != udg_singleplayerbutton then
        set m = -0.8
    elseif udg_mode == 5 then
        set m = -0.35
    elseif udg_mode == 7 then
        set m = -0.1
    endif
    if ( b == udg_singleplayerbutton ) then
        set udg_dif = 1
        call SetPlayerHandicap( p11, 0.4 + m )
        call SetPlayerHandicap( pna, 0.4 + m )
    elseif ( b == udg_difbutton[1] ) then
        set udg_dif = 1
        call SetPlayerHandicap( p11, 0.8 + 0.1 * p + m )
        call SetPlayerHandicap( pna, 0.8 + 0.15 * p + m )
        set udg_vpts = udg_vpts - 8
    elseif ( b == udg_difbutton[2] ) then
        set udg_dif = 2
        call SetPlayerHandicap( p11, 0.8 + 0.2 * p + m )
        call SetPlayerHandicap( pna, 0.8 + 0.25 * p + m )
        set udg_vpts = udg_vpts
    elseif ( b == udg_difbutton[3] ) then
        set udg_dif = 3
        call SetPlayerHandicap( p11, 0.8 + 0.3 * p + m )
        call SetPlayerHandicap( pna, 0.8 + 0.35 * p + m )
        set udg_vpts = udg_vpts + 4
    elseif ( b == udg_insanityButton ) then
        set udg_dif = 3
        set udg_insanity = true
        call SetPlayerHandicap( p11, 9 + m )
        call SetPlayerHandicap( pna, 9 + m )
        set udg_vpts = udg_vpts + 8
    endif
    set p11 = null
    set pna = null
    set b = null
    call DestroyTrigger( gg_trg_Difficulty_Selection_Handler )
endfunction

//===========================================================================
function InitTrig_Difficulty_Selection_Handler takes nothing returns nothing
    set gg_trg_Difficulty_Selection_Handler = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Difficulty_Selection_Handler, udg_DifSelect )
    call TriggerAddAction( gg_trg_Difficulty_Selection_Handler, function Trig_Difficulty_Selection_Handler_Actions )
endfunction



 
function Trig_Speed_Selection_Actions takes nothing returns nothing
    local player p = Player(0)
    if udg_mode == 2 or udg_mode == 4 or udg_mode == 5 or udg_mode == 7 then
        set udg_speed = 120
        if udg_mode == 5 then
            set udg_speed = 30
        endif
        if udg_mode == 7 then
            set udg_speed = 90
        endif
        call Message("(4/5) This step was skipped, because it is unnecesary due to other option choices.", 5)
        call TriggerExecute( gg_trg_Starting_Selection )
        return
    endif
    call TriggerSleepAction(1)
    call Message("(4/5) |cffff0000" + GetPlayerName(p) + "|r is choosing the time between waves.", 5)
    call DialogSetMessageBJ( udg_SpeedSelect, "Wave Frequency" )
    set udg_speedbutton[1] = DialogAddButtonBJ(udg_SpeedSelect, "|cff00ff00Boring|r")
    set udg_speedbutton[2] = DialogAddButtonBJ(udg_SpeedSelect, "|cff99ff00Slow|r")
    set udg_speedbutton[3] = DialogAddButtonBJ(udg_SpeedSelect, "|cffffffffNormal|r")
    set udg_speedbutton[4] = DialogAddButtonBJ(udg_SpeedSelect, "|cffff9900Fast|r")
    set udg_speedbutton[5] = DialogAddButtonBJ(udg_SpeedSelect, "|cffff0000Mach 5|r")
    call DialogDisplayBJ( true, udg_SpeedSelect, p )
    set p = null
    call DestroyTrigger( gg_trg_Speed_Selection )
endfunction

//===========================================================================
function InitTrig_Speed_Selection takes nothing returns nothing
    set gg_trg_Speed_Selection = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Speed_Selection, udg_DifSelect )
    call TriggerAddAction( gg_trg_Speed_Selection, function Trig_Speed_Selection_Actions )
endfunction

 
function Trig_Speed_Selection_Handler_Actions takes nothing returns nothing
    local button b = GetClickedButton()
    if ( b == udg_speedbutton[1] ) then
        set udg_speed = 150
        set udg_vpts = udg_vpts - 16
    elseif ( b == udg_speedbutton[2] ) then
        set udg_speed = 135
        set udg_vpts = udg_vpts - 8
    elseif ( b == udg_speedbutton[3] ) then
        set udg_speed = 120
    elseif ( b == udg_speedbutton[4] ) then
        set udg_speed = 105
        set udg_vpts = udg_vpts + 4
    elseif ( b == udg_speedbutton[5] ) then
        set udg_speed = 90
        set udg_vpts = udg_vpts + 8
    endif
    set b = null
    call DestroyTrigger( gg_trg_Speed_Selection_Handler )
endfunction

//===========================================================================
function InitTrig_Speed_Selection_Handler takes nothing returns nothing
    set gg_trg_Speed_Selection_Handler = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Speed_Selection_Handler, udg_SpeedSelect )
    call TriggerAddAction( gg_trg_Speed_Selection_Handler, function Trig_Speed_Selection_Handler_Actions )
endfunction
 
function Trig_Starting_Selection_Actions takes nothing returns nothing
    local player p = Player(0)
    call TriggerSleepAction(1)
    call Message("(5/5) |cffff0000" + GetPlayerName(Player(0)) + "|r is choosing the starting conditions.", 5)
    call DialogSetMessageBJ( udg_StartingSelect, "Starting Condition" )
    set udg_startingbutton[1] = DialogAddButtonBJ( udg_StartingSelect, "|cffffff00+1400 Gold|r" )
    set udg_startingbutton[4] = DialogAddButtonBJ( udg_StartingSelect, "|cff00ffff+7 Arcane Seals|r" )
    if udg_mode != 4 then
        set udg_startingbutton[3] = DialogAddButtonBJ( udg_StartingSelect, "|cffff00ff+5 Levels|r" )
    endif
    if udg_mode == 5 then
        set udg_startingbutton[2] = DialogAddButtonBJ( udg_StartingSelect, "|cff00ff00Messenger Bird|r (recommended)" )
    else
        set udg_startingbutton[2] = DialogAddButtonBJ( udg_StartingSelect, "|cff00ff00Messenger Bird|r" )
    endif
    call DialogDisplayBJ( true, udg_StartingSelect, p )
    set p = null
    call DestroyTrigger( gg_trg_Starting_Selection )
endfunction

//===========================================================================
function InitTrig_Starting_Selection takes nothing returns nothing
    set gg_trg_Starting_Selection = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Starting_Selection, udg_SpeedSelect )
    call TriggerAddAction( gg_trg_Starting_Selection, function Trig_Starting_Selection_Actions )
endfunction

 
function Trig_Starting_Selection_Handler_Actions takes nothing returns nothing
    local button b = GetClickedButton()
    call EnableTrigger( gg_trg_Hero_Select )
    if ( b == udg_startingbutton[1] ) then
        set udg_startingcondition = 1
    elseif ( b == udg_startingbutton[2] ) then
        set udg_startingcondition = 2
    elseif ( b == udg_startingbutton[3] ) then
        set udg_startingcondition = 3
    elseif ( b == udg_startingbutton[4] ) then
        set udg_startingcondition = 4
    endif
    set b = null
    call TriggerExecute( gg_trg_Initialization)
    call DestroyTrigger( gg_trg_Starting_Selection_Handler )
endfunction

//===========================================================================
function InitTrig_Starting_Selection_Handler takes nothing returns nothing
    set gg_trg_Starting_Selection_Handler = CreateTrigger(  )
    call TriggerRegisterDialogEventBJ( gg_trg_Starting_Selection_Handler, udg_StartingSelect )
    call TriggerAddAction( gg_trg_Starting_Selection_Handler, function Trig_Starting_Selection_Handler_Actions )
endfunction
 
function Trig_Victory_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local boolean b = (u == udg_FinalBoss)
    set u = null
    return b
endfunction

function Trig_Victory_Victory takes nothing returns nothing
    local player p = GetEnumPlayer()
    call CustomVictoryBJ( p, true, true )
    set p = null
endfunction

function Trig_Victory_Actions takes nothing returns nothing
    local player p = Player(0)
    local integer humans = Count_Humans()
    local integer allplayers = Count_Players()
    call Message("TRIGSTR_5977", 10)
    call TriggerSleepAction(5)
    call PlaySoundBJ(gg_snd_58271D)
    set udg_vpts = udg_vpts + udg_flagbonus - allplayers
    if udg_mode == 1 and humans > 1 and udg_dif > 1 and udg_speed <= 120 and GetUnitLifePercent(gg_unit_h009_0083) >= 99 then
        call Message("|cff00ff00You have unlocked a new password!|r", 15)
        call Message("|cff00ff00You can use it before you select your hero.|r", 15)
        call Message("|cff00ff00Passwords are not case-sensitive.|r", 15)
        call Message("|cff00ff00The password is:|r Divine Wrath", 15)
        call Message("Victory is awarded in 15 seconds.", 15)
        call TriggerSleepAction(10)
    elseif udg_mode == 5 and humans > 1 and udg_dif > 1 and udg_speed <= 120 and GetUnitLifePercent(gg_unit_h009_0083) >= 99 then
        call Message("|cff00ff00You have unlocked a new password!|r", 15)
        call Message("|cff00ff00You can use it before you select your hero.|r", 15)
        call Message("|cff00ff00Passwords are not case-sensitive.|r", 15)
        call Message("|cff00ff00The password is:|r The Grave Beckons", 15)
        call Message("Victory is awarded in 15 seconds.", 15)
        call TriggerSleepAction(10)
    elseif ((udg_mode == 3 and udg_speed <= 120) or (udg_mode == 7 and allplayers < 4 and udg_flagbonus > 9)) and humans > 1 then
        call Message("|cff00ff00You have unlocked a new password!|r", 15)
        call Message("|cff00ff00You can use it before you select your hero.|r", 15)
        call Message("|cff00ff00Passwords are not case-sensitive.|r", 15)
        call Message("|cff00ff00The password is:|r Age of Tranquility", 15)
        call Message("Victory is awarded in 15 seconds.", 15)
        call TriggerSleepAction(10)
    elseif udg_vpts > 99 and humans > 1 then
        call Message("|cff00ff00You have unlocked a new password!|r", 15)
        call Message("|cff00ff00You can use it before you select your hero.|r", 15)
        call Message("|cff00ff00Passwords are not case-sensitive.|r", 15)
        call Message("|cff00ff00The password is:|r Call of the Void", 15)
        call Message("Victory is awarded in 15 seconds.", 15)
        call TriggerSleepAction(10)
    else
        call Message("Victory is awarded in 5 seconds.", 5)
    endif
    call TriggerSleepAction(5)
    set p = null
    call ForForce(udg_Defenders, function Trig_Victory_Victory)
endfunction

//===========================================================================
function InitTrig_Victory takes nothing returns nothing
    set gg_trg_Victory = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Victory, Player(11), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Victory, Condition( function Trig_Victory_Conditions ) )
    call TriggerAddAction( gg_trg_Victory, function Trig_Victory_Actions )
endfunction
 
function Trig_Loss_Loss takes nothing returns nothing
    local player p = GetEnumPlayer()
    call CustomDefeatBJ( p, "TRIGSTR_5978" )
    set p = null
endfunction

function Trig_Loss_Actions takes nothing returns nothing
    call ForForce( udg_Defenders, function Trig_Loss_Loss )
endfunction

//===========================================================================
function InitTrig_Loss takes nothing returns nothing
    set gg_trg_Loss = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Loss, gg_unit_h009_0083, EVENT_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Loss, function Trig_Loss_Actions )
endfunction

 
function Trig_Hero_Select_Conditions takes nothing returns boolean
    local player p = GetTriggerPlayer()
    local rect r = gg_rct_Entire_Hero_Selection_Area
    local unit u = GetTriggerUnit()
    local boolean b = udg_PickedHero[GetConvertedPlayerId(p)] == false and RectContainsUnit(r, u) == true
    set p = null
    set r = null
    set u = null
    return b
endfunction

function Streamline takes nothing returns nothing
  //Destroys triggers that are not necessary due to certain units, features, or content not being used

  //LOCAL DECLARATIONS
    local player p
    local unit u
    local integer c = 1
    local integer cc
    local integer id
    local boolean array b
    local integer array i
    local integer isize

  //ARRAY SETUP : defines which heroes have trigger-enhanced abilities
    set isize = 28
    set i[0] = 'E00O'
    set i[1] = 'N00V'
    set i[2] = 'E005'
    set i[3] = 'N01I'
    set i[4] = 'E007'
    set i[5] = 'O00A'
    set i[6] = 'N00I'
    set i[7] = 'O00O'
    set i[8] = 'O01A'
    set i[9] = 'O01D'
    set i[10]= 'U004'
    set i[11]= 'N016'
    set i[12]= 'U00C'
    set i[13]= 'U000'
    set i[14]= 'E000'
    set i[15]= 'U007'
    set i[16]= 'H003'
    set i[17]= 'H006'
    set i[18]= 'H001'
    set i[19]= 'H000'
    set i[20]= 'N03D'
    set i[21]= 'N002'
    set i[22]= 'E00V'
    set i[23]= 'U00D'
    set i[24]= 'U00R'
    set i[25]= 'O020'
    set i[26]= 'U00V'
    set i[27]= 'U00Q'

  //CHECK IDs LOOP : for each hero checks each unit id from array i and sets each boolean from array b accordingly
    loop //loops through each unit in array udg_Hero
        exitwhen c > 10
        set u = udg_Hero[c]
        set id = GetUnitTypeId(u)
        set cc = 0
        loop //loops through each integer in array i and set each boolean from array b
            exitwhen cc >= isize
            if id == i[cc] then
                set b[cc] = true
            endif
            set cc = cc + 1
        endloop
        set c = c + 1
    endloop
   
  //DESTROY TRIGGERS : checks each boolean from array b and destroys the corrosponding trigger
    if (not b[0]) then
        call DestroyTrigger(gg_trg_Unforgiveness)
        call DestroyTrigger(gg_trg_Attrition)
        call DestroyTrigger(gg_trg_Backstab)
        call DestroyTrigger(gg_trg_Revenge)
    endif
    if (not b[1]) then
        if (not b[27]) then
            call DestroyTrigger(gg_trg_Crushing_Blade)
        endif
        call DestroyTrigger(gg_trg_Fel_Grapple)
        call DestroyTrigger(gg_trg_Launching_Strike)
        call DestroyTrigger(gg_trg_Knockback)
    endif
    if (not b[2]) then
        call DestroyTrigger(gg_trg_Tranquility)
        call DestroyTrigger(gg_trg_Wisp_Explosion)
    endif
    if (not b[3]) then
        call DestroyTrigger(gg_trg_Nightmare_Annihilation)
        call DestroyTrigger(gg_trg_Sleep)
    endif
    if (not b[4]) then
        call DestroyTrigger(gg_trg_Demon_Boost)
    endif
    if (not b[5]) and (not b[4]) then
        call DestroyTrigger(gg_trg_One_With_Shadow)
    endif
    if (not b[6]) then
        call DestroyTrigger(gg_trg_INFINITE_POWAH)
        call DestroyTrigger(gg_trg_INFINITE_POWAH_kill)
    endif
    if (not b[7]) then
        call DestroyTrigger(gg_trg_Bear_Attack_Bonus)
    endif
    if (not b[8]) then
        call DestroyTrigger(gg_trg_Charge)
    endif
    if (not b[9]) then
        call DestroyTrigger(gg_trg_Crimson)
    endif
    if (not b[10]) then
        call DestroyTrigger(gg_trg_Death_Nova)
    endif
    if (not b[11]) then
        //call DestroyTrigger(gg_trg_Demon_Prison)
        //no longer exists
    endif
    if (not b[12]) then
        call DestroyTrigger(gg_trg_Divine_Intervention)
    endif
    if (not b[13]) then
        call DestroyTrigger(gg_trg_Earth_Nova)
    endif
    if (not b[14]) then
        call DestroyTrigger(gg_trg_Full_Moon)
        call DestroyTrigger(gg_trg_Howl)
        call DestroyTrigger(gg_trg_Metamorphosis)
    endif
    if (not b[15]) then
        call DestroyTrigger(gg_trg_Ghost_Storm)
    endif
    if (not b[16]) then
        call DestroyTrigger(gg_trg_Tornado_Nerf)
    endif
    if (not b[17]) then
        call DestroyTrigger(gg_trg_Headshot)
    endif
    if (not b[18]) then
        call DestroyTrigger(gg_trg_Implode)
    endif
    if (not b[19]) then
        call DestroyTrigger(gg_trg_Lightning_Sword)
        call DestroyTrigger(gg_trg_Lightning_Burst)
    endif
    if (not b[20]) then
        call DestroyTrigger(gg_trg_Meteor)
    endif
    if (not b[21]) then
        call DestroyTrigger(gg_trg_Nuclear_Strike)
    endif
    if (not b[22]) then
        call DestroyTrigger(gg_trg_Shadow_Explode)
    endif
    if (not b[23]) then
        call DestroyTrigger(gg_trg_Tribute)
    endif
    if (not b[24]) then
        call DestroyTrigger(gg_trg_Eat_Tree)
        call DestroyTrigger(gg_trg_Rage)
    endif
    if (not b[25]) then
        call DestroyTrigger(gg_trg_Hatsuendan)
        call DestroyTrigger(gg_trg_Kunaidesu)
    endif
    if (not b[26]) then
        call DestroyTrigger(gg_trg_Vice)
        call DestroyTrigger(gg_trg_Total_Corruption)
        call DestroyTrigger(gg_trg_Conjure_Blight)
    endif

  //NULLIFICATIONS
    set p = null
    set u = null

  //RETURN SUCCESS
    //call Message("Streamlining is complete; unused triggers have been removed.", 10)//people probably don't need to know this
endfunction

function Trig_Hero_Select_Init_Mag takes unit e returns nothing
    local item newmag = UnitAddItemById(e, 'I03C')
    local player p = GetOwningPlayer(e)
    local integer w = GetPlayerId(p)
    call SaveItemHandle(udg_mag, w, 0, newmag)    //id
    call SaveInteger(udg_mag, w, 1, 4)            //lvl
    call SaveInteger(udg_mag, w, 2, 0)            //pow
    call SaveInteger(udg_mag, w, 3, 0)            //dex
    call SaveInteger(udg_mag, w, 4, 0)            //mind
    call SaveInteger(udg_mag, w, 5, 0)            //def
    call SaveInteger(udg_mag, w, 6, 0)            //pb
    call SaveReal(udg_mag, w, 7, 0)               //defcycler
    call MLevelUp(w, 0, 0, 0, 5, e) //add initial stats
endfunction

function Trig_Hero_Select_Actions takes nothing returns nothing
    local location l = GetRectCenter(gg_rct_Initial_Spawn)
    local unit u = GetTriggerUnit()
    local unit e
    local unit bird
    local player p = GetTriggerPlayer()
    local player t = GetLocalPlayer()
    local integer i = GetUnitTypeId(u)
    local integer c = 1
    local boolean b = true
    if i == 'N053' then
        call RemoveUnit(u)
        set u = CreateUnit(Player(15), 'N03D', 4223, 13825, 270)
    endif
    if u == udg_LoadHero[GetConvertedPlayerId(p)] then
        if i == 'n02V' then
            set e = Create_Random_Hero(p, GetLocationX(l), GetLocationY(l))
        else
            call RemoveUnit(u)
            set e = CreateUnitAtLoc(p, i, l, 270)
        endif
        if udg_startingcondition == 2 then
            set bird = CreateUnitAtLoc(p, 'n03B', l, 270)
        elseif udg_startingcondition == 3 then
            call SetHeroLevel(e, GetHeroLevel(e)+5, false)
        endif
        call Trig_Hero_Select_Init_Mag(e)
        if udg_mode == 4 then
            call SetHeroLevelBJ(e, 100, false)
        endif
        set udg_PickedHero[GetConvertedPlayerId(p)] = true
        set udg_Hero[GetConvertedPlayerId(p)] = e
        call PanCameraToTimedLocForPlayer(p, l, 0)
        call SetCameraFieldForPlayer(p, CAMERA_FIELD_TARGET_DISTANCE, 2250, 1)
    else
        set udg_LoadHero[GetConvertedPlayerId(p)] = u
        if t == p then
            call Message("\n|cffccccccClass:|r " + GetUnitName(u) + "\n|cffccccccType:|r " + LoadStr(udg_tips, GetUnitTypeId(u), 0), 20)
        endif
    endif
    set c = 1
    loop
        exitwhen c > 10
        set t = Player(c-1)
        if (GetPlayerSlotState(t) == PLAYER_SLOT_STATE_PLAYING) and (udg_Hero[c] == null) then
            set b = false
        endif
        set c = c + 1
    endloop
    set bird = null
    set t = null
    call RemoveLocation(l)
    set l = null
    set u = null
    set e = null
    set p = null
    if b then
        call Streamline()
        call FlushParentHashtable(udg_tips)
        call DestroyTrigger(gg_trg_Hero_Select)
    endif
endfunction

//===========================================================================
function InitTrig_Hero_Select takes nothing returns nothing
    local integer i = 0
    set gg_trg_Hero_Select = CreateTrigger()
    call DisableTrigger(gg_trg_Hero_Select)
    loop
        exitwhen i > 9
        call TriggerRegisterPlayerSelectionEventBJ(gg_trg_Hero_Select, Player(i), true)
        set i = i + 1
    endloop
    call TriggerAddCondition(gg_trg_Hero_Select, Condition(function Trig_Hero_Select_Conditions))
    call TriggerAddAction(gg_trg_Hero_Select, function Trig_Hero_Select_Actions)
endfunction
function Respawn_Conditions takes nothing returns boolean
    local unit u = GetDyingUnit()
    local player p = GetOwningPlayer(u)
    local boolean b = (u == udg_Hero[GetConvertedPlayerId(p)])
    set u = null
    set p = null
    return b
endfunction

function Respawn_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetDyingUnit()
    local player p = GetOwningPlayer(u)
    local location a = GetRectCenter(gg_rct_Base)
    local integer respawn_time_formula = 10
    local timerdialog d = CreateTimerDialog(t)
    if GetPlayerController(p) == MAP_CONTROL_COMPUTER then
        if udg_botspawn == 0 then
            set a = GetRectCenter(gg_rct_Target)
        elseif udg_botspawn == 1 then
            set a = GetRectCenter(gg_rct_Base)
        elseif udg_botspawn == 2 then
            set a = GetRectCenter(gg_rct_LaneW)
        elseif udg_botspawn == 3 then
            set a = GetRectCenter(gg_rct_LaneSW)
        else
            set a = GetRectCenter(gg_rct_LaneS)
        endif
    endif
    if udg_mode == 3 then
        call CustomDefeatBJ( p, "You've died!" )
    endif
    if UnitHasItemOfTypeBJ(u, 'I01Z') then
        set respawn_time_formula = respawn_time_formula * 4 / 5
    endif
    if UnitHasItemOfTypeBJ(u, 'I028') then
        set respawn_time_formula = respawn_time_formula / 2
    endif
    if UnitHasItemOfTypeBJ(u, 'I032') then
        set respawn_time_formula = 1
    endif
    call TimerDialogSetTitle(d, "Hero Respawn")
    if GetLocalPlayer() == p then
        call TimerDialogDisplay(d, true)
    endif
    call Message(GetUnitName(u) + " has fallen and will revive in |cff00ff00" + I2S(respawn_time_formula) + "|r seconds.", 5)
    call TimerStart(t, respawn_time_formula, false, null)
    if udg_rc[GetConvertedPlayerId(p)] > 0 then
        set udg_rc[GetConvertedPlayerId(p)] = udg_rc[GetConvertedPlayerId(p)] - 1
        set respawn_time_formula = 0
    endif
    if udg_mode == 7 then
        set respawn_time_formula = respawn_time_formula - udg_flagbonus + 1
    endif
    call TriggerSleepAction(I2R(respawn_time_formula))

    //this if block is now extra safe to put an end to the no-respawn bug
    if ( GetUnitState(u, UNIT_STATE_LIFE) <= 0.405 ) then //checks life
        call ReviveHeroLoc( u, a, true )
        call PanCameraToTimedLocForPlayer( p, a, 1 )
        call SelectUnitForPlayerSingle( u, p )
        call Message(GetUnitName(u) + " has revived.", 5)
    elseif ( IsUnitType(u, UNIT_TYPE_DEAD) ) then //just incase life is messed up, check unit type dead
        call ReviveHeroLoc( u, a, true )
        call PanCameraToTimedLocForPlayer( p, a, 1 )
        call SelectUnitForPlayerSingle( u, p )
        call Message(GetUnitName(u) + " has revived.", 5)
    endif
    if  UnitHasItemOfTypeBJ(u, 'I028') or UnitHasItemOfTypeBJ(u, 'I02B') then
        call SetUnitManaPercentBJ(u, 100)
    else
        call SetUnitManaPercentBJ(u, 33.33)
    endif
    call RemoveLocation(a)
    call DestroyTimerDialog(d)
    call DestroyTimer(t)
    set d = null
    set a = null
    set p = null
    set u = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Respawn takes nothing returns nothing
    local integer p = 0
    set gg_trg_Respawn = CreateTrigger()
    loop
        exitwhen p > 9
        call TriggerRegisterPlayerUnitEventSimple( gg_trg_Respawn, Player(p), EVENT_PLAYER_UNIT_DEATH )
        set p = p + 1
    endloop
    call TriggerAddCondition( gg_trg_Respawn, Condition( function Respawn_Conditions ) )
    call TriggerAddAction( gg_trg_Respawn, function Respawn_Actions )
endfunction
 
function Trig_Gold_Reward_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local player p = Player(11)
    local boolean b = ( GetUnitTypeId(u) == udg_Wave[(udg_waveCount-2)] or GetUnitTypeId(u) == udg_Wave[(udg_waveCount-1)] or GetUnitTypeId(u) == udg_Wave[(udg_waveCount)] ) and ( CountLivingPlayerUnitsOfTypeId_Fixed(GetUnitTypeId(u), p) == 0 )
    set u = null
    set p = null
    return b
endfunction

function Trig_Gold_Reward_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer a = 0
    local integer w = 0
    local integer gold_reward_formula = 0
    local integer xp_reward_formula = 0
    local player p
    set a = 0
    if ( GetUnitTypeId(u) == udg_Wave[udg_waveCount] ) then
        set w = udg_waveCount
    elseif ( GetUnitTypeId(u) == udg_Wave[(udg_waveCount-1)] ) then
        set w = udg_waveCount - 1
    elseif ( GetUnitTypeId(u) == udg_Wave[(udg_waveCount-2)] ) then
        set w = udg_waveCount - 2
    endif
    set u = null
    if udg_prevbonus != w then
        set udg_prevbonus = w
        set gold_reward_formula = w * 50 + 50
        set xp_reward_formula = R2I( 10 + Pow(w, 1.2) * 20 + w * 30 * Count_Players() )
        if udg_mode == 7 then
            set gold_reward_formula = gold_reward_formula + udg_flagbonus * 50 - 300
            set xp_reward_formula = R2I( 100 * udg_flagbonus - 100 + Pow(w, 1.2) * 20 + w * 30 * Count_Players() )
        endif
        loop
            exitwhen a > 9
            set p = Player(a)
            call AddHeroXP( udg_Hero[a + 1], xp_reward_formula, true )
            call AdjustPlayerStateBJ( gold_reward_formula, Player(a), PLAYER_STATE_RESOURCE_GOLD )
            call AdjustPlayerStateBJ( 1, p, PLAYER_STATE_RESOURCE_LUMBER )
            set a = a + 1
        endloop
        call Message("--- |cff9900ffWave " + I2S(w) + " Report|r ---", 5)
        call Message("+|cffffcc00" + I2S(gold_reward_formula) + "|r Gold", 5)
        call Message("+|cff0000ff1|r Arcane Seal", 5)
        call Message("+|cff00ff00" + I2S(xp_reward_formula) + "|r Experience", 5)
        if udg_mode == 6 then
            call Next_Wave()
        endif
    endif
    set p = null
endfunction

//===========================================================================
function InitTrig_Gold_Reward takes nothing returns nothing
    set gg_trg_Gold_Reward = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Gold_Reward, Player(11), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Gold_Reward, Condition( function Trig_Gold_Reward_Conditions ) )
    call TriggerAddAction( gg_trg_Gold_Reward, function Trig_Gold_Reward_Actions )
endfunction
 
function Trig_Helper_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local boolean b = GetUnitLifePercent(u) <= 25 and udg_helper
    set u = null
    return b
endfunction

function Trig_Helper_Actions takes nothing returns nothing
    local location l = GetRectCenter(gg_rct_Base)
    local player p = Player(10)
    local unit u = CreateUnitAtLoc( p, 'O01E', l, 0 )
    set udg_helper = false
    call SetHeroLevel( u, 200, false )
    call UnitApplyTimedLifeBJ( udg_speed, 'BTLF', u )
    set udg_Chaos = udg_Chaos + 5
    call Check_Chaos()
    set udg_vpts = udg_vpts - 15
    set p = null
    set u = null
    call RemoveLocation(l)
    set l = null
endfunction

//===========================================================================
function InitTrig_Helper takes nothing returns nothing
    set gg_trg_Helper = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Helper, gg_unit_h009_0083, EVENT_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Helper, Condition( function Trig_Helper_Conditions ) )
    call TriggerAddAction( gg_trg_Helper, function Trig_Helper_Actions )
endfunction

 
function Trig_Waves_Actions takes nothing returns nothing
    if udg_mode == 2 or udg_mode == 4 then
        return
    endif
    set udg_Timer = CreateTimer()
    set udg_TimerDialog = CreateTimerDialog(udg_Timer)
    call TimerDialogSetTitle(udg_TimerDialog, "Wave 2 spawns in:")
    call TimerStart(udg_Timer, udg_speed, true, function Next_Wave)
    call TimerDialogDisplay(udg_TimerDialog, true)
    call Next_Wave()
endfunction

//===========================================================================
function InitTrig_Waves takes nothing returns nothing
    set gg_trg_Waves = CreateTrigger(  )
    call DisableTrigger( gg_trg_Waves )
    call TriggerAddAction( gg_trg_Waves, function Trig_Waves_Actions )
endfunction
 
//function Trig_Order_Conditions takes nothing returns boolean
//    local player p1 = Player(11)
//    local unit u = GetTriggerUnit()
//    local player p2 = GetOwningPlayer(u)
//    local boolean b = ( p1 == p2 )
//    set p1 = null
//    set p2 = null
//    set u = null
//    return b
//endfunction

function Trig_Order_Actions takes nothing returns nothing
    local rect r = gg_rct_Target
    local unit u = GetTriggerUnit()
    call IssuePointOrder(u, "patrol", GetRectCenterX(r), GetRectCenterY(r))
    set r = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Order takes nothing returns nothing
    local rect rr = GetPlayableMapRect()
    local region r = CreateRegion()
    call RegionAddRect(r, rr)
    set gg_trg_Order = CreateTrigger(  )
    call TriggerRegisterEnterRegion(gg_trg_Order, r, Condition(function Enemy_Check_11))
    //call TriggerRegisterEnterRectSimple( gg_trg_Order, GetPlayableMapRect() )
    //call TriggerAddCondition( gg_trg_Order, Condition( function Trig_Order_Conditions ) )
    call TriggerAddAction(gg_trg_Order, function Trig_Order_Actions)
    set r = null
    set rr = null
endfunction

 
//function Trig_Switch_Target_Conditions takes nothing returns boolean
//    local unit u = GetTriggerUnit()
//    local player p1 = GetOwningPlayer(u)
//    local player p2 = Player(11)
//    local boolean b = ( p1 == p2)
//    set u = null
//    set p1 = null
//    set p2 = null
//    return b
//endfunction

function Trig_Switch_Target_Actions takes nothing returns nothing
    local rect r = gg_rct_Main_Target
    local location l = GetRectCenter(r)
    local unit u = GetTriggerUnit()
    call IssuePointOrderLocBJ( u, "patrol", l )
    call RemoveLocation(l)
    set u = null
    set l = null
    set r = null
endfunction

//===========================================================================
function InitTrig_Switch_Target takes nothing returns nothing
    local region r = CreateRegion()
    call RegionAddRect(r, gg_rct_Target)
    set gg_trg_Switch_Target = CreateTrigger()
    call TriggerRegisterEnterRegion(gg_trg_Switch_Target, r, Condition(function Enemy_Check_11))
    //call TriggerRegisterEnterRectSimple( gg_trg_Switch_Target, gg_rct_Target )
    //call TriggerAddCondition( gg_trg_Switch_Target, Condition( function Trig_Switch_Target_Conditions ) )
    call TriggerAddAction( gg_trg_Switch_Target, function Trig_Switch_Target_Actions )
    set r = null
endfunction
 
//function Trig_Near_Conditions takes nothing returns boolean
//    local unit u = GetTriggerUnit()
//    local player p1 = Player(11)
//    local player p2 = GetOwningPlayer(u)
//    local boolean b = ( p1 == p2 )
//    set u = null
//    set p1 = null
//    set p2 = null
//    return b
//endfunction

function Trig_Near_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call SetUnitMoveSpeed(u, GetUnitDefaultMoveSpeed(u))
    set u = null
endfunction

//===========================================================================
function InitTrig_Near takes nothing returns nothing
    local region r = CreateRegion()
    call RegionAddRect(r, gg_rct_Near)
    set gg_trg_Near = CreateTrigger(  )
    call TriggerRegisterEnterRegion(gg_trg_Near, r, Condition(function Enemy_Check_11))
    //call TriggerRegisterEnterRectSimple( gg_trg_Near, gg_rct_Near )
    //call TriggerAddCondition( gg_trg_Near, Condition( function Trig_Near_Conditions ) )
    call TriggerAddAction( gg_trg_Near, function Trig_Near_Actions )
    set r = null
endfunction

 
//function Trig_Enemy_Cleanup_Conditions takes nothing returns boolean
//    local unit u = GetTriggerUnit()
//    local player p1 = GetOwningPlayer(u)
//    local player p2 = Player(11)
//    local boolean b = ( p1 == p2 )
//    set u = null
//    set p1 = null
//    set p2 = null
//    return b
//endfunction

function Trig_Enemy_Cleanup_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call IssuePointOrder(u, "patrol", GetRectCenterX(gg_rct_Main_Target), GetRectCenterY(gg_rct_Main_Target))
    set u = null
endfunction

//===========================================================================
function InitTrig_Enemy_Cleanup takes nothing returns nothing
    local rect rr = GetPlayableMapRect()
    local region r = CreateRegion()
    call RegionAddRect(r, rr)
    set gg_trg_Enemy_Cleanup = CreateTrigger()
    call TriggerRegisterEnterRegion(gg_trg_Enemy_Cleanup, r, Condition(function Enemy_Check_11))
    //call TriggerRegisterEnterRectSimple(gg_trg_Enemy_Cleanup, r)
    //call TriggerAddCondition(gg_trg_Enemy_Cleanup, Condition(function Trig_Enemy_Cleanup_Conditions))
    call TriggerAddAction(gg_trg_Enemy_Cleanup, function Trig_Enemy_Cleanup_Actions)
    set r = null
    set rr = null
endfunction
 
function Trig_Mag_Level_Up_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local item i = LoadItemHandle(udg_mag, GetPlayerId(p), 0)
    local boolean b = UnitHasItem(u, i)
    set u = null
    set p = null
    set i = null
    return b
endfunction

function Trig_Mag_Level_Up_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetTriggerPlayer()
    local integer g = GetPlayerId(p)
    call MLevelUp(g, 1, 1, 1, 1, u)
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Mag_Level_Up takes nothing returns nothing
    set gg_trg_Mag_Level_Up = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Mag_Level_Up, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddCondition( gg_trg_Mag_Level_Up, Condition( function Trig_Mag_Level_Up_Conditions ) )
    call TriggerAddAction( gg_trg_Mag_Level_Up, function Trig_Mag_Level_Up_Actions )
endfunction

 
function Trig_Check_Level_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A085'
endfunction

function Trig_Check_Level_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetTriggerPlayer()
    local integer i = GetPlayerId(p)
    local item mag = LoadItemHandle(udg_mag, i, 0)
    local integer lvl = LoadInteger(udg_mag, i, MStat("lvl"))
    local integer pow = LoadInteger(udg_mag, i, MStat("pow"))
    local integer dex = LoadInteger(udg_mag, i, MStat("dex"))
    local integer mind = LoadInteger(udg_mag, i, MStat("mind"))
    local integer def = LoadInteger(udg_mag, i, MStat("def"))
    local integer pb = LoadInteger(udg_mag, i, MStat("pb"))
    local string pbname
    local string name = GetItemName(mag)
    //call IssueImmediateOrder(u,"stop")
    if pow > dex and pow > mind and pow > def then
        set pbname = "|cffff0000PILLA|r (damage enemies)"
    elseif dex > pow and dex > mind and dex > def then
        set pbname = "|cffffff00ESTLLA|r (destroy enemy mana)"
    elseif mind > pow and mind > dex and mind > def then
        set pbname = "|cff00ff00MYLLA & YOULLA|r (cooldown reset)"
    else
        set pbname = "|cff0000ffLEILLA|r (hp & mana bonus)"
    endif
    call DisplayTextToPlayer(p, 0, 0, "--- " + name + " ---\n|cffff00ffLVL|r: " + I2S(lvl) + "\n|cffff0000POW|r: " + I2S(pow) + "\n|cffffff00DEX|r: " + I2S(dex) + "\n|cff00ff00MIND|r: " + I2S(mind) + "\n|cff0000ffDEF|r: " + I2S(def) + "\n|cffccccccPB|r: " + I2S(pb) + "\n---\n|cffccccccPhoton Blast|r: " + pbname + "\n---" )
    set p = null
    set u = null
    set mag = null
endfunction

//===========================================================================
function InitTrig_Check_Level takes nothing returns nothing
    set gg_trg_Check_Level = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Check_Level, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Check_Level, Condition( function Trig_Check_Level_Conditions ) )
    call TriggerAddAction( gg_trg_Check_Level, function Trig_Check_Level_Actions )
endfunction

 
function Trig_Feed_Trimate_Conditions takes nothing returns boolean
    local player p = GetTriggerPlayer()
    local boolean b = GetSpellAbilityId() == 'A0A7' and GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) >= 100
    set p = null
    return b
endfunction

function Trig_Feed_Trimate_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u = GetTriggerUnit()
    local integer i = GetPlayerId(p)
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) - 100)
    call MLevelUp(i, 1, 0, 0, 0, u)
    call DisplayTextToPlayer(p, 0, 0, "--- |cff00ffffFeeding Report|r ---\n|cffff0000POW|r + 1\n---")
    //call IssueImmediateOrder(u,"stop")
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Feed_Trimate takes nothing returns nothing
    set gg_trg_Feed_Trimate = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Feed_Trimate, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Feed_Trimate, Condition( function Trig_Feed_Trimate_Conditions ) )
    call TriggerAddAction( gg_trg_Feed_Trimate, function Trig_Feed_Trimate_Actions )
endfunction

 
function Trig_Feed_Sol_Atomizer_Conditions takes nothing returns boolean
    local player p = GetTriggerPlayer()
    local boolean b = GetSpellAbilityId() == 'A0AA' and GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) >= 100
    set p = null
    return b
endfunction

function Trig_Feed_Sol_Atomizer_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u = GetTriggerUnit()
    local integer i = GetPlayerId(p)
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) - 100)
    call MLevelUp(i, 0, 1, 0, 0, u)
    call DisplayTextToPlayer(p, 0, 0, "--- |cff00ffffFeeding Report|r ---\n|cffffff00DEX|r + 1\n---")
    //call IssueImmediateOrder(u,"stop")
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Feed_Sol_Atomizer takes nothing returns nothing
    set gg_trg_Feed_Sol_Atomizer = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Feed_Sol_Atomizer, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Feed_Sol_Atomizer, Condition( function Trig_Feed_Sol_Atomizer_Conditions ) )
    call TriggerAddAction( gg_trg_Feed_Sol_Atomizer, function Trig_Feed_Sol_Atomizer_Actions )
endfunction

 
function Trig_Feed_Trifluid_Conditions takes nothing returns boolean
    local player p = GetTriggerPlayer()
    local boolean b = GetSpellAbilityId() == 'A0AB' and GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) >= 100
    set p = null
    return b
endfunction

function Trig_Feed_Trifluid_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u = GetTriggerUnit()
    local integer i = GetPlayerId(p)
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) - 100)
    call MLevelUp(i, 0, 0, 1, 0, u)
    call DisplayTextToPlayer(p, 0, 0, "--- |cff00ffffFeeding Report|r ---\n|cff00ff00MIND|r + 1\n---")
    //call IssueImmediateOrder(u,"stop")
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Feed_Trifluid takes nothing returns nothing
    set gg_trg_Feed_Trifluid = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Feed_Trifluid, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Feed_Trifluid, Condition( function Trig_Feed_Trifluid_Conditions ) )
    call TriggerAddAction( gg_trg_Feed_Trifluid, function Trig_Feed_Trifluid_Actions )
endfunction

 
function Trig_Feed_Moon_Atomizer_Conditions takes nothing returns boolean
    local player p = GetTriggerPlayer()
    local boolean b = GetSpellAbilityId() == 'A0AC' and GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) >= 100
    set p = null
    return b
endfunction

function Trig_Feed_Moon_Atomizer_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u = GetTriggerUnit()
    local integer i = GetPlayerId(p)
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) - 100)
    call MLevelUp(i, 0, 0, 0, 1, u)
    call DisplayTextToPlayer(p, 0, 0, "--- |cff00ffffFeeding Report|r ---\n|cff0000ffDEF|r + 1\n---")
    //call IssueImmediateOrder(u,"stop")
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Feed_Moon_Atomizer takes nothing returns nothing
    set gg_trg_Feed_Moon_Atomizer = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Feed_Moon_Atomizer, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Feed_Moon_Atomizer, Condition( function Trig_Feed_Moon_Atomizer_Conditions ) )
    call TriggerAddAction( gg_trg_Feed_Moon_Atomizer, function Trig_Feed_Moon_Atomizer_Actions )
endfunction

 
function Trig_PB_Generate_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local boolean b = UnitHasItem(u, LoadItemHandle(udg_mag, GetPlayerId(p), 0)) and LoadInteger(udg_mag, GetPlayerId(p), MStat("pb")) >= 99
    if (GetRandomInt(1, 20) <= 7) then
        call SaveInteger(udg_mag, GetPlayerId(p), MStat("pb"), LoadInteger(udg_mag, GetPlayerId(p), MStat("pb"))+1)
        if GetRandomInt(1, 20) == 7 and UnitHasItemOfTypeBJ(u, 'I02V') and UnitHasItemOfTypeBJ(u, 'I02X') then
            call SaveInteger(udg_mag, GetPlayerId(p), MStat("pb"), LoadInteger(udg_mag, GetPlayerId(p), MStat("pb"))+1)
        endif
    endif
    set u = null
    set p = null
    return b
endfunction

function Trig_PB_Generate_ManaKill takes nothing returns nothing
    local unit u = GetEnumUnit()
    local real i = GetUnitState(u, UNIT_STATE_LIFE) - (GetUnitState(u, UNIT_STATE_MANA)/5)
    if i < 1 then
        set i = 1
    endif
    call SetUnitState(u, UNIT_STATE_LIFE, i)
    call SetUnitState(u, UNIT_STATE_MANA, 0)
    set u = null
endfunction

function Trig_PB_Generate_Kill takes nothing returns nothing //no longer kills, just sets HP to 1
    local unit u = GetEnumUnit()
    if GetUnitLevel(u) < 99 then
        call SetUnitState(u, UNIT_STATE_LIFE, 1)
    else
        call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE)/2)
    endif
    set u = null
endfunction

function Trig_PB_Generate_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local location l = GetUnitLoc(u)
    local group g = CreateGroup()
    local player p = GetOwningPlayer(u)
    local integer id = GetPlayerId(p)
    local integer pow = LoadInteger(udg_mag, id, MStat("pow"))
    local integer dex = LoadInteger(udg_mag, id, MStat("dex"))
    local integer mind = LoadInteger(udg_mag, id, MStat("mind"))
    local integer def = LoadInteger(udg_mag, id, MStat("def"))
    local texttag t = CreateTextTagUnitBJ("PHOTON BLAST ACTIVATE!", u, 0, 10, 100, 100, 0, 10)
    local unit e = CreateUnit(p, 'ncp3', GetUnitX(u), GetUnitY(u), 0)
    local string s = "|cffffff00ACTIVATE!|r\n+ Affects "
    local integer m = 0
    if UnitHasItemOfTypeBJ(u, 'I02V') then
        set m = m + 1
    endif
    if UnitHasItemOfTypeBJ(u, 'I02X') then
        set m = m + 1
    endif
    call SetTextTagPermanentBJ(t, false)
    call SetTextTagFadepointBJ(t, 2)
    call SetTextTagVelocityBJ(t, 40, 90)
    call SetTextTagLifespanBJ(t, 3)
    if pow > dex and pow > mind and pow > def then
        set s = "|cffff0000PILLA|r " + s + "enemies within 300 range\n+ 99.9% HP destruction (non-bosses)\n+ 50% HP destruction (bosses)"
        set g = GetUnitsInRangeOfLocMatching(300 + 50 * m, l, Filter(function Enemy_Check))
        call ForGroup(g, function Trig_PB_Generate_Kill)
    elseif dex > pow and dex > mind and dex > def then
        set s = "|cffffff00ESTLLA|r " + s + "enemies within 2000 range\n+ 20% mana burn damage\n+ 100% mana destruction"
        set g = GetUnitsInRangeOfLocMatching(2000 + 500 * m, l, Filter(function Enemy_Check))
        call ForGroup(g, function Trig_PB_Generate_ManaKill)
    elseif mind > pow and mind > dex and mind > def then
        set s = "|cff00ff00MYLLA & YOULLA|r " + s + "self\n+ Cooldown reset"
        call UnitResetCooldown(u)
    elseif def >= pow and def >= dex and def >= mind then
        set s = "|cff0000ffLEILLA|r " + s + "self\n+ Up to 50% HP restore\n+ 100% mana restore"
        if GetUnitStatePercent(u, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) < (50 + 10 * m) then
            call SetUnitLifePercentBJ(u, 50 + 50 * m)
        endif
        call SetUnitManaPercentBJ(u, 100)
    endif
    if p == GetLocalPlayer() then
        call Message("|cffffff00PHOTON BLAST:|r " + s, 8)
    endif
    call SaveInteger(udg_mag, GetPlayerId(p), MStat("pb"), 0)
    set u = null
    set p = null
    call RemoveLocation(l)
    set l = null
    call DestroyGroup(g)
    set g = null
    call TriggerSleepAction(3)
    call RemoveUnit(e)
    set e = null
    set t = null
endfunction

//===========================================================================
function InitTrig_PB_Generate takes nothing returns nothing
    set gg_trg_PB_Generate = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_PB_Generate, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_PB_Generate, Condition( function Trig_PB_Generate_Conditions ) )
    call TriggerAddAction( gg_trg_PB_Generate, function Trig_PB_Generate_Actions )
endfunction

 
function Awakenable takes nothing returns boolean
    local unit u = GetFilterUnit()
    local boolean b = (GetHeroLevel(u) >= 35 and UnitHasItemOfTypeBJ(u, 'I02N'))
    set u = null
    return b
endfunction

function Trig_Awaken_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item i = GetItemOfTypeFromUnitBJ(u, 'I02N')
    local player p = GetOwningPlayer(u)
    call RemoveItem(i)
    set i = UnitAddItemById(u, 'I043')
    call Message(GetPlayerName(p) + " has awakened the true power of the Hammer of Thor!", 5)
    call DestroyEffect(AddSpecialEffectTarget("war3mapImported\\Lightnings Long.mdx", u, "origin"))
    set udg_Chaos = udg_Chaos + 2
    call Check_Chaos()
    set udg_vpts = udg_vpts + 10/Count_Players()
    set u = null
    set p = null
    set i = null
endfunction

//===========================================================================
function InitTrig_Awaken takes nothing returns nothing
    local region r = CreateRegion()
    call RegionAddRect(r, gg_rct_Region_045)
    set gg_trg_Awaken = CreateTrigger()
    call TriggerRegisterEnterRegion(gg_trg_Awaken, r, Condition(function Awakenable))
    call TriggerAddAction(gg_trg_Awaken, function Trig_Awaken_Actions)
    set r = null
endfunction
 
function Trig_Dragon_Stone_Conditions takes nothing returns boolean
    local unit u = GetKillingUnit()
    local boolean b = UnitHasItemOfTypeBJ(u, 'I02D')
    set u = null
    return b
endfunction

function Trig_Dragon_Stone_Actions takes nothing returns nothing
    local unit u = GetKillingUnit()
    local player p = GetOwningPlayer(u)
    local item i = UnitAddItemById(u, 'I032')
    call Message(GetPlayerName(p) + " has acquired the legendary Dragon Stone!", 5)
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin"))
    set udg_Chaos = udg_Chaos + 2
    call Check_Chaos()
    set udg_vpts = udg_vpts + 10/Count_Players()
    set u = null
    set p = null
    set i = null
endfunction

//===========================================================================
function InitTrig_Dragon_Stone takes nothing returns nothing
    set gg_trg_Dragon_Stone = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Dragon_Stone, gg_unit_h017_0059, EVENT_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Dragon_Stone, Condition( function Trig_Dragon_Stone_Conditions ) )
    call TriggerAddAction( gg_trg_Dragon_Stone, function Trig_Dragon_Stone_Actions )
endfunction

 
function Trig_Leviathan_Razor_Armor_Conditions takes nothing returns boolean
    local unit u = GetKillingUnit()
    local boolean b = UnitHasItemOfTypeBJ(u, 'I02D')
    set u = null
    return b
endfunction

function Trig_Leviathan_Razor_Armor_Actions takes nothing returns nothing
    local unit u = GetKillingUnit()
    local player p = GetOwningPlayer(u)
    local item i = UnitAddItemById(u, 'I01S')
    call Message(GetPlayerName(p) + " has acquired the legendary Leviathan Razor Armor!", 5)
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin"))
    set udg_Chaos = udg_Chaos + 2
    call Check_Chaos()
    set udg_vpts = udg_vpts + 10/Count_Players()
    set u = null
    set p = null
    set i = null
endfunction

//===========================================================================
function InitTrig_Leviathan_Razor_Armor takes nothing returns nothing
    set gg_trg_Leviathan_Razor_Armor = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Leviathan_Razor_Armor, gg_unit_n01U_0046, EVENT_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Leviathan_Razor_Armor, Condition( function Trig_Leviathan_Razor_Armor_Conditions ) )
    call TriggerAddAction( gg_trg_Leviathan_Razor_Armor, function Trig_Leviathan_Razor_Armor_Actions )
endfunction

 
function Trig_Phoenix_Wing_Conditions takes nothing returns boolean
    local unit u = GetKillingUnit()
    local boolean b = UnitHasItemOfTypeBJ(u, 'I02D')
    set u = null
    return b
endfunction

function Trig_Phoenix_Wing_Actions takes nothing returns nothing
    local unit u = GetKillingUnit()
    local player p = GetOwningPlayer(u)
    local item i = UnitAddItemById(u, 'I042')
    call Message(GetPlayerName(p) + " has acquired the legendary Phoenix Wing!", 5)
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin"))
    set udg_Chaos = udg_Chaos + 2
    call Check_Chaos()
    set udg_vpts = udg_vpts + 10/Count_Players()
    set u = null
    set p = null
    set i = null
endfunction

//===========================================================================
function InitTrig_Phoenix_Wing takes nothing returns nothing
    set gg_trg_Phoenix_Wing = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_Phoenix_Wing, gg_unit_h00P_0042, EVENT_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Phoenix_Wing, Condition( function Trig_Phoenix_Wing_Conditions ) )
    call TriggerAddAction( gg_trg_Phoenix_Wing, function Trig_Phoenix_Wing_Actions )
endfunction

 
function Trig_Masashi_Asuka_Kills_Conditions takes nothing returns boolean
    local unit u = GetKillingUnit()
    local item i
    local integer a = 0
    loop
        exitwhen a > 6
        set i = UnitItemInSlot(u, a)
        if (i != null) and (GetItemTypeId(i) == 'I01L') then
            set i = null
            set u = null
            return true
        endif
        set a = a + 1
    endloop
    set i = null
    set u = null
    return false
endfunction

function Trig_Masashi_Asuka_Kills_Actions takes nothing returns nothing
    local unit u = GetKillingUnit()
    local player p = GetOwningPlayer(u)
    local item m = null
    local effect e = null
    local integer i = LoadInteger( udg_h, GetPlayerId(p), 'SAYK' ) + 1
    set u = udg_Hero[GetPlayerId(p)+1]
    if ( i >= 230 ) then
        set m = GetItemOfTypeFromUnitBJ(u, 'I01L')
        call RemoveItem( m )
        set m = null
        set m = UnitAddItemByIdSwapped( 'I02T', u )
        call Message(GetPlayerName(p) + " has unlocked the legendary combo Masashi & Asuka!", 5)
        set e = AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin" )
        set udg_Chaos = udg_Chaos + 2
        call Check_Chaos()
        call DestroyEffect(e)
        set e = null
        set i = 0
        set udg_vpts = udg_vpts + 10/Count_Players()
    endif
    call SaveInteger( udg_h, GetPlayerId(p), 'SAYK', i )
    set u = null
    set p = null
    set m = null
endfunction

//===========================================================================
function InitTrig_Masashi_Asuka_Kills takes nothing returns nothing
    set gg_trg_Masashi_Asuka_Kills = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Masashi_Asuka_Kills, Player(11), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Masashi_Asuka_Kills, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Masashi_Asuka_Kills, Condition( function Trig_Masashi_Asuka_Kills_Conditions ) )
    call TriggerAddAction( gg_trg_Masashi_Asuka_Kills, function Trig_Masashi_Asuka_Kills_Actions )
endfunction
Goes for 230 kills instead of 23000... also I only wanted to make one and to not use variables so the SJS recipe has a massive cooldown and this trigger can only make 3.
function Trig_Tsumikiri_Kills_Conditions takes nothing returns boolean
    local unit u = GetKillingUnit()
    local item i
    local integer a = 0
    loop
        set i = UnitItemInSlot(u, a)
        if (i != null) and (GetItemTypeId(i) == 'I01I') then
            set i = null
            set u = null
            return true
        endif
        set a = a + 1
        exitwhen a >= 6
    endloop
    set i = null
    set u = null
    return false
endfunction

function Trig_Tsumikiri_Kills_Actions takes nothing returns nothing
    local unit u = GetKillingUnit()
    local player p = GetOwningPlayer(u)
    local integer i = LoadInteger( udg_h, GetPlayerId(p), 'TKIL' ) + 1
    local effect e = null
    set u = udg_Hero[GetPlayerId(p)+1]
    if ( i >= 230 ) then
        call RemoveItem( GetItemOfTypeFromUnitBJ(u, 'I01I') )
        call UnitAddItemByIdSwapped( 'I01J', u )
        call Message(GetPlayerName(p) + " has unlocked the legendary Tsumikiri J-Sword!", 5)
        set e = AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin" )
        set udg_Chaos = udg_Chaos + 2
        call Check_Chaos()
        call DestroyEffect(e)
        set e = null
        set i = 0
        set udg_vpts = udg_vpts + 10/Count_Players()
    endif
    call SaveInteger( udg_h, GetPlayerId(p), 'TKIL', i )
    set u = null
    set p = null
endfunction

//===========================================================================
function InitTrig_Tsumikiri_Kills takes nothing returns nothing
    set gg_trg_Tsumikiri_Kills = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Tsumikiri_Kills, Player(11), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Tsumikiri_Kills, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Tsumikiri_Kills, Condition( function Trig_Tsumikiri_Kills_Conditions ) )
    call TriggerAddAction( gg_trg_Tsumikiri_Kills, function Trig_Tsumikiri_Kills_Actions )
endfunction
 
Goes for 230 kills instead of 23000... also I only wanted to make one and to not use variables so the SJS recipe has a massive cooldown and this trigger can only make 3.
function Trig_Archangel_Kills_Conditions takes nothing returns boolean
    local unit u = GetKillingUnit()
    local item i
    local integer a = 0
    loop
        set i = UnitItemInSlot(u, a)
        if (i != null) and (GetItemTypeId(i) == 'I024') then
            set i = null
            set u = null
            return true
        endif
        set a = a + 1
        exitwhen a >= 6
    endloop
    set i = null
    set u = null
    return false
endfunction

function Trig_Archangel_Kills_Actions takes nothing returns nothing
    local unit u = GetKillingUnit()
    local player p = GetOwningPlayer(u)
    local item m
    local integer i = LoadInteger( udg_h, GetPlayerId(p), 'AKIL' ) + 1
    set u = udg_Hero[GetPlayerId(p)+1]
    if ( i >= 230 ) then
        set m = GetItemOfTypeFromUnitBJ(u, 'I024')
        call RemoveItem( m )
        set m = null
        set m = UnitAddItemByIdSwapped( 'I02F', u )
        call Message(GetPlayerName(p) + " has unlocked the legendary Archangel's Blade!", 5)
        call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin" ) )
        set udg_Chaos = udg_Chaos + 2
        call Check_Chaos()
        set i = 0
        set udg_vpts = udg_vpts + 10/Count_Players()
    endif
    call SaveInteger( udg_h, GetPlayerId(p), 'AKIL', i )
    set u = null
    set p = null
    set m = null
endfunction

//===========================================================================
function InitTrig_Archangel_Kills takes nothing returns nothing
    set gg_trg_Archangel_Kills = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Archangel_Kills, Player(11), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Archangel_Kills, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Archangel_Kills, Condition( function Trig_Archangel_Kills_Conditions ) )
    call TriggerAddAction( gg_trg_Archangel_Kills, function Trig_Archangel_Kills_Actions )
endfunction

 
function Trig_Perfect_Rebirth_Damage_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local boolean b = UnitHasItemOfTypeBJ(u, 'I01Z')
    set u = null
    return b
endfunction

function Trig_Perfect_Rebirth_Damage_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local integer mission_id = GetConvertedPlayerId(p)
    call SaveInteger( udg_h, mission_id, 'PRBD', LoadInteger(udg_h, mission_id, 'PRBD') + udg_waveCount )
    set u = null
    set p = null
endfunction

//===========================================================================
function InitTrig_Perfect_Rebirth_Damage takes nothing returns nothing
    set gg_trg_Perfect_Rebirth_Damage = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Perfect_Rebirth_Damage, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition( gg_trg_Perfect_Rebirth_Damage, Condition( function Trig_Perfect_Rebirth_Damage_Conditions ) )
    call TriggerAddAction( gg_trg_Perfect_Rebirth_Damage, function Trig_Perfect_Rebirth_Damage_Actions )
endfunction

 
function Trig_Perfect_Rebirth_Raise_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local boolean b = UnitHasItemOfTypeBJ(u, 'I01Z')
    set u = null
    return b
endfunction

function Trig_Perfect_Rebirth_Raise_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local item i
    if ( LoadInteger(udg_h, GetConvertedPlayerId(p), 'PRBD') >= 10000 ) then
        set i = GetItemOfTypeFromUnitBJ(u, 'I01Z')
        call RemoveItem( i )
        set i = null
        set i = UnitAddItemByIdSwapped( 'I028', udg_Hero[GetPlayerId(p)+1] )
        call Message(GetPlayerName(p) + " has unlocked the legendary Perfect Rebirth!", 5)
        call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin" ) )
        set udg_Chaos = udg_Chaos + 2
        call Check_Chaos()
        call SaveInteger(udg_h, GetConvertedPlayerId(p), 'PRBD', 0)
        set udg_vpts = udg_vpts + 10/Count_Players()
    endif
    set u = null
    set p = null
    set i = null
endfunction

//===========================================================================
function InitTrig_Perfect_Rebirth_Raise takes nothing returns nothing
    set gg_trg_Perfect_Rebirth_Raise = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Perfect_Rebirth_Raise, EVENT_PLAYER_HERO_REVIVE_FINISH )
    call TriggerAddCondition( gg_trg_Perfect_Rebirth_Raise, Condition( function Trig_Perfect_Rebirth_Raise_Conditions ) )
    call TriggerAddAction( gg_trg_Perfect_Rebirth_Raise, function Trig_Perfect_Rebirth_Raise_Actions )
endfunction

 
function Trig_Forgotten_Jewel_Count_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local boolean b = UnitHasItemOfTypeBJ(u, 'I022')
    set u = null
    return b
endfunction

function Trig_Forgotten_Jewel_Count_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local integer count = LoadInteger( udg_h, GetConvertedPlayerId(p), 'FJCC')
    local item i
    set u = udg_Hero[GetPlayerId(p)+1]
    set i = GetItemOfTypeFromUnitBJ(u, 'I022')
    if count >= 90 then
        call RemoveItem(i)
        call UnitAddItemByIdSwapped('I02B', u)
        call Message(GetPlayerName(p) + " has unlocked the legendary Forgotten Jewel!", 5)
        call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin" ) )
        set udg_Chaos = udg_Chaos + 2
        call Check_Chaos()
        call SaveInteger(udg_h, GetConvertedPlayerId(p), 'FJCC', 0)
        set udg_vpts = udg_vpts + 10/Count_Players()
    else
        set count = count + 1
        call SaveInteger(udg_h, GetConvertedPlayerId(p), 'FJCC', count)
    endif
    set i = null
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Forgotten_Jewel_Count takes nothing returns nothing
    set gg_trg_Forgotten_Jewel_Count = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Forgotten_Jewel_Count, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Forgotten_Jewel_Count, Condition( function Trig_Forgotten_Jewel_Count_Conditions ) )
    call TriggerAddAction( gg_trg_Forgotten_Jewel_Count, function Trig_Forgotten_Jewel_Count_Actions )
endfunction
function Trig_Obsidian_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local boolean b = UnitHasItemOfTypeBJ(u, 'I029') and (GetSpellAbilityId() == 'A06R')
    set u = null
    return b
endfunction

function Trig_Obsidian_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local integer count = LoadInteger( udg_h, GetConvertedPlayerId(p), 'OBSD')
    local item i
    set u = udg_Hero[GetPlayerId(p)+1]
    set i = GetItemOfTypeFromUnitBJ(u, 'I029')
    if count >= 12 then
        call RemoveItem(i)
        call UnitAddItemByIdSwapped('I044', u)
        call Message(GetPlayerName(p) + " has unlocked the legendary Obsidian Blade!", 5)
        call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", u, "origin" ) )
        set udg_Chaos = udg_Chaos + 2
        call Check_Chaos()
        call SaveInteger(udg_h, GetConvertedPlayerId(p), 'OBSD', 0)
        set udg_vpts = udg_vpts + 10/Count_Players()
    else
        set count = count + 1
        call SaveInteger(udg_h, GetConvertedPlayerId(p), 'OBSD', count)
    endif
    set i = null
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Obsidian takes nothing returns nothing
    set gg_trg_Obsidian = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Obsidian, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Obsidian, Condition( function Trig_Obsidian_Conditions ) )
    call TriggerAddAction( gg_trg_Obsidian, function Trig_Obsidian_Actions )
endfunction
function Trig_Spirit_of_Corruption_Timer_Conditions takes nothing returns boolean
    local item i = GetManipulatedItem()
    local boolean b = GetItemTypeId(i) == 'I02P'
    set i = null
    return b
endfunction

function corruption_check takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer pid = LoadInteger(udg_crpt, GetHandleId(t), 'p')
    local item i
    local integer c = LoadInteger(udg_crpt, GetHandleId(t), 'c')
    if UnitHasItemOfTypeBJ(udg_Hero[pid+1], 'I02P') then
        if c >= 300 then
            set i = GetItemOfTypeFromUnitBJ(udg_Hero[pid+1], 'I02P')
            call RemoveItem(i)
            call UnitAddItemByIdSwapped('I01Q', udg_Hero[pid+1])
            call Message(GetPlayerName(Player(pid)) + " has unlocked the legendary Spirit of Corruption!", 5)
            call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", udg_Hero[pid+1], "origin" ) )
            set udg_Chaos = udg_Chaos + 2
            call Check_Chaos()
            call SaveInteger(udg_crpt, GetHandleId(t), 'c', -1)
            call PauseTimer(t)
            call DestroyTimer(t)
            set udg_vpts = udg_vpts + 10/Count_Players()
        elseif c >= 0 then
            call SaveInteger(udg_crpt, GetHandleId(t), 'c', c + 1)
        endif
    else
        call SaveInteger(udg_crpt, GetHandleId(t), 'c', 0)
        call FlushChildHashtable(udg_crpt, GetHandleId(t))
        call PauseTimer(t)
        call DestroyTimer(t)
    endif
    set i = null
    set t = null
endfunction

function Trig_Spirit_of_Corruption_Timer_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local timer t = CreateTimer()
    call SaveInteger(udg_crpt, GetHandleId(t), 'p', GetPlayerId(p))
    call SaveInteger(udg_crpt, GetHandleId(t), 'c', 0)
    call TimerStart(t, 3, true, function corruption_check)
    set t = null
    set p = null
endfunction

//===========================================================================
function InitTrig_Spirit_of_Corruption_Timer takes nothing returns nothing
    set gg_trg_Spirit_of_Corruption_Timer = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Spirit_of_Corruption_Timer, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_Spirit_of_Corruption_Timer, Condition( function Trig_Spirit_of_Corruption_Timer_Conditions ) )
    call TriggerAddAction( gg_trg_Spirit_of_Corruption_Timer, function Trig_Spirit_of_Corruption_Timer_Actions )
endfunction

 
function PlayerId2ColorString takes integer id returns string
    if id == 0 then
        return "|cffff0000"
    elseif id == 1 then
        return "|cff0042ff"
    elseif id == 2 then
        return "|cff1ce6b9"
    elseif id == 3 then
        return "|cff540081"
    elseif id == 4 then
        return "|cffffff00"
    elseif id == 5 then
        return "|cffff8a0e"
    elseif id == 6 then
        return "|cff20c000"
    elseif id == 7 then
        return "|cffe55bb0"
    elseif id == 8 then
        return "|cff959697"
    elseif id == 9 then
        return "|cff7ebff1"
    else
        return "|cff000000"
    endif
endfunction

function Trig_Create_Actions takes nothing returns nothing
    local integer playerid = 0
    local integer boardrow = 0
    local player p
    local string name
    set udg_multiboard = CreateMultiboardBJ( 2, Count_Players(), "Kills" )
    call MultiboardSetItemsStyle(udg_multiboard, true, false)
    loop
        exitwhen playerid > 9
        set p = Player(playerid)
        if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then
            set name = PlayerId2ColorString(GetPlayerId(p))
            if GetPlayerController(p) == MAP_CONTROL_COMPUTER then
                set name = name + "Bot " + I2S(GetPlayerId(p)+1) + "|r"
                call SetPlayerName(p, name)
            else
                set name = name + GetPlayerName(p) + "|r"
            endif
            set udg_playerorder[playerid] = boardrow+1
            call MultiboardSetItemWidthBJ(udg_multiboard, 1, udg_playerorder[playerid], 10)
            call MultiboardSetItemWidthBJ(udg_multiboard, 2, udg_playerorder[playerid], 3)
            call MultiboardSetItemValueBJ(udg_multiboard, 1, udg_playerorder[playerid], name)
            call MultiboardSetItemValueBJ(udg_multiboard, 2, udg_playerorder[playerid], I2S(udg_kills[playerid]))
            set boardrow = boardrow + 1
        endif
        set playerid = playerid + 1
    endloop
    call MultiboardMinimize(udg_multiboard, true)
    set p = null
    call DestroyTrigger(gg_trg_Create)
endfunction

//===========================================================================
function InitTrig_Create takes nothing returns nothing
    set gg_trg_Create = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Create, 10 )
    call TriggerAddAction( gg_trg_Create, function Trig_Create_Actions )
endfunction

 
function Trig_Kill_Increment_Actions takes nothing returns nothing
    local unit u = GetKillingUnit()
    local player p = GetOwningPlayer(u)
    local integer i = GetPlayerId(p)
    local integer row = udg_playerorder[i]
    if u == null or p == null or i > 9 then
        set p = null
        return
    endif
    set udg_kills[i] = udg_kills[i] + 1
    if udg_kills[i] == 100 then
        call AdjustPlayerStateBJ( 1, p, PLAYER_STATE_RESOURCE_LUMBER )
    elseif udg_kills[i] == 200 then
        call AdjustPlayerStateBJ( 2, p, PLAYER_STATE_RESOURCE_LUMBER )
        set udg_Chaos = udg_Chaos + 1
        call Check_Chaos()
    elseif udg_kills[i] == 300 then
        call AdjustPlayerStateBJ( 3, p, PLAYER_STATE_RESOURCE_LUMBER )
    elseif udg_kills[i] == 400 then
        call AdjustPlayerStateBJ( 4, p, PLAYER_STATE_RESOURCE_LUMBER )
        set udg_Chaos = udg_Chaos + 1
        call Check_Chaos()
    elseif udg_kills[i] == 500 then
        call AdjustPlayerStateBJ( 5, p, PLAYER_STATE_RESOURCE_LUMBER )
        set udg_vpts = udg_vpts + 10
    elseif udg_kills[i] == 600 then
        call AdjustPlayerStateBJ( 6, p, PLAYER_STATE_RESOURCE_LUMBER )
        set udg_Chaos = udg_Chaos + 1
        call Check_Chaos()
    elseif udg_kills[i] == 700 then
        call AdjustPlayerStateBJ( 7, p, PLAYER_STATE_RESOURCE_LUMBER )
    elseif udg_kills[i] == 800 then
        call AdjustPlayerStateBJ( 8, p, PLAYER_STATE_RESOURCE_LUMBER )
        set udg_Chaos = udg_Chaos + 1
        call Check_Chaos()
    elseif udg_kills[i] == 900 then
        call AdjustPlayerStateBJ( 9, p, PLAYER_STATE_RESOURCE_LUMBER )
    elseif udg_kills[i] == 1000 then
        call AdjustPlayerStateBJ( 10, p, PLAYER_STATE_RESOURCE_LUMBER )
        set udg_Chaos = udg_Chaos + 1
        call Check_Chaos()
        set udg_vpts = udg_vpts + 20
    endif
    call MultiboardSetItemValueBJ(udg_multiboard, 2, row, I2S(udg_kills[i]))
    set u = null
    set p = null
endfunction

//===========================================================================
function InitTrig_Kill_Increment takes nothing returns nothing
    set gg_trg_Kill_Increment = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Kill_Increment, Player(11), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Kill_Increment, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Kill_Increment, function Trig_Kill_Increment_Actions )
endfunction
 
function Trig_Camera_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    call SetCameraFieldForPlayer( p, CAMERA_FIELD_TARGET_DISTANCE, 2250, 1 )
    set p = null
endfunction

//===========================================================================
function InitTrig_Camera takes nothing returns nothing
    set gg_trg_Camera = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(0), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(1), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(2), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(3), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(4), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(5), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(6), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(7), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(8), "-z", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera, Player(9), "-z", true )
    call TriggerAddAction( gg_trg_Camera, function Trig_Camera_Actions )
endfunction

 
function Trig_Enable_Wayward_Purge_Actions takes nothing returns nothing
    local string s = "en"
    set udg_purge = not udg_purge
    if udg_purge == false then
        set s = "dis"
    endif
    call Message("Wayward purging has been " + s + "abled.", 5)
endfunction

//===========================================================================
function InitTrig_Enable_Wayward_Purge takes nothing returns nothing
    set gg_trg_Enable_Wayward_Purge = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(0), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(1), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(2), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(3), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(4), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(5), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(6), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(7), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(8), "-e", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Enable_Wayward_Purge, Player(9), "-e", true )
    call TriggerAddAction( gg_trg_Enable_Wayward_Purge, function Trig_Enable_Wayward_Purge_Actions )
endfunction

 
function Trig_No_Passwords_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local player l
    if IsTriggerEnabled(gg_trg_Secret_Hero_Command_1) then
        call DisableTrigger(gg_trg_Secret_Hero_Command_1)
        call DisableTrigger(gg_trg_Secret_Hero_Command_2)
        call DisableTrigger(gg_trg_Secret_Hero_Command_4)
        call DisableTrigger(gg_trg_Secret_Hero_Command_5)
        call SavePlayerHandle(udg_h, 'NPAS', 0, p)
        call Message("|cffff0000Passwords have been disabled.|r", 5)
    else
        set l = LoadPlayerHandle(udg_h, 'NPAS', 0)
        if p == l or GetPlayerSlotState(l) == PLAYER_SLOT_STATE_LEFT then
            call EnableTrigger(gg_trg_Secret_Hero_Command_1)
            call EnableTrigger(gg_trg_Secret_Hero_Command_2)
            call EnableTrigger(gg_trg_Secret_Hero_Command_4)
            call EnableTrigger(gg_trg_Secret_Hero_Command_5)
            call Message("|cffff0000Passwords have been enabled.|r", 5)
        else
            call Message("|cffff0000Only the player who disabled passwords can enable them.|r", 5)
        endif
    endif
    set l = null
    set p = null
endfunction

//===========================================================================
function InitTrig_No_Passwords takes nothing returns nothing
    set gg_trg_No_Passwords = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(0), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(1), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(2), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(3), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(4), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(5), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(6), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(7), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(8), "-p", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_No_Passwords, Player(9), "-p", true )
    call TriggerAddAction( gg_trg_No_Passwords, function Trig_No_Passwords_Actions )
endfunction

 
function Trig_Cleanup_Enemies_Actions takes nothing returns nothing
    local player p = Player(11)
    local group g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, p, Condition(function NullCondition))
    call GroupPointOrder(g, "patrol", GetRectCenterX(gg_rct_Main_Target), GetRectCenterY(gg_rct_Main_Target))
    call DestroyGroup(g)
    set g = null
    set p = null
endfunction

//===========================================================================
function InitTrig_Cleanup_Enemies takes nothing returns nothing
    set gg_trg_Cleanup_Enemies = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(0), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(1), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(2), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(3), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(4), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(5), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(6), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(7), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(8), "-c", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Cleanup_Enemies, Player(9), "-c", true )
    call TriggerAddAction( gg_trg_Cleanup_Enemies, function Trig_Cleanup_Enemies_Actions )
endfunction

 
function Trig_Free_Play_Next_Wave_Actions takes nothing returns nothing
    if (udg_mode == 2 or udg_mode == 4) and (LoadBoolean(udg_h, 'w', 0) == true) then
        call Next_Wave()
        call SaveBoolean(udg_h, 'w', 0, false)
        call TriggerSleepAction(15)
        call SaveBoolean(udg_h, 'w', 0, true)
    endif
endfunction

//===========================================================================
function InitTrig_Free_Play_Next_Wave takes nothing returns nothing
    set gg_trg_Free_Play_Next_Wave = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(0), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(1), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(2), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(3), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(4), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(5), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(6), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(7), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(8), "-w", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Free_Play_Next_Wave, Player(9), "-w", true )
    call TriggerAddAction( gg_trg_Free_Play_Next_Wave, function Trig_Free_Play_Next_Wave_Actions )
endfunction



 
function Trig_Secret_Hero_Command_1_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    call CreateFogModifierRectBJ( true, p, FOG_OF_WAR_VISIBLE, gg_rct_SecretHero1 )
    set udg_vpts = udg_vpts - 5
    set p = null
endfunction

//===========================================================================
function InitTrig_Secret_Hero_Command_1 takes nothing returns nothing
    set gg_trg_Secret_Hero_Command_1 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(0), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(1), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(2), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(3), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(4), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(5), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(6), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(7), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(8), "Divine Wrath", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_1, Player(9), "Divine Wrath", true )
    call TriggerAddAction( gg_trg_Secret_Hero_Command_1, function Trig_Secret_Hero_Command_1_Actions )
endfunction

 
function Trig_Secret_Hero_Command_2_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local rect r = gg_rct_SecretHero2
    call CreateFogModifierRectBJ( true, p, FOG_OF_WAR_VISIBLE, r )
    set udg_vpts = udg_vpts - 5
    set p = null
    set r = null
endfunction

//===========================================================================
function InitTrig_Secret_Hero_Command_2 takes nothing returns nothing
    set gg_trg_Secret_Hero_Command_2 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(0), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(1), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(2), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(3), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(4), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(5), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(6), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(7), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(8), "The Grave Beckons", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_2, Player(9), "The Grave Beckons", true )
    call TriggerAddAction( gg_trg_Secret_Hero_Command_2, function Trig_Secret_Hero_Command_2_Actions )
endfunction

 
function Trig_Secret_Hero_Command_4_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local rect r = gg_rct_SecretHero4
    call CreateFogModifierRectBJ( true, p, FOG_OF_WAR_VISIBLE, r )
    set udg_vpts = udg_vpts - 5
    set p = null
    set r = null
endfunction

//===========================================================================
function InitTrig_Secret_Hero_Command_4 takes nothing returns nothing
    set gg_trg_Secret_Hero_Command_4 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(0), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(1), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(2), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(3), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(4), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(5), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(6), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(7), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(8), "Age of Tranquility", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_4, Player(9), "Age of Tranquility", true )
    call TriggerAddAction( gg_trg_Secret_Hero_Command_4, function Trig_Secret_Hero_Command_4_Actions )
endfunction

 
function Trig_Secret_Hero_Command_5_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local rect r = gg_rct_SecretHero5
    call CreateFogModifierRectBJ( true, p, FOG_OF_WAR_VISIBLE, r )
    set p = null
    set r = null
endfunction

//===========================================================================
function InitTrig_Secret_Hero_Command_5 takes nothing returns nothing
    set gg_trg_Secret_Hero_Command_5 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(0), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(1), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(2), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(3), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(4), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(5), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(6), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(7), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(8), "Call of the Void", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Secret_Hero_Command_5, Player(9), "Call of the Void", true )
    call TriggerAddAction( gg_trg_Secret_Hero_Command_5, function Trig_Secret_Hero_Command_5_Actions )
endfunction

 
function Trig_Camera_Lock_Command_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer i = GetConvertedPlayerId(p)
    if udg_CameraLocked[i] then
        call ResetToGameCameraForPlayer(p, 0)
        call SetCameraFieldForPlayer(p, CAMERA_FIELD_TARGET_DISTANCE, 2250, 0)
        set udg_CameraLocked[i] = false
    else
        call SetCameraTargetControllerNoZForPlayer(p, udg_Hero[i], 0, 0, false)
        set udg_CameraLocked[i] = true
    endif
    set p = null
endfunction

//===========================================================================
function InitTrig_Camera_Lock_Command takes nothing returns nothing
    set gg_trg_Camera_Lock_Command = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(0), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(1), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(2), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(3), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(4), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(5), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(6), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(7), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(8), "-l", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Lock_Command, Player(9), "-l", true )
    call TriggerAddAction( gg_trg_Camera_Lock_Command, function Trig_Camera_Lock_Command_Actions )
endfunction

 
function Trig_Suicide_Command_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u = udg_Hero[GetConvertedPlayerId(p)]
    local rect r = gg_rct_Initial_Spawn
    local location l = GetRectCenter(r)
    call KillUnit( u )
    call ReviveHeroLoc( u, l, false )
    call PanCameraToTimedLocForPlayer( p, l, 1 )
    call SelectUnitForPlayerSingle( u, p )
    call DisplayTextToForce( bj_FORCE_ALL_PLAYERS, GetUnitName(u) + " has revived." )
    call SetUnitLifePercentBJ( u, 1 )
    call SetUnitManaPercentBJ( u, 0 )
    set u = null
    set p = null
    call RemoveLocation(l)
    set l = null
    set r = null
endfunction

//===========================================================================
function InitTrig_Suicide_Command takes nothing returns nothing
    set gg_trg_Suicide_Command = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(0), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(1), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(2), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(3), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(4), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(5), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(6), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(7), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(8), "-k", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Suicide_Command, Player(9), "-k", true )
    call TriggerAddAction( gg_trg_Suicide_Command, function Trig_Suicide_Command_Actions )
endfunction

 
function Trig_Clear_Hero_Area_Remove takes nothing returns nothing
    local unit u = GetEnumUnit()
    call RemoveUnit(u)
    set u = null
endfunction

function Trig_Clear_Hero_Area_Actions takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local group g = GetUnitsInRectAll(gg_rct_Entire_Hero_Selection_Area)
    if GetTriggerExecCount(t) > 1 then
        call ForGroupBJ( g, function Trig_Clear_Hero_Area_Remove )
    else
        call DisplayTextToForce( bj_FORCE_PLAYER[0], "TRIGSTR_5979" )
    endif
    set t = null
    call DestroyGroup(g)
    set g = null
endfunction

//===========================================================================
function InitTrig_Clear_Hero_Area takes nothing returns nothing
    set gg_trg_Clear_Hero_Area = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Hero_Area, Player(0), "-a", true )
    call TriggerAddAction( gg_trg_Clear_Hero_Area, function Trig_Clear_Hero_Area_Actions )
endfunction

 
function Trig_A_Actions takes nothing returns nothing
    call StartSound(gg_snd_58271D)
    call KillSoundWhenDone(gg_snd_58271D)
    set udg_vpts = udg_vpts + 1
endfunction

//===========================================================================
function InitTrig_A takes nothing returns nothing
    set gg_trg_A = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(0), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(1), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(2), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(3), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(4), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(5), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(6), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(7), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(8), "-omg", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_A, Player(9), "-omg", true )
    call TriggerAddAction( gg_trg_A, function Trig_A_Actions )
endfunction

 
function Trig_Destroy_MAG_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local item i = LoadItemHandle(udg_mag, GetPlayerId(p), 0)
    call RemoveItem(i)
    set p = null
    set i = null
endfunction

//===========================================================================
function InitTrig_Destroy_MAG takes nothing returns nothing
    local integer a = 0
    set gg_trg_Destroy_MAG = CreateTrigger(  )
    loop
        exitwhen a > 9
        call TriggerRegisterPlayerChatEvent( gg_trg_Destroy_MAG, Player(a), "-destroymag", true )
        set a = a + 1
    endloop
    call TriggerAddAction( gg_trg_Destroy_MAG, function Trig_Destroy_MAG_Actions )
endfunction

 
function Trig_Spawn_Actions takes nothing returns nothing
    local string array s
    set s[0] = "Battlefield"
    set s[1] = "Castle"
    set s[2] = "Western Lane"
    set s[3] = "Southwestern Lane"
    set s[4] = "Southern Lane"
    set udg_botspawn = udg_botspawn + 1
    if udg_botspawn > 4 then
        set udg_botspawn = 0
    endif
    call Message("Bot Spawn Point changed to the " + s[udg_botspawn] + ".", 5)
endfunction

//===========================================================================
function InitTrig_Spawn takes nothing returns nothing
    set gg_trg_Spawn = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(0), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(1), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(2), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(3), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(4), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(5), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(6), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(7), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(8), "-s", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Spawn, Player(9), "-s", true )
    call TriggerAddAction( gg_trg_Spawn, function Trig_Spawn_Actions )
endfunction

 
function Trig_Control_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    call Set_Computer_Controller(GetPlayerId(p))
    call Message("Player " + I2S(GetPlayerId(p)+1) + " has been given control of the bots.", 5)
    set p = null
endfunction

//===========================================================================
function InitTrig_Control takes nothing returns nothing
    set gg_trg_Control = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(0), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(1), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(2), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(3), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(4), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(5), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(6), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(7), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(8), "-b", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Control, Player(9), "-b", true )
    call TriggerAddAction( gg_trg_Control, function Trig_Control_Actions )
endfunction

 
function Trig_Define_Actions takes nothing returns nothing
    local string a = GetEventPlayerChatString()
    local integer id = S2I(SubString(a, 3, 4))-1
    local player p = Player(id)
    local string name = SubString(a, 5, StringLength(a))
    local group g = CreateGroup()
    local unit u
    local unit e
    local integer i = 0
    local integer l = 0
    local boolean b = false
    if id == 0 and SubString(a, 3, 5) == "10" then
        set id = 9
        set name = SubString(a, 6, StringLength(a))
        set p = Player(id)
    endif
    if id >= 0 and id < 10 then
        call GroupEnumUnitsInRect(g, gg_rct_Entire_Hero_Selection_Area, Condition(function NullCondition))
        set l = CountUnitsInGroup(g)
        loop
            exitwhen ((b == true) or (i > l))
            set u = FirstOfGroup(g)
            if GetUnitName(u) == name then
                set e = u
                set b = true
            endif
            call GroupRemoveUnit(g, u)
            set i = i + 1
        endloop
        if e == null then
            call Message("Could not find a hero class called: |cff00ffff" + name + "|r", 10)
        elseif GetPlayerController(p) == MAP_CONTROL_COMPUTER then
            set udg_LoadHero[id+1] = e
            call Message("Player " + I2S(id+1) + " will be |cff00ffff" + GetUnitName(udg_LoadHero[id+1]) + "|r.", 10)
        else
            call Message("The |cff00ff00-d|r command cannot be used for human players.", 10)
        endif
    else
        call Message("Player " + I2S(id+1) + " not found.", 10)
    endif
    call DestroyGroup(g)
    set g = null
    set u = null
    set e = null
    set p = null
endfunction

//===========================================================================
function InitTrig_Define takes nothing returns nothing
    set gg_trg_Define = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(0), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(1), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(2), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(3), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(4), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(5), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(6), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(7), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(8), "-d ", false)
    call TriggerRegisterPlayerChatEvent(gg_trg_Define, Player(9), "-d ", false)
    call TriggerAddAction( gg_trg_Define, function Trig_Define_Actions )
endfunction
function Trig_Attrition_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A07E'
endfunction

function Trig_Attrition_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local location l = GetUnitLoc(u)
    local group g = GetUnitsInRangeOfLocMatching(1000.00, l, Condition(function Enemy_Check))
    local unit e
    local integer level = GetUnitAbilityLevelSwapped('A07E', u)
    local texttag t = CreateTextTagUnitBJ( "–" + I2S(udg_ven), u, 0, 12, 100, 20, 100, 0 )
    call SetTextTagPermanentBJ( t, false )
    call SetTextTagFadepointBJ( t, 1 )
    call SetTextTagVelocityBJ( t, 64, 90 )
    call SetTextTagLifespanBJ( t, 2 )
    loop
        exitwhen CountUnitsInGroup(g) <= 0
        set e = FirstOfGroup(g)
        call UnitDamageTargetBJ( u, e, 0.75 * udg_ven * level, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL )
        call GroupRemoveUnit(g, e)
    endloop
    call SetUnitLifePercentBJ( u, GetUnitStatePercent(u, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) / 4 )
    set udg_ven = 0
    call RemoveLocation(l)
    set l = null
    set u = null
    set e = null
    call DestroyGroup(g)
    set g = null
endfunction

//===========================================================================
function InitTrig_Attrition takes nothing returns nothing
    set gg_trg_Attrition = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Attrition, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Attrition, Condition( function Trig_Attrition_Conditions ) )
    call TriggerAddAction( gg_trg_Attrition, function Trig_Attrition_Actions )
endfunction

 
function Trig_Backstab_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A07C' )
endfunction

function Trig_Backstab_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit e = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevelSwapped('A07C', u)
    local location l = GetSpellTargetLoc()
    local texttag t = CreateTextTagUnitBJ( "–" + I2S(udg_ven), u, 0, 12, 100, 20, 100, 0 )
    call SetTextTagPermanentBJ( t, false )
    call SetTextTagFadepointBJ( t, 1 )
    call SetTextTagVelocityBJ( t, 64, 90 )
    call SetTextTagLifespanBJ( t, 2 )
    set t = null
    call TriggerSleepAction(0.7)
    call UnitDamageTargetBJ( u, e, 1 * udg_ven * level, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL )
    call SetUnitPositionLoc( u, l )
    call RemoveLocation(l)
    set l = null
    set u = null
    set e = null
    set udg_ven = 0
endfunction

//===========================================================================
function InitTrig_Backstab takes nothing returns nothing
    set gg_trg_Backstab = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Backstab, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Backstab, Condition( function Trig_Backstab_Conditions ) )
    call TriggerAddAction( gg_trg_Backstab, function Trig_Backstab_Actions )
endfunction

 
function Trig_Bear_Attack_Bonus_Conditions takes nothing returns boolean
    local unit u = GetAttacker()
    local boolean b = (GetUnitTypeId(u) == 'n01S' or GetUnitTypeId(u) == 'n01R')
    set u = null
    return b
endfunction

function Bear_Attack_Bonus_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit a = GetAttacker()
    call UnitDamageTarget( a, u, GetHeroLevel(a) * 10, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS )
    set u = null
    set a = null
endfunction

//===========================================================================
function InitTrig_Bear_Attack_Bonus takes nothing returns nothing
    set gg_trg_Bear_Attack_Bonus = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Bear_Attack_Bonus, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Bear_Attack_Bonus, Condition( function Trig_Bear_Attack_Bonus_Conditions ) )
    call TriggerAddAction( gg_trg_Bear_Attack_Bonus, function Bear_Attack_Bonus_Actions )
endfunction
function Charge_Ability_Check takes nothing returns boolean
    return GetSpellAbilityId() == 'A07I'
endfunction

function Charge_Move takes unit u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location lu = GetUnitLoc(u)
    call SetUnitPositionLoc( t, PolarProjectionBJ( lu, DistanceBetweenPoints(lu, lt) - d, AngleBetweenPoints( lu, lt ) ) )
    call RemoveLocation(lt)
    call RemoveLocation(lu)
    set lt = null
    set lu = null
endfunction

function Charge_Move_2 takes unit u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location lu = GetUnitLoc(u)
    call SetUnitPositionLoc( t, PolarProjectionBJ( lu, DistanceBetweenPoints(lu, lt) + d, AngleBetweenPoints( lu, lt ) ) )
    call RemoveLocation(lt)
    call RemoveLocation(lu)
    set lt = null
    set lu = null
endfunction

function Charge_Pull takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = LoadUnitHandle(udg_h, GetHandleId(t), 0)
    local unit e = LoadUnitHandle(udg_h, GetHandleId(t), 1)
    local integer level = GetUnitAbilityLevel(u, 'A07I')
    local location lu = GetUnitLoc(u)
    local location le = GetUnitLoc(e)
    local group g
    local unit ge
    call SaveInteger(udg_h, GetHandleId(t), 2, LoadInteger(udg_h, GetHandleId(t), 2) + 1)
    if LoadInteger(udg_h, GetHandleId(t), 2) < 30 and DistanceBetweenPoints(lu, le) > 150 and GetUnitState(e, UNIT_STATE_LIFE) > 0.405 and GetUnitState(u, UNIT_STATE_LIFE) > 0.405 then
        call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", e, "origin"))
        call Charge_Move(e, u, 60)
        set g = GetUnitsInRangeOfLocMatching(170, lu, Condition(function Enemy_Check))
        loop
            exitwhen CountUnitsInGroup(g) <= 0
            set ge = FirstOfGroup(g)
            if ge == e then
                call GroupRemoveUnit(g, e)
                call UnitDamageTarget(u, ge, 5 * level, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_METAL_HEAVY_BASH)
                call Charge_Move_2(u, ge, 25)
            else
                call Charge_Move_2(u, ge, 50)
                call UnitDamageTarget(u, ge, 15 * level, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_METAL_HEAVY_BASH)
                call GroupRemoveUnit(g, ge)
            endif
        endloop
    else
        if GetUnitState(e, UNIT_STATE_LIFE) > 0.405 and GetUnitState(u, UNIT_STATE_LIFE) > 0.405 then
            call UnitDamageTargetBJ(u, e, 100 + 125 * (level - 1), ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)
        endif
        call PauseTimer(t)
        call DestroyTimer(t)
        call FlushChildHashtable(udg_h, GetHandleId(t))
        set t = null
        set u = null
        set e = null
    endif
    call RemoveLocation(lu)
    call RemoveLocation(le)
    set lu = null
    set le = null
    call DestroyGroup(g)
    set g = null
    set ge = null
    set t = null
endfunction

function Charge_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetTriggerUnit()
    local unit e = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(u, 'A07I')
    call SaveUnitHandle( udg_h, GetHandleId(t), 0, u )
    call SaveUnitHandle( udg_h, GetHandleId(t), 1, e )
    call SaveInteger( udg_h, GetHandleId(t), 2, 0)
    call TimerStart(t, 0.05, true, function Charge_Pull)
    set u = null
    set e = null
    set t = null
endfunction

function InitTrig_Charge takes nothing returns nothing
    set gg_trg_Charge = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Charge, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Charge, Condition( function Charge_Ability_Check ) )
    call TriggerAddAction( gg_trg_Charge, function Charge_Actions )
endfunction
function Trig_Consume_Blight_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A0DN' )
endfunction

function Trig_Consume_Blight_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    if IsPointBlighted(GetUnitX(u), GetUnitY(u)) == true then
        call SetUnitLifePercentBJ(u, GetUnitStatePercent(u, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) + 3.5 + 7.0 * GetUnitAbilityLevel(u, 'A0DN'))
    else
        call SetUnitLifePercentBJ(u, GetUnitStatePercent(u, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) + 3.5 * GetUnitAbilityLevel(u, 'A0DN'))
    endif
    set u = null
endfunction

//===========================================================================
function InitTrig_Consume_Blight takes nothing returns nothing
    set gg_trg_Consume_Blight = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Consume_Blight, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Consume_Blight, Condition( function Trig_Consume_Blight_Conditions ) )
    call TriggerAddAction( gg_trg_Consume_Blight, function Trig_Consume_Blight_Actions )
endfunction

 
function Trig_Conjure_Blight_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A0DM' )
endfunction

function Trig_Conjure_Blight_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    call SetBlight(p, GetSpellTargetX(), GetSpellTargetY(), 250, true)
    set p = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Conjure_Blight takes nothing returns nothing
    set gg_trg_Conjure_Blight = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Conjure_Blight, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Conjure_Blight, Condition( function Trig_Conjure_Blight_Conditions ) )
    call TriggerAddAction( gg_trg_Conjure_Blight, function Trig_Conjure_Blight_Actions )
endfunction

 
function Crimson_Ability_Check takes nothing returns boolean
    return GetSpellAbilityId() == 'A00Y'
endfunction

function Crimson_Move takes unit u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location lu = GetUnitLoc(u)
    call SetUnitPositionLoc( t, PolarProjectionBJ( lu, DistanceBetweenPoints(lu, lt) - d, AngleBetweenPoints( lu, lt ) ) )
    call RemoveLocation(lt)
    call RemoveLocation(lu)
    set lt = null
    set lu = null
endfunction

function Crimson_Move_2 takes unit u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location lu = GetUnitLoc(u)
    call SetUnitPositionLoc( t, PolarProjectionBJ( lu, DistanceBetweenPoints(lu, lt) + d, AngleBetweenPoints( lu, lt ) ) )
    call RemoveLocation(lt)
    call RemoveLocation(lu)
    set lt = null
    set lu = null
endfunction

function Crimson_Pull takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = LoadUnitHandle(udg_h, GetHandleId(t), 0)
    local unit e = LoadUnitHandle(udg_h, GetHandleId(t), 1)
    local integer level = GetUnitAbilityLevel(u, 'A00Y')
    local location lu = GetUnitLoc(u)
    local location le = GetUnitLoc(e)
    local group g
    local unit ge
    call SaveInteger(udg_h, GetHandleId(t), 2, LoadInteger(udg_h, GetHandleId(t), 2) + 1)
    if LoadInteger(udg_h, GetHandleId(t), 2) < 30 and DistanceBetweenPoints(lu, le) > 150 and GetUnitState(e, UNIT_STATE_LIFE) > 0.405 and GetUnitState(u, UNIT_STATE_LIFE) > 0.405 then
        set g = GetUnitsInRangeOfLocMatching(170, lu, Condition(function Enemy_Check))
        if GetRandomInt(0, 5) == 1 then
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", u, "origin"))
        endif
        call Crimson_Move(e, u, 60)
        loop
            exitwhen CountUnitsInGroup(g) <= 0
            set ge = FirstOfGroup(g)
            if ge == e then
                call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodFootman.mdl", e, "origin"))
                call GroupRemoveUnit(g, e)
            else
                call Crimson_Move_2(u, ge, 50)
                call UnitDamageTarget(u, ge, 200 * level, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_METAL_LIGHT_SLICE)
                call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodFootman.mdl", ge, "origin"))
                call GroupRemoveUnit(g, ge)
            endif
        endloop
    else
        if GetUnitState(e, UNIT_STATE_LIFE) > 0.405 and GetUnitState(u, UNIT_STATE_LIFE) > 0.405 then
            call UnitDamageTarget(u, e, LoadInteger(udg_h, GetHandleId(t), 2) * 20 + 500 * level, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_METAL_LIGHT_SLICE)
            call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodFootman.mdl", ge, "origin"))
        endif
        call SetUnitVertexColor(u, 255, 255, 255, 255)
        call PauseTimer(t)
        call DestroyTimer(t)
        call FlushChildHashtable(udg_h, GetHandleId(t))
        set t = null
        set u = null
        set e = null
    endif
    call RemoveLocation(lu)
    call RemoveLocation(le)
    set lu = null
    set le = null
    call DestroyGroup(g)
    set g = null
    set ge = null
    set t = null
endfunction

function Crimson_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetTriggerUnit()
    local unit e = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(u, 'A00Y')
    call SetUnitVertexColor(u, 255, 127, 127, 127)
    call SaveUnitHandle( udg_h, GetHandleId(t), 0, u )
    call SaveUnitHandle( udg_h, GetHandleId(t), 1, e )
    call TimerStart(t, 0.05, true, function Crimson_Pull)
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", u, "origin"))
    set t = null
    set u = null
    set e = null
endfunction

function InitTrig_Crimson takes nothing returns nothing
    set gg_trg_Crimson = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Crimson, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Crimson, Condition( function Crimson_Ability_Check ) )
    call TriggerAddAction( gg_trg_Crimson, function Crimson_Actions )
endfunction
function Crushing_Blade_Ability_Check takes nothing returns boolean
    return GetSpellAbilityId() == 'A054' or GetSpellAbilityId() == 'A0B0'
endfunction

function Crushing_Blade_Enemy_Check takes nothing returns boolean
    local unit u = GetFilterUnit()
    local player p = GetOwningPlayer(u)
    local player p11 = Player(11)
    local player pna = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local boolean b = IsUnitAliveBJ(u) and (p == p11 or p == pna)
    set u = null
    set p = null
    set p11 = null
    set pna = null
    return b
endfunction

function Crushing_Blade_Move takes unit u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location lu = GetUnitLoc(u)
    call SetUnitPositionLoc( t, PolarProjectionBJ( lu, d + DistanceBetweenPoints(lu, lt), AngleBetweenPoints( lu, lt ) ) )
    call RemoveLocation(lt)
    call RemoveLocation(lu)
    set lt = null
    set lu = null
endfunction

function Crushing_Blade_Knockback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer i = LoadInteger( udg_h, GetHandleId(t), 'i' )
    local unit u = LoadUnitHandle( udg_h, GetHandleId(t), 'u' )
    local location l = GetUnitLoc(u)
    local group g = GetUnitsInRangeOfLocMatching(400 + 25 * GetUnitAbilityLevel(u, 'A054'), l, Condition(function Crushing_Blade_Enemy_Check))
    local integer a = 1
    local integer aa = CountUnitsInGroup( g )
    local integer level = GetUnitAbilityLevel(u, 'A054')
    local unit e
    if level <= 0 then
        set level = GetUnitAbilityLevel(u, 'A0B0')
    endif
    if i < 15 then
        loop
            exitwhen a > aa
            set e = FirstOfGroup( g )
            call Crushing_Blade_Move( u, e, 30 )
            if i == 1 then
                call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", e, "origin"))
            endif
            call UnitDamageTarget( u, e, 11 + 11 * level, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_METAL_HEAVY_BASH )
            call GroupRemoveUnit( g, e )
            set a = a + 1
        endloop
        set i = i + 1
        call SaveInteger( udg_h, GetHandleId(t), 'i', i )
    else
        call FlushChildHashtable(udg_h, GetHandleId(t))
        call DestroyGroup(g)
        call PauseTimer(t)
        call DestroyTimer(t)
    endif
    call RemoveLocation(l)
    set l = null
    set e = null
    set g = null
    set t = null
    set u = null
endfunction

function Crushing_Blade_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetTriggerUnit()
    local integer i = 1
    call SaveUnitHandle( udg_h, GetHandleId(t), 'u', u )
    call SaveInteger( udg_h, GetHandleId(t), 'i', i )
    call TimerStart(t, 0.04, true, function Crushing_Blade_Knockback)
    set u = null
    set t = null
endfunction

function InitTrig_Crushing_Blade takes nothing returns nothing
    set gg_trg_Crushing_Blade = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Crushing_Blade, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Crushing_Blade, Condition( function Crushing_Blade_Ability_Check ) )
    call TriggerAddAction( gg_trg_Crushing_Blade, function Crushing_Blade_Actions )
endfunction
function Trig_Death_Nova_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A01K' )
endfunction

function Trig_Death_Nova_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call UnitDamageTargetBJ(u, u, -100 * GetUnitAbilityLevelSwapped('A01K', u), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNKNOWN)
    set u = null
endfunction

//===========================================================================
function InitTrig_Death_Nova takes nothing returns nothing
    set gg_trg_Death_Nova = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Death_Nova, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Death_Nova, Condition( function Trig_Death_Nova_Conditions ) )
    call TriggerAddAction( gg_trg_Death_Nova, function Trig_Death_Nova_Actions )
endfunction
 
function Demon_Boost_Ability_Check takes nothing returns boolean
    return GetSpellAbilityId() == 'A0E8'
endfunction

function Demon_Boost_Move takes unit u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location lu = GetUnitLoc(u)
    call SetUnitPositionLoc( t, PolarProjectionBJ( lu, DistanceBetweenPoints(lu, lt) - d, AngleBetweenPoints( lu, lt ) ) )
    call RemoveLocation(lt)
    call RemoveLocation(lu)
    set lt = null
    set lu = null
endfunction

function Demon_Boost_Move_2 takes unit u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location lu = GetUnitLoc(u)
    call SetUnitPositionLoc( t, PolarProjectionBJ( lu, DistanceBetweenPoints(lu, lt) + d, AngleBetweenPoints( lu, lt ) ) )
    call RemoveLocation(lt)
    call RemoveLocation(lu)
    set lt = null
    set lu = null
endfunction

function Demon_Boost_Pull takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = LoadUnitHandle(udg_h, GetHandleId(t), 0)
    local unit e = LoadUnitHandle(udg_h, GetHandleId(t), 1)
    local integer level = GetUnitAbilityLevel(u, 'A0E8')
    local group g
    local unit ge
    local location l = GetUnitLoc(u)
    local location le = GetUnitLoc(e)
    if GetRandomInt(0, 3) == 1 then
        call SetUnitAnimation(u, "attack")
    endif
    call SaveInteger(udg_h, GetHandleId(t), 2, LoadInteger(udg_h, GetHandleId(t), 2) + 1)
    if LoadInteger(udg_h, GetHandleId(t), 2) < 40 and GetUnitState(e, UNIT_STATE_LIFE) > 0.405 and GetUnitState(u, UNIT_STATE_LIFE) > 0.405 then
        set g = GetUnitsInRangeOfLocMatching(150, l, Condition(function Enemy_Check))
        if DistanceBetweenPoints(l, le) > 90 then
            call Demon_Boost_Move(e, u, 60)
        endif
        loop
            exitwhen CountUnitsInGroup(g) <= 0
            set ge = FirstOfGroup(g)
            call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodFootman.mdl", ge, "origin"))
            call UnitDamageTarget(u, ge, GetRandomInt(2, 8) * level, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_METAL_LIGHT_SLICE)
            call GroupRemoveUnit(g, ge)
            if ge != e and DistanceBetweenPoints(l, le) > 90 then
                call Demon_Boost_Move_2(u, ge, 76)
            endif
        endloop
    else
        call SetUnitTimeScale(u, 1)
        call SetUnitVertexColor(u, 255, 255, 255, 255)
        call PauseTimer(t)
        call DestroyTimer(t)
        call FlushChildHashtable(udg_h, GetHandleId(t))
        set t = null
        set u = null
        set e = null
    endif
    call RemoveLocation(l)
    set l = null
    call RemoveLocation(le)
    set le = null
    call DestroyGroup(g)
    set g = null
    set ge = null
    set t = null
endfunction

function Demon_Boost_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetTriggerUnit()
    local unit e = GetSpellTargetUnit()
    call SetUnitTimeScale(u, 15)
    call SetUnitVertexColor(u, 127, 127, 127, 127)
    call SaveUnitHandle(udg_h, GetHandleId(t), 0, u)
    call SaveUnitHandle(udg_h, GetHandleId(t), 1, e)
    call TimerStart(t, 0.05, true, function Demon_Boost_Pull)
    set t = null
    set u = null
    set e = null
endfunction

//===========================================================================
function InitTrig_Demon_Boost takes nothing returns nothing
    set gg_trg_Demon_Boost = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Demon_Boost, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Demon_Boost, Condition( function Demon_Boost_Ability_Check ) )
    call TriggerAddAction( gg_trg_Demon_Boost, function Demon_Boost_Actions )
endfunction
function Trig_Divine_Intervention_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A04K' )
endfunction

function Trig_Divine_Intervention_Actions takes nothing returns nothing
    local integer i = 1
    local unit u = GetTriggerUnit()
    local player p
    local player po
    local player pl = GetLocalPlayer()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    loop
        exitwhen i > 10
        set p = ConvertedPlayer(i)
        if udg_Hero[i] != null then
            if udg_Hero[i] != u and IsUnitAliveBJ(udg_Hero[i]) == false then
                call ReviveHero(udg_Hero[i], x, y, true)
                call SelectUnitForPlayerSingle(udg_Hero[i], p)
                set po = GetOwningPlayer(udg_Hero[i])
                if pl == po then
                    call PanCameraToTimed(x, y, 0)
                endif
                call SetUnitLifePercentBJ(udg_Hero[i], 100)
            elseif udg_Hero[i] != null and udg_Hero[i] == u then
                call SetUnitLifePercentBJ(udg_Hero[i], 100)
            endif
        endif
        set i = i + 1
    endloop
    set u = null
    set p = null
    set pl = null
    set po = null
endfunction

//===========================================================================
function InitTrig_Divine_Intervention takes nothing returns nothing
    set gg_trg_Divine_Intervention = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Divine_Intervention, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Divine_Intervention, Condition( function Trig_Divine_Intervention_Conditions ) )
    call TriggerAddAction( gg_trg_Divine_Intervention, function Trig_Divine_Intervention_Actions )
endfunction
function Trig_Earth_Nova_Conditions takes nothing returns boolean
    return (GetSpellAbilityId() == 'A006')
endfunction

function Trig_Earth_Nova_Actions takes nothing returns nothing
    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()
    local destructable d = CreateDestructable('LTrc', x, y, 270, 1, 0)
    set d = null
endfunction

//===========================================================================
function InitTrig_Earth_Nova takes nothing returns nothing
    set gg_trg_Earth_Nova = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Earth_Nova, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Earth_Nova, Condition( function Trig_Earth_Nova_Conditions ) )
    call TriggerAddAction( gg_trg_Earth_Nova, function Trig_Earth_Nova_Actions )
endfunction
 
function Trig_Eat_Tree_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A0BM' )
endfunction

function Trig_Eat_Tree_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer l = GetUnitAbilityLevelSwapped('A0BM', u)
    local real formula = GetUnitLifePercent(u) + 60 + 8 * l
    if (formula > 100) then
        set formula = 100
    endif
    if (udg_mgscale < 1.5) then
        set udg_mgscale = udg_mgscale + 0.25
    endif
    call SetUnitLifePercentBJ(u, formula)
    call SetUnitManaPercentBJ(u, 100)
    call SetUnitScale(u, udg_mgscale, 0, 0)
    if GetRandomInt(1, (6 - l)) == 1 then
        call SetHeroStr(u, GetHeroStr(u, false), true)
    endif
    set u = null
endfunction

//===========================================================================
function InitTrig_Eat_Tree takes nothing returns nothing
    set gg_trg_Eat_Tree = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Eat_Tree, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Eat_Tree, Condition( function Trig_Eat_Tree_Conditions ) )
    call TriggerAddAction( gg_trg_Eat_Tree, function Trig_Eat_Tree_Actions )
endfunction
function Fel_Grapple_Ability_Check takes nothing returns boolean
    return GetSpellAbilityId() == 'A055'
endfunction

function Fel_Grapple_Move takes unit u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location lu = GetUnitLoc(u)
    call SetUnitPositionLoc(t, PolarProjectionBJ(lu, DistanceBetweenPoints(lu, lt) - d, AngleBetweenPoints(lu, lt)))
    call RemoveLocation(lt)
    call RemoveLocation(lu)
    set lt = null
    set lu = null
endfunction

function Fel_Grapple_Pull takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = LoadUnitHandle(udg_h, GetHandleId(t), 'u')
    local unit e = LoadUnitHandle(udg_h, GetHandleId(t), 'e')
    local integer level = GetUnitAbilityLevel(u, 'A055')
    if GetUnitState(e, UNIT_STATE_LIFE) > .405 and GetUnitState(u, UNIT_STATE_LIFE) > .405 then
        if GetRandomInt(1, 10) == 5 then
            call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", e, "origin"))
        endif
        call Fel_Grapple_Move(u, e, 35)
        call UnitDamageTarget( u, e, 2 * level, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS )
    endif
    set t = null
    set u = null
    set e = null
endfunction

function Fel_Grapple_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetTriggerUnit()
    local unit e = GetSpellTargetUnit()
    call SetUnitVertexColor(e, 255, 255, 255, 127)
    call SaveUnitHandle(udg_h, GetHandleId(t), 'u', u)
    call SaveUnitHandle(udg_h, GetHandleId(t), 'e', e)
    call TimerStart(t, 0.04, true, function Fel_Grapple_Pull)
    call TriggerSleepAction(8)
    call FlushChildHashtable(udg_h, GetHandleId(t))
    call PauseTimer(t)
    call DestroyTimer(t)
    call SetUnitVertexColor(e, 255, 255, 255, 255)
    set t = null
    set u = null
    set e = null
endfunction

function InitTrig_Fel_Grapple takes nothing returns nothing
    set gg_trg_Fel_Grapple = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Fel_Grapple, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Fel_Grapple, Condition(function Fel_Grapple_Ability_Check))
    call TriggerAddAction(gg_trg_Fel_Grapple, function Fel_Grapple_Actions)
endfunction
function Trig_Forgotten_Power_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A06X' )
endfunction

function Trig_Forgotten_Power_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call SetUnitManaPercentBJ(u, 100)
    call UnitResetCooldown(u)
    set u = null
endfunction

//===========================================================================
function InitTrig_Forgotten_Power takes nothing returns nothing
    set gg_trg_Forgotten_Power = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Forgotten_Power, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Forgotten_Power, Condition( function Trig_Forgotten_Power_Conditions ) )
    call TriggerAddAction( gg_trg_Forgotten_Power, function Trig_Forgotten_Power_Actions )
endfunction


 
function Trig_Full_Moon_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A002' )
endfunction

function Trig_Full_Moon_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call SetUnitManaPercentBJ(u, 100)
    call SetUnitLifePercentBJ(u, 100)
    set u = null
endfunction

//===========================================================================
function InitTrig_Full_Moon takes nothing returns nothing
    set gg_trg_Full_Moon = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Full_Moon, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Full_Moon, Condition( function Trig_Full_Moon_Conditions ) )
    call TriggerAddAction( gg_trg_Full_Moon, function Trig_Full_Moon_Actions )
endfunction

 
function Trig_Ghost_Storm_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A02J'
endfunction

function Trig_Ghost_Storm_Actions takes nothing returns nothing
    local real x = GetSpellTargetX()
    local real y = GetSpellTargetY()
    local location l = GetSpellTargetLoc()
    local unit u = GetTriggerUnit()
    local unit e
    local player p = GetTriggerPlayer()
    local group g = GetUnitsInRangeOfLocMatching(512, l, Condition(function Enemy_Check))
    local group f = GetUnitsOfPlayerAndTypeId(p, 'o009')
    local integer count = CountLivingPlayerUnitsOfTypeId('o009', p)
    local integer level = GetUnitAbilityLevelSwapped('A02J', u)
    call GroupPointOrder(f, "clusterrockets", x, y)
    call TriggerSleepAction(1)
    loop
        exitwhen CountUnitsInGroup(g) <= 0
        set e = FirstOfGroup(g)     //count * 125 + level * 25
        call UnitDamageTargetBJ(u, e, count * 125 * level, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)
        call GroupRemoveUnit(g, e)
    endloop
    call RemoveLocation(l)
    set l = null
    set u = null
    set e = null
    set p = null
    call DestroyGroup(g)
    set g = null
    call DestroyGroup(f)
    set f = null
endfunction

//===========================================================================
function InitTrig_Ghost_Storm takes nothing returns nothing
    set gg_trg_Ghost_Storm = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ghost_Storm, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Ghost_Storm, Condition( function Trig_Ghost_Storm_Conditions ) )
    call TriggerAddAction( gg_trg_Ghost_Storm, function Trig_Ghost_Storm_Actions )
endfunction
 
function Trig_Golem_Control_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local boolean b = (GetUnitTypeId(u) == 'n028' or GetUnitTypeId(u) == 'n02A' or GetUnitTypeId(u) == 'n029')
    set u = null
    return b
endfunction

function Trig_Golem_Control_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call UnitApplyTimedLifeBJ( 50, 'BTLF', u )
    set u = null
endfunction

//===========================================================================
function InitTrig_Golem_Control takes nothing returns nothing
    set gg_trg_Golem_Control = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Golem_Control, GetPlayableMapRect() )
    call TriggerAddCondition( gg_trg_Golem_Control, Condition( function Trig_Golem_Control_Conditions ) )
    call TriggerAddAction( gg_trg_Golem_Control, function Trig_Golem_Control_Actions )
endfunction

 
function Trig_Tornado_Nerf_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local boolean b = (GetUnitTypeId(u) == 'ntor')
    set u = null
    return b
endfunction

function Trig_Tornado_Nerf_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    call UnitApplyTimedLifeBJ( 10, 'BTLF', u )
    set u = null
endfunction

//===========================================================================
function InitTrig_Tornado_Nerf takes nothing returns nothing
    set gg_trg_Tornado_Nerf = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Tornado_Nerf, GetPlayableMapRect() )
    call TriggerAddCondition( gg_trg_Tornado_Nerf, Condition( function Trig_Tornado_Nerf_Conditions ) )
    call TriggerAddAction( gg_trg_Tornado_Nerf, function Trig_Tornado_Nerf_Actions )
endfunction

 
function Trig_Hatsuendan_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A0C5'
endfunction

function Trig_Hatsuendan_Actions takes nothing returns nothing
    local unit t = GetTriggerUnit()
    local real x = GetUnitX(t)
    local real y = GetUnitY(t)
    local player p = GetTriggerPlayer()
    local unit u = CreateUnit(p, 'n02S', x, y, 270)
    call UnitApplyTimedLifeBJ( 8, 'BTLF', u )
    set u = null
    set t = null
    set p = null
endfunction

//===========================================================================
function InitTrig_Hatsuendan takes nothing returns nothing
    set gg_trg_Hatsuendan = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hatsuendan, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Hatsuendan, Condition( function Trig_Hatsuendan_Conditions ) )
    call TriggerAddAction( gg_trg_Hatsuendan, function Trig_Hatsuendan_Actions )
endfunction
 
function Trig_Headshot_Conditions takes nothing returns boolean
    return (GetSpellAbilityId() == 'A01D')
endfunction

function Trig_Headshot_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local texttag t = CreateTextTagUnitBJ("HEADSHOT!", u, 0, 14, 100, 0, 0, 10)
    call SetTextTagPermanentBJ(t, false)
    call SetTextTagFadepointBJ(t, 2)
    call SetTextTagVelocityBJ(t, 64, 90)
    call SetTextTagLifespanBJ(t, 3)
    set t = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Headshot takes nothing returns nothing
    set gg_trg_Headshot = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Headshot, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Headshot, Condition( function Trig_Headshot_Conditions ) )
    call TriggerAddAction( gg_trg_Headshot, function Trig_Headshot_Actions )
endfunction
function Trig_Howl_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A003'
endfunction

function Trig_Howl_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local location c = GetUnitLoc(u)
    local unit e
    local integer level = GetUnitAbilityLevel(u, 'A003')
    local group g = GetUnitsInRangeOfLocMatching(350 + 50 * level, c, Condition(function Enemy_Check))
    local integer a = 1
    local integer b = CountUnitsInGroup(g)
    loop
        exitwhen a > b
        set e = FirstOfGroup(g)
        if (GetTimeOfDay() >= 18) or (GetTimeOfDay() <= 6) then
            call SetUnitManaPercentBJ(e, 0)
        endif
        call GroupRemoveUnit(g, e)
        set a = a + 1
    endloop
    set u = null
    call RemoveLocation(c)
    set c = null
    set e = null
    call DestroyGroup(g)
    set g = null
endfunction

//===========================================================================
function InitTrig_Howl takes nothing returns nothing
    set gg_trg_Howl = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Howl, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Howl, Condition( function Trig_Howl_Conditions ) )
    call TriggerAddAction( gg_trg_Howl, function Trig_Howl_Actions )
endfunction
function Implode_Ability_Check takes nothing returns boolean
    return GetSpellAbilityId() == 'A057'
endfunction

function Implode_Move takes location u, unit t, real d returns nothing
    local location lt = GetUnitLoc(t)
    local location l = PolarProjectionBJ( u, DistanceBetweenPoints(u, lt) - d, AngleBetweenPoints( u, lt ) )
    call SetUnitPositionLoc( t, l )
    call RemoveLocation(lt)
    call RemoveLocation(l)
    set lt = null
    set l = null
endfunction

function Implode_Knockback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer i = LoadInteger( udg_h, GetHandleId(t), 'i' )
    local unit u = LoadUnitHandle( udg_h, GetHandleId(t), 'u' )
    local location c = LoadLocationHandle( udg_h, GetHandleId(t), 'c' )
    local group g = GetUnitsInRangeOfLocMatching(325 + 25 * GetUnitAbilityLevel(u, 'A057'), c, Condition(function Enemy_Check))
    local integer a = 1
    local integer aa = CountUnitsInGroup( g )
    local integer level = GetUnitAbilityLevel(u, 'A057')
    local unit e
    set i = i + 1
    call SaveInteger( udg_h, GetHandleId(t), 'i', i )
    if (i < 20) and (i > 0) then
        loop
            exitwhen a > aa
            set e = FirstOfGroup( g )
            call Implode_Move( c, e, 60 )
            if i == 1 then
                call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl", e, "origin"))
            endif
            call UnitDamageTarget( u, e, level, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_METAL_HEAVY_BASH )
            call GroupRemoveUnit( g, e )