• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Little triggers

Level 17
Joined
Nov 13, 2006
Messages
1,814

JASS:
function Trig_Periodic_camera_lock_Actions takes nothing returns nothing
    local integer i = 1
    local integer pl
    loop
        exitwhen i > udg_Cam_Index
        set pl = udg_Cam_Pl[i]
        if udg_Camera_Lock[pl] > 0 then
            if (GetLocalPlayer() == Player(pl - 1)) then
                call CameraSetupApplyForceDuration(udg_Cam2, true, 0.00)
                call CameraSetupApplyForceDuration(udg_Cam1, true, 1.00)
            endif
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Periodic_camera_lock takes nothing returns nothing
    set gg_trg_Periodic_camera_lock = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Periodic_camera_lock, 0.03 )
    call TriggerAddAction( gg_trg_Periodic_camera_lock, function Trig_Periodic_camera_lock_Actions )
endfunction



JASS:
function Unit_Use_Item takes nothing returns boolean
    local integer pl = GetPlayerId(GetTriggerPlayer()) + 1
    local item itm1 = GetManipulatedItem()
    local integer i = GetHandleId(itm1)
    local integer ilv = GetItemLevel(itm1)
    local item itm2
    local integer c
    local integer it
    local destructable d
    local unit u = GetTriggerUnit()
    if ilv > 1901 and ilv < 1906 then
        set it = LoadInteger(udg_CItem_Table, i, 2)
        set c = LoadInteger(udg_CItem_Table, i, 3)
        set c = LoadInteger(udg_CItem_Table, i, c)
        if GetHeroLevel(u) >= LoadInteger(udg_CItem_Table, i, 8) then
            call DestroyEffect(AddSpecialEffectTarget(EFFECT(LoadInteger(udg_CItem_Table, i, 19)), u, "chest"))
            if it == 1 then
                call SetWidgetLife(u, GetWidgetLife(u) + c)
            elseif it == 2 then
                call SetUnitState(u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MANA) + c)
            elseif it == 3 then
                call AddOT (u, u, - 1, R2I(c / 30.00), 30)
            elseif it == 4 then
                call AddOT (u, u, - 2, R2I(c / 30.00), 30)
            endif
            call FlushChildHashtable(udg_CItem_Table, i)
        else
            call DisplayTextToPlayer(Player(pl - 1), 0, 0, "|cffff3333Your level is too low for this potion, you get back the potion!|r")
            set ilv = CreatePotion(it, GetUnitX(u), GetUnitY(u), LoadInteger(udg_CItem_Table, i, 8), c, LoadInteger(udg_CItem_Table, i, c), LoadInteger(udg_CItem_Table, i, 5), LoadInteger(udg_CItem_Table, i, 19))
            call SaveInteger(udg_CItem_Table, ilv, 12, LoadInteger(udg_CItem_Table, i, 12))
            call FlushChildHashtable(udg_CItem_Table, i)
            set itm2 = LoadItemHandle(udg_CItem_Table, ilv, 100)
            if udg_Camera_Lock[pl] > 0 then
                call AddItem2HeroExt (GetUnitUserData(u), itm2, false)
            else
                set i = GetUnitUserData(u)
                set udg_Stop_Stack[i] = true
                call UnitAddItem(u, itm2)
                set udg_Stop_Stack[i] = false
            endif
            set itm2 = null
        endif
    elseif ilv == BAG_LEVEL() then
        call DisplayTextToPlayer(Player(pl - 1), 0, 0, "|cffffff00You must open from inventory|r")
        set udg_Inv_Bag[pl] = i
        set udg_Inv_Unit[pl] = GetUnitUserData(u)
        set c = GetUnitUserData(u)
        if udg_Inv_Unit[pl] == 0 or udg_Inv_Unit[pl] == c then
            set udg_Inv_Bag[pl] = i
            set udg_Inv_Unit[pl] = c
            if udg_Camera_Lock[pl] > 0 then
                call WindowTransition(pl, udg_Camera_Lock[pl], 3)
            else
                set udg_Inv_Prev[pl] = 1
                call EnableCamLock(pl, 3)
            endif
        endif
    elseif ilv == BOX_LEVEL() then
        set c = GetRandomInt(0, 999)
        set itm2 = null
        if c < 1 then
            set c = GenerateEQ ( - 1, - 1, 6, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), false, - 1)
            set itm2 = LoadItemHandle(udg_CItem_Table, c, 100)
        elseif c < 10 then
            set c = GenerateEQ ( - 1, - 1, 5, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), false, - 1)
            set itm2 = LoadItemHandle(udg_CItem_Table, c, 100)
        elseif c < 30 then
            set c = GenerateEQ ( - 1, - 1, 4, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), false, - 1)
            set itm2 = LoadItemHandle(udg_CItem_Table, c, 100)
        elseif c < 80 then
            set c = GenerateEQ ( - 1, - 1, 3, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), false, - 1)
            set itm2 = LoadItemHandle(udg_CItem_Table, c, 100)
        elseif c < 160 then
            set c = CreatePotion(1, GetUnitX(u), GetUnitY(u), 0, 26, GetHeroLevel(u) * 5 + 50, 0, 26)
            set itm2 = LoadItemHandle(udg_CItem_Table, c, 100)
        elseif c < 220 then
            set c = CreatePotion(2, GetUnitX(u), GetUnitY(u), 0, 30, GetHeroLevel(u) * 5 + 50, 0, 30)
            set itm2 = LoadItemHandle(udg_CItem_Table, c, 100)
        elseif c < 250 then
            set c = CreatePotion(3, GetUnitX(u), GetUnitY(u), 0, 26, (GetHeroLevel(u) - 1) * 20 + 100, 0, 26)
            set itm2 = LoadItemHandle(udg_CItem_Table, c, 100)
        elseif c < 280 then
            set c = CreatePotion(3, GetUnitX(u), GetUnitY(u), 0, 30, (GetHeroLevel(u) - 1) * 20 + 100, 0, 30)
            set itm2 = LoadItemHandle(udg_CItem_Table, c, 100)
        elseif c < 350 then
            set itm2 = CreateItem('gold', GetUnitX(u), GetUnitY(u))
            call SetItemUserData(itm2, GetRandomInt(GetHeroLevel(u) * 2 + 10, GetHeroLevel(u) * 5 + 17))
            set c = - 1
        
        endif
        if itm2 != null then
            if udg_Camera_Lock[pl] > 0 and c != - 1 then
                call AddItem2HeroExt (GetUnitUserData(u), itm2, false)
            else
                call UnitAddItem(u, itm2)
            endif
            if GetItemTypeId(itm2) != 'gold' then
                call DisplayTextToPlayer(Player(pl - 1), 0, 0, "|cffffffaaAcquired|r " + GetFullItemName(itm2, true) + "|r")
            endif
            set itm2 = null
        else
            set c = GetRandomInt(0, 3)
            if c == 0 then
                call DisplayTextToPlayer(Player(pl - 1), 0, 0, "|cffff0000Bad luck|r")
            elseif c == 1 then
                call DisplayTextToPlayer(Player(pl - 1), 0, 0, "|cffff0000Better luck next time|r")
            elseif c == 2 then
                call DisplayTextToPlayer(Player(pl - 1), 0, 0, "|cffff0000Empty|r")
            elseif c == 3 then
                call DisplayTextToPlayer(Player(pl - 1), 0, 0, "|cffff0000Try again next time|r")
            endif
        endif
        call RemoveItem(itm1)
    endif
   
    if udg_Camera_Lock[GetPlayerId(GetTriggerPlayer()) + 1] == 1 then
        set i = 0
        set c = GetItemCharges(itm1)
        call TriggerSleepAction(0.27)
        if c == 0 then
            loop
                exitwhen i > 5
                set itm2 = UnitItemInSlot(GetTriggerUnit(), i)
                if itm2 == null then
                    set d = LoadDestructableHandle(udg_FSS, 2409 + pl, 200 + i)
                    if d != null then
                        call RemoveDestructable(d)
                    endif
                endif
                set i = i + 1
            endloop
        endif

        call SetChargesText(pl)

        set itm2 = null
        set d = null
    endif
    set itm1 = null
    set u = null
    return false
endfunction

//===========================================================================
function InitTrig_Unit_Use_Item takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_USE_ITEM, null)
        set i = i + 1
        exitwhen i == 15
    endloop
    call TriggerAddCondition( t, Condition( function Unit_Use_Item ) )
    set t = null
endfunction



JASS:
function Trig_InventoryItemAction_Conditions takes nothing returns boolean
    return udg_Camera_Lock[GetPlayerId(GetTriggerPlayer())+1] == 1 and GetOrderTargetItem() != null and UnitHasItem(GetTriggerUnit(), GetOrderTargetItem())
endfunction

function Trig_InventoryItemAction_Actions takes nothing returns nothing
    local integer pl = GetPlayerId(GetTriggerPlayer()) + 1
    local integer i = 200
    local destructable d
    local real x
    local real y
    local integer ilv
    local integer dt
    local item itm
    local unit u = GetTriggerUnit()
    call TriggerSleepAction(0.27)

    loop
        exitwhen i > 205
        set itm = UnitItemInSlot(u, i - 200)
        set d = LoadDestructableHandle(udg_FSS, 2409 + pl, i)
        if d != null then
            call RemoveDestructable(d)
        endif
        if itm != null then
            set ilv = GetItemLevel(itm)
            set dt = LoadInteger(udg_FSS, 600, GetItemTypeId(itm))
            set x = LoadReal(udg_FSS, i, 1)
            set y = LoadReal(udg_FSS, i, 2)
            if dt > 0 then
                set d = CreateDestructableZ(dt, x, y, 5, 0, 0.6, 0)
                call SaveDestructableHandle(udg_FSS, 2409 + pl, i, d)
                call ShowDestructable(d, false)
                if GetLocalPlayer() == Player(pl - 1) then
                    call ShowDestructable(d, true)
                endif
            endif
        endif
        set i = i + 1
    endloop
    call SetChargesText(pl)
    set itm = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Inventory_Item_Action takes nothing returns nothing
    set gg_trg_Inventory_Item_Action = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Inventory_Item_Action, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddCondition( gg_trg_Inventory_Item_Action, Condition( function Trig_InventoryItemAction_Conditions ) )
    call TriggerAddAction( gg_trg_Inventory_Item_Action, function Trig_InventoryItemAction_Actions )
endfunction



JASS:
function Trig_Ability_Preload_Actions takes nothing returns nothing
    local integer i = 1
    local integer a
    local unit u
    set udg_Abilities[0] = 'A003'
    set udg_Abilities[1] = 'A004'
    set udg_Abilities[2] = 'A00C'
    set udg_Abilities[3] = 'A00G'
    set udg_Abilities[4] = 'A00H'
    set udg_Abilities[5] = 'A00B'
    set udg_Abilities[6] = 'A00D'
    set udg_Abilities[7] = 'A00E'
    set udg_Abilities[8] = 'A001'
    set udg_Abilities[9] = 'A005'
    set udg_Abilities[10] = 'A006'
    set udg_Abilities[11] = 'A002'
    set udg_Abilities[12] = 'A007'
    set udg_Abilities[13] = 'A008'
    set udg_Abilities[14] = 'A009'
    set udg_Abilities[15] = 'A00F'
    set udg_Abilities[16] = 'A00J'
    set udg_Abilities[17] = 'A00K'
    set udg_Abilities[18] = 'A00L'
    set udg_Abilities[19] = 'A00M'
    set udg_Abilities[20] = 'A00N'
    set udg_Abilities[21] = 'A00O'
    set udg_Abilities[22] = 'A00P'
    set udg_Abilities[23] = 'A00Q'
    set udg_Abilities[24] = 'A00R'
    set udg_Abilities[25] = 'A00S'
    set udg_Abilities[26] = 'A00T'
    set udg_Abilities[27] = 'A013'
    set udg_Abilities[28] = 'A00X'
    set udg_Abilities[39] = 'A00Y'
    set udg_Abilities[30] = 'A00Z'
    set udg_Abilities[31] = 'A010'
    set udg_Abilities[32] = 'A011'
    set udg_Abilities[33] = 'A012'
    set udg_Abilities[34] = 'A00U'
    set udg_Abilities[35] = 'A00V'
    set udg_Abilities[36] = 'A014'
    set udg_Abilities[37] = 'A015'
    set udg_Abilities[38] = 'A016'
    set udg_Abilities[39] = 'A00W'
    set udg_Abilities[40] = 'A00I'


    loop
        exitwhen i > 12
        if ( GetPlayerController(Player(i - 1)) == MAP_CONTROL_USER ) then
            set u = CreateUnit(Player(i - 1), 'H000', GetStartLocationX(i - 1), GetStartLocationY(i - 1), bj_UNIT_FACING )
            set a = 1
            loop
                exitwhen udg_Abilities[a] == 0
                call UnitAddAbility( u, udg_Abilities[a])
                call UnitRemoveAbility( u, udg_Abilities[a])
                set a = a + 1
            endloop
            call RemoveUnit(u)
        endif
        set i = i + 1
    endloop
    set u = null
    call DisableTrigger( GetTriggeringTrigger() )
endfunction

//===========================================================================
function InitTrig_Ability_Preload takes nothing returns nothing
    set gg_trg_Ability_Preload = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Ability_Preload, function Trig_Ability_Preload_Actions )
endfunction



  • Init hashtables and variables
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Difficulty = 1
      • Player - Turn Gives bounty Off for Neutral Hostile
      • Set DummyVillager = Dummy Villager (Male 2)
      • -------- Border destructibles: L=left,U=up,R=right,D=down, LU = left + up corner etc --------
      • Set Borders[0] = CustomWindow (Corner - LU)
      • Set Borders[1] = CustomWindow (Corner - LD)
      • Set Borders[2] = CustomWindow (Corner - RU)
      • Set Borders[3] = CustomWindow (Corner - RD)
      • Set Borders[4] = CustomWindow (Border - U)
      • Set Borders[5] = CustomWindow (Border - D)
      • Set Borders[6] = CustomWindow (Border - L)
      • Set Borders[7] = CustomWindow (Border - R)
      • Set Icons[0] = CustomWindow (Icon - Empty slot)
      • Set Icons[1] = CustomWindow (Icon - Helm Slot)
      • Set Icons[2] = CustomWindow (Icon - Armor Slot)
      • Set Icons[3] = CustomWindow (Icon - Weapon Slot)
      • Set Icons[4] = CustomWindow (Icon - Boot Slot)
      • Set Icons[5] = CustomWindow (Icon - Shield Slot)
      • Set Icons[6] = CustomWindow (Icon - Amulet Slot)
      • Set Icons[7] = CustomWindow (Icon - Ring Slot)
      • Set Icons[8] = CustomWindow (Icon - Ring Slot)
      • Set Icons[9] = CustomWindow (Icon - Wings Slot)
      • Set Icons[10] = CustomWindow (Icon - Tome Slot)
      • Set Icons[11] = CustomWindow (Icon - Socketing Gem)
      • Set Icons[20] = CustomWindow (Icon - Drop)
      • Set Icons[21] = CustomWindow (Icon - Repair)
      • Set Icons[22] = CustomWindow (Icon - Repair)
      • Set Icons[23] = CustomWindow (Icon - Exit)
      • Set Icons[24] = CustomWindow (Selector)
      • Set Icons[25] = CustomWindow (Icon - Trade)
      • Set Icons[26] = CustomWindow (Icon - RESTAT)
      • Set Icons[27] = CustomWindow (Icon - STR)
      • Set Icons[28] = CustomWindow (Icon - AGI)
      • Set Icons[29] = CustomWindow (Icon - INT)
      • Set Icons[30] = CustomWindow (Icon - Trade Ok)
      • Set Icons[31] = CustomWindow (Icon - Gold)
      • Set Icons[32] = CustomWindow (Icon - Box)
      • Hashtable - Create a hashtable
      • Set FSS = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set Stat_Table = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set CItem_Table = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set Shop_Table = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set Drop_Table = (Last created hashtable)
      • Trigger - Turn off (This trigger)



JASS:
function Unit_Drop_Item takes nothing returns boolean
       call AddItemRot (GetManipulatedItem(), 0)
    return false
endfunction

//===========================================================================
function InitTrig_Unit_Drop_Item takes nothing returns nothing
    local trigger t = CreateTrigger() 
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DROP_ITEM, null)
        call TriggerAddAction( t, function Unit_Drop_Item )
        set i = i + 1
        exitwhen i == 15
    endloop
    set t = null
endfunction



JASS:
function Trig_ESC_destroy_MB_Actions takes nothing returns nothing
    local integer pl = GetPlayerId(GetTriggerPlayer()) + 1
    if udg_Camera_Lock[pl] > 0 then
        if udg_Inv_Prev[pl] == 0 then
            if udg_Camera_Lock[pl] > 0 then
                call WindowTransition (pl, udg_Camera_Lock[pl], 0)
            endif
        elseif udg_Inv_Prev[pl] != udg_Camera_Lock[pl] then
            call WindowTransition(pl, udg_Camera_Lock[pl], udg_Inv_Prev[pl])
        else
            call WindowTransition (pl, udg_Camera_Lock[pl], 0)
        endif
    else
//nothing
    endif

    if udg_Mb_Type[pl] > 0 then
        call DestroyMultiboard(udg_Mb_Table[pl])
        set udg_Mb_Table[pl] = null
        set udg_Mb_Type[pl] = 0
    elseif udg_Camera_Lock[pl] == 0 then
        set udg_Mb_Table[pl] = CreateMultiboard()
        set udg_Mb_Type[pl] = 3
        call MultiboardSetRowCount(udg_Mb_Table[pl], 0)
        call MultiboardSetColumnCount(udg_Mb_Table[pl], 0)
        call MultiboardSetTitleText(udg_Mb_Table[pl], "Time board")
        call MultiboardSetTitleTextColor(udg_Mb_Table[pl], 100, 100, 250, 255)
        call MultiboardMinimize(udg_Mb_Table[pl], false)
        call MultiboardDisplay( udg_Mb_Table[pl], false )
        if GetLocalPlayer() == Player(pl - 1) then
            call MultiboardDisplay( udg_Mb_Table[pl], true )
        endif
    endif

endfunction

//===========================================================================
function InitTrig_ESC_close_window_and_destroy_MB takes nothing returns nothing
    set gg_trg_ESC_close_window_and_destroy_MB = CreateTrigger( )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(0) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(1) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(2) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(3) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(4) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(5) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(6) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(7) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(8) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(9) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(10) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(11) )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_ESC_close_window_and_destroy_MB, Player(12) )
    call TriggerAddAction( gg_trg_ESC_close_window_and_destroy_MB, function Trig_ESC_destroy_MB_Actions )
endfunction


JASS:
function HarvestFT takes unit u returns nothing
    local integer cv = GetUnitUserData(u)
    local texttag tt = null
    local integer t = R2I(LoadInteger(udg_Stat_Table, 8981, cv) * 100 / LoadInteger(udg_Stat_Table, 8982, cv))
    local real x = LoadReal(udg_Stat_Table, 8985, cv) - 8
    local real y = LoadReal(udg_Stat_Table, 8986, cv)

    if t > 9 then
        set x = x - 8
    endif
    call DestroyTextTag (LoadTextTagHandle(udg_Stat_Table, 8984, cv))
    call SaveTextTagHandle(udg_Stat_Table, 8984, cv, tt)
    if LoadInteger(udg_Stat_Table, 8980, cv) == 1 then
        if GetLocalPlayer() == GetOwningPlayer(u) then
            set tt = CreateTextTag( )
            call SetTextTagText( tt, I2S(t) + "%", 1 * 0.023 )
            call SetTextTagPos( tt, x, y, 100.00 )
            call SetTextTagColor( tt, 255, 255, 0, 100 )
            call SetTextTagPermanent( tt, true )
        endif
        call SaveTextTagHandle(udg_Stat_Table, 8984, cv, tt)
    endif
    set tt = null
endfunction

function Trig_Start_Harvest_Actions takes nothing returns nothing
    local integer ilv
    local item itm = GetOrderTargetItem()
    local unit u = GetOrderedUnit()
    local unit ut = GetOrderTargetUnit()
    local integer cv = GetUnitUserData(u)
    local integer i
    local integer n
    local integer pl
    local real minRange = MIN_RANGE()
    local real r
    if GetPlayerController(GetTriggerPlayer()) == MAP_CONTROL_USER then
        set pl = GetPlayerId(GetOwningPlayer(u)) + 1
        if itm != null then
           set ilv = GetItemLevel(itm)
            set r = (GetUnitX(u)-GetItemX(itm))*(GetUnitX(u)-GetItemX(itm))+(GetUnitY(u)-GetItemY(itm))*(GetUnitY(u)-GetItemY(itm))
            if  r < minRange then
               if (itm != udg_Item_Last[pl] and udg_Item_Last[pl] != null) then
                set r = GetUnitFacing(u)
                call IssuePointOrder (u, "move", GetUnitX(u), GetUnitY(u))
                call SetUnitFacing(u, r)
               endif
            endif

            if itm != udg_Item_Last[pl] then
                call Mb_Item_ToolTip (itm, cv, 0, 0)
            endif

            if (itm == udg_Item_Last[pl] and udg_Item_Last[pl] != null) or (ilv > 1200 and ilv < 1203) or GetItemTypeId(itm) == 'gold' then
                if ilv > 1200 and ilv < 1203 and GetItemUserData(itm) == 0 then
                    call IssueImmediateOrder( u, "stop" )
                    if GetIssuedOrderId() == OrderId("smart") then
                        set i = LoadInteger(udg_Stat_Table, 8989, GetHandleId(itm))
                        if LoadItemHandle(udg_Stat_Table, 8983, cv) != null then
                            if cv == i then
                                call SaveInteger(udg_Stat_Table, 8989, GetHandleId(LoadItemHandle(udg_Stat_Table, 8983, cv)), 0)
                                set i = 0
                            endif
                            call DestroyTextTag(LoadTextTagHandle(udg_Stat_Table, 9984, cv))
                            call SaveTextTagHandle(udg_Stat_Table, 8984, cv, null)
                            call SaveItemHandle(udg_Stat_Table, 8983, cv, null)
                        endif
                        if LoadInteger(udg_Stat_Table, 8987, cv) != 0 or LoadInteger(udg_Stat_Table, 8980, cv) == 1 then
                            call SaveInteger(udg_Stat_Table, 8980, cv, 0)
                            call SaveInteger(udg_Stat_Table, 8981, cv, -1)
                            call SaveInteger(udg_Stat_Table, 8982, cv, 0)
                            call SaveReal(udg_Stat_Table, 8985, cv, 0)
                            call SaveReal(udg_Stat_Table, 8986, cv, 0)
                            if LoadInteger(udg_Stat_Table, 8987, cv) != 0 then
                                set udg_H_U[LoadInteger(udg_Stat_Table, 8987, cv)] = udg_H_U[udg_H_I]
                                call SaveInteger(udg_Stat_Table, 8987, cv, 0)
                                set udg_H_I = udg_H_I - 1
                            endif
                        endif
                        if i == 0 then
                            set udg_H_I = udg_H_I + 1
                            set udg_H_U[udg_H_I] = u
                            if ilv == 1201 then
                                set n = 80 - R2I((GetCraftLv(LoadInteger(udg_Stat_Table, 27000 + cv, 1), true) + GetCraftLv(LoadInteger(udg_Stat_Table, 27000 + cv, 2), true) + GetCraftLv(LoadInteger(udg_Stat_Table, 27000 + cv, 3), true)) / 3.00 * 4)
                            else
                                set n = 60 - (GetCraftLv(LoadInteger(udg_Stat_Table, 27000 + cv, 4), true) * 4)
                            endif

                            call SaveInteger(udg_Stat_Table, 8980, cv, 1)
                            call SaveInteger(udg_Stat_Table, 8981, cv, - 1)
                            call SaveInteger(udg_Stat_Table, 8982, cv, n)
                            call SaveItemHandle(udg_Stat_Table, 8983, cv, itm)
                            call SaveTextTagHandle(udg_Stat_Table, 8984, cv, null)
                            call SaveReal(udg_Stat_Table, 8985, cv, GetItemX(itm))
                            call SaveReal(udg_Stat_Table, 8986, cv, GetItemY(itm))
                            call SaveInteger(udg_Stat_Table, 8987, cv, udg_H_I)
                            call SaveInteger(udg_Stat_Table, 8989, GetHandleId(itm), cv)
                            call IssuePointOrder (u, "unloadall", GetItemX(itm), GetItemY(itm))
                            if udg_H_I == 1 then
                                call EnableTrigger( gg_trg_Harvester_Timer )
                            endif
                        else
                            call IssuePointOrder (u, "move", GetItemX(itm), GetItemY(itm))
                        endif
                    endif
                endif
            endif
            set udg_Item_Last[pl] = itm
        else
            set udg_Item_Last[pl] = null
            if ut != null then
               if not IsUnitType(ut, UNIT_TYPE_STRUCTURE) and LoadBoolean(udg_FSS, 551, 100 + pl) then
                if GetUnitTypeId(ut) == 'h004' and IsUnitType(u, UNIT_TYPE_HERO) then
                    //call IssueImmediateOrder( u, "stop" )
                    //call IssueTargetOrder( u, "repair", ut )
                elseif GetOwningPlayer(u) != GetOwningPlayer(ut) then
                    if udg_Unit_Last[pl] != ut then
                       if udg_Mb_Type[pl] == 0 then
                         call scaning (u, ut, GetTriggerPlayer())
                         set udg_Scan_Player[pl] = 1
                         set udg_Scan_Unit[pl] = u
                         set udg_Scan_Target[pl] = ut
                       else
                         call DestroyMultiboard(udg_Mb_Table[pl])
                         set udg_Mb_Type[pl] = 0
                         call scaning (u, ut, GetTriggerPlayer())
                         set udg_Scan_Player[pl] = 1
                         set udg_Scan_Unit[pl] = u
                         set udg_Scan_Target[pl] = ut
                       endif
                       set udg_Unit_Last[pl] = ut
                       set r = GetUnitFacing(u)
                       if IsUnitType(u, UNIT_TYPE_RANGED_ATTACKER) then
                         call IssuePointOrder (u, "move", GetUnitX(u), GetUnitY(u))
                         call SetUnitFacing(u, r)
                       endif
                    endif
                endif
               endif
            else
              set udg_Unit_Last[pl] = null
            endif

        endif
    endif
    set itm = null
    set u = null
    set ut = null
endfunction

//===========================================================================
function InitTrig_Start_Harvest_and_Item_Scan takes nothing returns nothing
    set gg_trg_Start_Harvest_and_Item_Scan = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Start_Harvest_and_Item_Scan, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddAction( gg_trg_Start_Harvest_and_Item_Scan, function Trig_Start_Harvest_Actions )
endfunction



JASS:
function Trig_Start_Harvest_ability_Conditions takes nothing returns boolean
    if  GetSpellAbilityId() == HARVEST_ID() then
         call SaveInteger(udg_Stat_Table, 8981, GetUnitUserData(GetTriggerUnit()), 0)
    endif
    return false
endfunction


//===========================================================================
function InitTrig_Start_Harvest_ability takes nothing returns nothing
    set gg_trg_Start_Harvest_ability = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Start_Harvest_ability, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Start_Harvest_ability, Condition( function Trig_Start_Harvest_ability_Conditions ) )
endfunction


JASS:
function Trig_Harvester_Timer_Actions takes nothing returns nothing
    local integer i = 1
    local integer d
    local integer cv
    loop
        exitwhen i > udg_H_I
        set d = 0
        if GetWidgetLife(udg_H_U[i]) < 0.2 then
            set d = 1
        endif
        if OrderId2String(GetUnitCurrentOrder(udg_H_U[i])) != "unloadall" then
            set d = 1
        endif
        set cv = GetUnitUserData(udg_H_U[i])
        if LoadItemHandle(udg_Stat_Table, 8983, cv) == null then
            set d = 1
        endif
        if LoadInteger(udg_Stat_Table, 8981, cv) == LoadInteger(udg_Stat_Table, 8982, cv) and d == 0 then
            set d = 2
        endif

        if d == 0 then
            if LoadInteger(udg_Stat_Table, 8981, cv) > - 1 then
                call SaveInteger(udg_Stat_Table, 8981, cv, LoadInteger(udg_Stat_Table, 8981, cv) + 1)
                call HarvestFT(udg_H_U[i])
            endif
        else
            if d == 2 then
                call IssueImmediateOrder( udg_H_U[i], "stop" )
                call SetItemUserData(LoadItemHandle(udg_Stat_Table, 8983, cv), 1)
                call UnitAddItem(udg_H_U[i], LoadItemHandle(udg_Stat_Table, 8983, cv))
            endif

            if udg_H_I == i then
                set udg_H_U[i] = null
            else
                set udg_H_U[i] = udg_H_U[udg_H_I]
            endif
            set udg_H_I = udg_H_I - 1
            if LoadItemHandle(udg_Stat_Table, 8983, cv) != null then
                call SaveInteger(udg_Stat_Table, 8989, GetHandleId(LoadItemHandle(udg_Stat_Table, 8983, cv)), 0)
            endif
            call SaveInteger(udg_Stat_Table, 8980, cv, 0)
            call SaveInteger(udg_Stat_Table, 8981, cv, 0)
            call SaveInteger(udg_Stat_Table, 8982, cv, 0)
            call SaveItemHandle(udg_Stat_Table, 8983, cv, null)
            call SaveReal(udg_Stat_Table, 8985, cv, 0)
            call SaveReal(udg_Stat_Table, 8986, cv, 0)
            call DestroyTextTag (LoadTextTagHandle(udg_Stat_Table, 8984, cv))
            call SaveTextTagHandle(udg_Stat_Table, 8984, cv, null)
            call SaveInteger(udg_Stat_Table, 8987, cv, 0)
        endif
        set i = i + 1
    endloop

    if udg_H_I == 0 then
        call DisableTrigger( gg_trg_Harvester_Timer )
    endif
endfunction

//===========================================================================
function InitTrig_Harvester_Timer takes nothing returns nothing
    set gg_trg_Harvester_Timer = CreateTrigger( )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Harvester_Timer, 0.50 )
    call TriggerAddAction( gg_trg_Harvester_Timer, function Trig_Harvester_Timer_Actions )
endfunction



JASS:
function Trig_Scan_Actions takes nothing returns nothing
      call SaveBoolean(udg_FSS, 551, 100 + GetPlayerId(GetTriggerPlayer())+1, true)
endfunction

//===========================================================================
function InitTrig_Scan takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
    exitwhen i > 11
      call TriggerRegisterPlayerChatEvent( t, Player(i), "-scan", true )
      set i = i + 1
    endloop
    call TriggerAddAction( t, function Trig_Scan_Actions )
    set t = null
endfunction



JASS:
function Trig_Scan_timer_Actions takes nothing returns nothing
    local integer i = 1
    local integer a = 0
    loop
        exitwhen i > 12
        if udg_Scan_Player[i] == 1 then
            set a = a + 1
            if GetWidgetLife(udg_Scan_Unit[udg_Scan_Player[i]]) > 0.2 and GetWidgetLife(udg_Scan_Target[udg_Scan_Player[i]]) > 0.2 and udg_Mb_Type[udg_Scan_Player[i]] == 2 and udg_Mb_Table[udg_Scan_Player[i]] != null then
                call UpdateMb (udg_Mb_Table[udg_Scan_Player[i]], 3, 1, "|cffffff00" + I2S(R2I(GetWidgetLife(udg_Scan_Target[udg_Scan_Player[i]]))) + "|r / |cffff3300" + I2S(R2I(GetUnitState(udg_Scan_Target[udg_Scan_Player[i]], UNIT_STATE_MAX_LIFE))) + "|r")
            else
                set udg_Scan_Unit[udg_Scan_Player[i]] = null
                set udg_Scan_Target[udg_Scan_Player[i]] = null
                call DestroyMultiboard(udg_Mb_Table[udg_Scan_Player[i]])
                set udg_Mb_Table[udg_Scan_Player[i]] = null
                set udg_Mb_Type[udg_Scan_Player[i]] = 0
                set udg_Scan_Player[i] = 0
            endif
            if a == 0 then
                call DisableTrigger( GetTriggeringTrigger() )
            endif
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Scan_timer takes nothing returns nothing
    set gg_trg_Scan_timer = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Scan_timer, 0.50 )
    call TriggerAddAction( gg_trg_Scan_timer, function Trig_Scan_timer_Actions )
endfunction



JASS:
function AddZero takes integer i returns string
if i < 10 then
return "0" + I2S(i)
else
return I2S(i)
endif
endfunction

function Trig_Global_1sec_Timer_Actions takes nothing returns nothing
local integer i = 1
local integer cv
local integer bt // buff type
local integer bc // buff count
local integer tl // second left from timer
local integer bv // buff value
local integer b // just a number
//call DisplayTextToForce( GetPlayersAll(), "out max:"+I2S(udg_OT_Max)+" i:"+I2S(i)+" timer"+I2S(udg_OT_Timer) )

set udg_Time_Sec = udg_Time_Sec + 1
if udg_Time_Sec == 60 then
set udg_Time_Sec = 0
set udg_Time_Min = udg_Time_Min + 1
if udg_Time_Min == 60 then
set udg_Time_Min = 0
set udg_Time_Hour = udg_Time_Hour + 1
endif
endif

loop
exitwhen i > 12
if udg_Mb_Type == 3 then
call MultiboardSetTitleText(udg_Mb_Table, "Timer: " + AddZero(udg_Time_Hour) + ":" + AddZero(udg_Time_Min) + ":" + AddZero(udg_Time_Sec))
endif
set i = i + 1
endloop

//---------------------------------------------------
// buff timer part
//---------------------------------------------------
set i = 1
if udg_Buff_Max > 0 then
loop
exitwhen i > udg_Buff_Max
set cv = udg_Buff_List
set b = 36000 + udg_Buff_List
if GetWidgetLife(udg_UDexUnits[cv]) > 0.3 then
set bc = 1
loop
exitwhen bc > udg_Buff_Count[cv]
set bt = LoadInteger(udg_Stat_Table, b, bc)
set bv = LoadInteger(udg_Stat_Table, - b, - bt)
set tl = LoadInteger(udg_Stat_Table, b, - bt) - 1
if tl < 1 or udg_Buff_Purge[cv] == 3 or (udg_Buff_Purge[cv] == 1 and bv > 0) or (udg_Buff_Purge[cv] == 2 and bv < 0) then
//call DisplayTextToForce( GetPlayersAll(), "|cffffff00"+GetUnitName(udg_UDexUnits[cv]) + ":|r buff type |cff0000ff" + I2S(bt) + ", buffs on unit " + I2S(udg_Buff_Count[cv]) + ", current buff is:" + I2S(bc)+" buff amount "+I2S(bv) + " expired or removed|r" )
set bc = RemoveUnitBuff(cv, bc)
else
call SaveInteger(udg_Stat_Table, b, - bt, tl)
//call DisplayTextToForce( GetPlayersAll(), "|cffffff00"+GetUnitName(udg_UDexUnits[cv]) + ":|r buff type |cffaaaaff" + I2S(bt) + "|r " + ", buffs on unit "+ I2S(udg_Buff_Count[cv]) +" buff amount " + I2S(bc) + " buff value "+I2S(bv)+ ", left |cffff4444" + I2S(tl) + "|r second" )
endif
set bc = bc + 1
endloop

set udg_Buff_Purge[cv] = 0 //set purge off to unit

if udg_Buff_Count[cv] == 0 then
//call DisplayTextToForce( GetPlayersAll(), "|cffffff00"+GetUnitName(udg_UDexUnits[cv]) + ":|r all buff expired" )
if i != udg_Buff_Max then
set udg_Buff_List = udg_Buff_List[udg_Buff_Max]
endif
set udg_Buff_List[udg_Buff_Max] = 0
set udg_Buff_Max = udg_Buff_Max - 1
set bc = - 1
endif
else
//call DisplayTextToForce( GetPlayersAll(), "|cffffff00"+GetUnitName(udg_UDexUnits[cv]) + ":|r i am died, lost all buff")
call RemoveUnitBuffs(i)
set udg_Buff_Max = udg_Buff_Max - 1
if udg_Buff_Max == 0 then
//call DisplayTextToForce( GetPlayersAll(), "dont have any buffed unit" )
endif
endif
set i = i + 1
endloop
endif
//---------------------------------------------------
// combat timer part
//---------------------------------------------------

if udg_CombatIndex > 0 then
set i = 1
loop
exitwhen i > udg_CombatIndex
set cv = udg_CombatI2CV
set udg_CombatTimer[cv] = udg_CombatTimer[cv] - 1
if udg_CombatTimer[cv] < 1 then
set udg_CombatTimer[cv] = 0
call StatRefresh (cv)
set cv = GetPlayerId(GetOwningPlayer(udg_UDexUnits[cv])) + 1
if udg_Camera_Lock[cv] == 1 then
call ShowStat (cv)
endif

if i != udg_CombatIndex then
set udg_CombatI2CV = udg_CombatI2CV[udg_CombatIndex]
set udg_CombatTimer[udg_CombatI2CV] = udg_CombatTimer[udg_CombatI2CV[udg_CombatIndex]]
endif
set udg_CombatIndex = udg_CombatIndex - 1
set i = i - 1
endif
set i = i + 1
endloop
endif

//---------------------------------------------------
// over time things like Dot and regen stuffs
//---------------------------------------------------
if udg_OT_Max > 0 then
set i = 1
loop
exitwhen i > udg_OT_Max
if GetWidgetLife(udg_OT_Source) > 0.4 and GetWidgetLife(udg_OT_Target) > 0.4 and udg_OT_Timer > 0 then
//call DisplayTextToForce( GetPlayersAll(), "max:"+I2S(udg_OT_Max)+" i:"+I2S(i)+" timer"+I2S(udg_OT_Timer) )
set udg_OT_Timer = udg_OT_Timer - 1
if udg_OT_Type < 0 then
if udg_OT_Type == - 1 then
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", udg_OT_Source, "origin"))
call SetWidgetLife(udg_OT_Source, GetWidgetLife(udg_OT_Source) + udg_OT_Value)
elseif udg_OT_Type == - 2 then
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\ReplenishMana\\SpiritTouchTarget.mdl", udg_OT_Source, "origin"))
call SetUnitState(udg_OT_Source, UNIT_STATE_MANA, GetUnitState(udg_OT_Source, UNIT_STATE_MANA) + udg_OT_Value)
endif
else
set udg_DamageEventType = udg_OT_Type
set udg_DamageTypeDOT = 1
call UnitDamageTarget(udg_OT_Source, udg_OT_Target, udg_OT_Value, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\NightElf\\shadowstrike\\shadowstrike.mdl", udg_OT_Target, "overhead"))
endif
else
if i != udg_OT_Max then
set udg_OT_Source = udg_OT_Source[udg_OT_Max]
set udg_OT_Target = udg_OT_Target[udg_OT_Max]
set udg_OT_Type = udg_OT_Type[udg_OT_Max]
set udg_OT_Value = udg_OT_Value[udg_OT_Max]
set udg_OT_Timer = udg_OT_Timer[udg_OT_Max]
endif
set udg_OT_Source[udg_OT_Max] = null
set udg_OT_Target[udg_OT_Max] = null
set udg_OT_Max = udg_OT_Max - 1
set i = i - 1
endif
set i = i + 1
endloop
endif
endfunction

//===========================================================================
function InitTrig_Global_1sec_Timer takes nothing returns nothing
set gg_trg_Global_1sec_Timer = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Global_1sec_Timer, 1.00 )
call TriggerAddAction( gg_trg_Global_1sec_Timer, function Trig_Global_1sec_Timer_Actions )
endfunction



JASS:
function Trig_Hero_Stat_Point_Conditions takes nothing returns boolean
    local integer pl = GetPlayerId(GetTriggerPlayer()) + 1
    local integer cv = GetUnitUserData(GetLevelingUnit())
    set udg_Stat_Point[cv] = udg_Stat_Point[cv] + STAT_PER_LV()
    if udg_Camera_Lock[pl] == 1 and udg_Trader[pl] == 0 then
        call ShowStat(pl)
    endif
    return false
endfunction

function AddStaetEquipmentToHero takes unit u returns nothing
    local integer class = LoadInteger(udg_FSS, 633, GetUnitTypeId(u))
    local integer rnd
    local integer w = 1
    if class == 0 then
        set rnd = GetRandomInt(1, 3)
    elseif class == 1 or class == 2 then
        set rnd = 1
    elseif class == 3 or class == 4 then
        set rnd = 2
    elseif class == 5 then
        set rnd = 3
    endif

    if rnd == 1 then
        if class == 1 then
            set w = 3
        else
            loop
                exitwhen w != 3
                set w = GetRandomInt(1, 5)
            endloop
        endif
        call UnitAddItem(u, LoadItemHandle(udg_CItem_Table, GenerateEQ (3, w, 2, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), true, 2), 100))
        if w < 3 then
            call UnitAddItem(u, LoadItemHandle(udg_CItem_Table, GenerateEQ (5, 1, 2, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), true, 2), 100))
        endif
    elseif rnd == 2 then
        if class == 3 then
            set w = 6
        else
            set w = 7
        endif
        call UnitAddItem(u, LoadItemHandle(udg_CItem_Table, GenerateEQ (3, w, 2, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), true, 2), 100))
    elseif rnd == 3 then
        set w = GetRandomInt(7, 8)
        call UnitAddItem(u, LoadItemHandle(udg_CItem_Table, GenerateEQ (3, w, 2, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), true, 2), 100))
    endif
    call UnitAddItem(u, LoadItemHandle(udg_CItem_Table, GenerateEQ (1, rnd, 2, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), true, 2), 100))
    call UnitAddItem(u, LoadItemHandle(udg_CItem_Table, GenerateEQ (2, rnd, 2, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), true, 2), 100))
    call UnitAddItem(u, LoadItemHandle(udg_CItem_Table, GenerateEQ (4, rnd, 2, GetHeroLevel(u), GetHeroLevel(u), GetUnitX(u), GetUnitY(u), true, 2), 100))
  //add bag
    call UnitAddItem(u, CreateItem('I00U', GetUnitX(u), GetUnitY(u)))

endfunction

function AddInv2Hero takes unit u returns nothing
    local integer cv
    local integer i = GetPlayerId(GetOwningPlayer(u)) + 1
    call SelectUnitAddForPlayer( u, Player(i - 1) )
    call SetHeroLevel( u, 5, false )
    call SuspendHeroXP( u, true )
            // make them permanent
    call SetPlayerAbilityAvailable( Player(i - 1), MELEE2RANGED_ID(), false)
    call UnitAddAbility( u, 'A00D' )
    call UnitAddAbility( u, 'A001' )
    call UnitAddAbility( u, 'A005' )
    call UnitAddAbility( u, 'A006' )
    call UnitAddAbility( u, 'A002' )
    call UnitAddAbility( u, 'A007' )
    call UnitAddAbility( u, 'A008' )
    call UnitAddAbility( u, 'A009' )
    call UnitAddAbility( u, 'A00H' )
    call UnitAddAbility( u, 'A00G' )
    call UnitMakeAbilityPermanent(u, true, 'A00D')
    call UnitMakeAbilityPermanent(u, true, 'A001')
    call UnitMakeAbilityPermanent(u, true, 'A002')
    call UnitMakeAbilityPermanent(u, true, 'A005')
    call UnitMakeAbilityPermanent(u, true, 'A006')
    call UnitMakeAbilityPermanent(u, true, 'A007')
    call UnitMakeAbilityPermanent(u, true, 'A008')
    call UnitMakeAbilityPermanent(u, true, 'A009')
    call UnitMakeAbilityPermanent(u, true, 'A00B')
    call UnitMakeAbilityPermanent(u, true, 'A00E')
    call UnitMakeAbilityPermanent(u, true, 'A00G')
    call UnitMakeAbilityPermanent(u, true, 'A00H')
    set cv = GetUnitUserData(u)
    set udg_Stat_Point[cv] = udg_Stat_Point[cv] + START_POINT()
    call StatRefresh (cv)
    call AddStaetEquipmentToHero (u)
    call SaveBoolean(udg_Stat_Table, 8890, GetHandleId(u), true)
    call TriggerRegisterUnitEvent( gg_trg_Start_Inventory, u, EVENT_UNIT_SPELL_EFFECT )
endfunction

function MakeAllyFromPlayer takes integer p returns nothing
    local integer i = 0
    loop
        exitwhen i > 11
        if p != i then
            call SetPlayerAlliance(Player(p), Player(i), ALLIANCE_PASSIVE, true)
        endif
        set i = i + 1
    endloop
endfunction

function Trig_Create_Heroes_and_gold_for_test_Actions takes nothing returns nothing
    local integer i = 1
    local real x
    local real y
    local trigger t1 = CreateTrigger()
    local unit u
    local integer id
    call TriggerAddCondition( t1, Condition( function Trig_Hero_Stat_Point_Conditions ) )
    loop
        exitwhen i > 12
        if ( GetPlayerSlotState(Player(i - 1)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i - 1)) == MAP_CONTROL_USER ) then
            set x = GetStartLocationX(i - 1)
            set y = GetStartLocationY(i - 1)
            set u = CreateUnit( Player(i - 1), 'H000', x, y, bj_UNIT_FACING )
            call TriggerRegisterUnitEvent( t1, u, EVENT_UNIT_HERO_LEVEL )
            set udg_Hero[i] = u
            call AddInv2Hero(u)
            set u = CreateUnit( Player(i - 1), 'Hpal', x + 100, y, bj_UNIT_FACING )
            call TriggerRegisterUnitEvent( t1, u, EVENT_UNIT_HERO_LEVEL )
            call AddInv2Hero(u)
            set u = CreateUnit( Player(i - 1), 'Hvwd', x + 100, y + 100, bj_UNIT_FACING )
            call TriggerRegisterUnitEvent( t1, u, EVENT_UNIT_HERO_LEVEL )
            call AddInv2Hero(u)
            call TriggerRegisterPlayerChatEvent( gg_trg_Trade_Gold_amount, Player(i - 1), GetEventPlayerChatString(), true )
            call SetPlayerState( Player(i - 1), PLAYER_STATE_RESOURCE_GOLD, 100000 )
            if GetLocalPlayer() == Player(i - 1) then
                call ClearSelection()
            endif
            call MakeAllyFromPlayer(i - 1)
        endif
        call FlushFT_Stat(i)
        set i = i + 1
    endloop
    set t1 = null
    set u = null
    call CWInterface()
    call ShowTradeWindow()
endfunction

//===========================================================================
function InitTrig_Create_Heroes_and_gold_for_test_and_Lv_up_func takes nothing returns nothing
    set gg_trg_Create_Heroes_and_gold_for_test_and_Lv_up_func = CreateTrigger( )
    call TriggerRegisterTimerEventSingle( gg_trg_Create_Heroes_and_gold_for_test_and_Lv_up_func, 1.00 )
    call TriggerAddAction( gg_trg_Create_Heroes_and_gold_for_test_and_Lv_up_func, function Trig_Create_Heroes_and_gold_for_test_Actions )
endfunction



JASS:
function Trig_Create_Dummy_Interface_Actions takes nothing returns nothing
    local real x1 = LoadReal(udg_FSS, 0, 1)
    local real y1 = LoadReal(udg_FSS, 0, 2)
    local real x2 = x1 + 1152
    local real y2 = y1 + 512
    local real bz = 1
    local integer i = R2I(x1)
    local integer c = 0
    local destructable d
    local unit u

    loop
        exitwhen i > R2I(x2) + 64
        set d = CreateDestructableZ('B017', i, y1 - 64, bz, 0, 1, 0)
        call SaveDestructableHandle(udg_FSS, 1400, c, d)
        set c = c + 1
        set d = CreateDestructableZ('B017', i, y2 + 64, bz, 0, 1, 0)
        call SaveDestructableHandle(udg_FSS, 1400, c, d)
        set c = c + 1
        set i = i + 196
    endloop
    set i = 0

    set i = R2I(y1)
    loop
        exitwhen i > R2I(y2) + 64
        set d = CreateDestructableZ('B018', x1 - 96, i + 32, bz, 0, 1, 0)
        call SaveDestructableHandle(udg_FSS, 1400, c, d)
        set c = c + 1
        set d = CreateDestructableZ('B018', x2 + 96, i + 32, bz, 0, 1, 0)
        call SaveDestructableHandle(udg_FSS, 1400, c, d)
        set c = c + 1
        set i = i + 196
    endloop

    set i = 0
    set c = 0
    loop
        exitwhen i > 20
        set u = CreateUnit(Player(15), 'nshe', GetRandomReal(x1 + 64, x2 - 64), GetRandomReal(y1 + 64, y2 - 64), GetRandomReal(0, 360))
        call UnitAddAbility (u, 'Aloc')
        call SaveUnitHandle(udg_FSS, 1401, c, u)
        set c = c + 1
        set i = i + 1
    endloop
    set u = CreateUnit(Player(15), 'nvlw', (x1 + x2) / 2, (y1 + y2) / 2, GetRandomReal(0, 360))
    call UnitAddAbility (u, 'Aloc')
    call SaveUnitHandle(udg_FSS, 1401, c, u)
    set d = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Create_Fake_Interface takes nothing returns nothing
    set gg_trg_Create_Fake_Interface = CreateTrigger( )
    call TriggerRegisterTimerEventSingle( gg_trg_Create_Fake_Interface, 2.00 )
    call TriggerAddAction( gg_trg_Create_Fake_Interface, function Trig_Create_Dummy_Interface_Actions )
endfunction



JASS:
function Trig_Indexing_Conditions takes nothing returns boolean
    return GetPlayerController(GetOwningPlayer(udg_UDexUnits[udg_UDex])) != MAP_CONTROL_USER  and IsUnitType(udg_UDexUnits[udg_UDex], UNIT_TYPE_SUMMONED)==false
endfunction

function Trig_Indexing_Actions takes nothing returns nothing
    local unit u = udg_UDexUnits[udg_UDex]
    local integer lv
    local integer pv = GetUnitPointValue(u)
    local integer prate = 2
    local integer mrate = 2
    local integer exprate = 1
    local integer rnd = GetRandomInt(0,99)

    call SaveReal(udg_Stat_Table, 9999, udg_UDex, GetUnitX(u))
    call SaveReal(udg_Stat_Table, 9998, udg_UDex, GetUnitY(u))
    call SaveReal(udg_Stat_Table, 9997, udg_UDex, GetUnitFacing(u))
    call SaveInteger(udg_Stat_Table, 9996, udg_UDex, GetHeroLevel(u))

    set udg_Global_Crit[udg_UDex] = 1

if GetOwningPlayer(u) != Player(PLAYER_NEUTRAL_PASSIVE) then
    if pv >= 50 and pv < 55 then
      set mrate = 3        
    elseif pv == 100 then
      set prate = 3
    elseif pv == 75 then
      set udg_Global_Crit[udg_UDex] = 10
    endif

    if ( IsUnitType(u, UNIT_TYPE_HERO)) then
        set lv = GetHeroLevel(u)
        set udg_Global_Pdef[udg_UDex] = lv * lv * 3 * mrate
        set udg_Global_Mdef1[udg_UDex] = lv * lv * 3 * mrate
        set udg_Global_Mdef2[udg_UDex] = lv * lv * 3 * mrate
        set udg_Global_Mdef3[udg_UDex] = lv * lv * 3 * mrate
        set udg_Global_Mdef4[udg_UDex] = lv * lv * 3 * mrate
        set udg_Global_Mdef5[udg_UDex] = lv * lv * 3 * mrate
        set udg_Global_Acc[udg_UDex] = lv * 300
        set udg_Global_Eva[udg_UDex] = lv * 30
        set udg_Global_Block[udg_UDex] = udg_Difficulty * 5 - 2
        set exprate = 2
        call SetUnitDrop (GetUnitTypeId(u), 110, 125, 5001, 125)
    else
        set lv = GetUnitLevel(u)
        set udg_Global_Pdef[udg_UDex] = lv * lv * prate*2
        set udg_Global_Mdef1[udg_UDex] = lv * lv * mrate*2
        set udg_Global_Mdef2[udg_UDex] = lv * lv * mrate*2
        set udg_Global_Mdef3[udg_UDex] = lv * lv * mrate*2
        set udg_Global_Mdef4[udg_UDex] = lv * lv * mrate*2
        set udg_Global_Mdef5[udg_UDex] = lv * lv * mrate*2
        set udg_Global_Acc[udg_UDex] = lv * 100
        set udg_Global_Eva[udg_UDex] = lv * 10
        set udg_Global_Block[udg_UDex] = udg_Difficulty * 3 - 2
        call SetUnitDrop (GetUnitTypeId(u), 105, 101, 5000, 120)
    endif
    
    if pv >= 50 and pv < 55 then
      if pv == 50 then
        set udg_Global_Mdef1[udg_UDex] = udg_Global_Mdef1[udg_UDex] * 2
        set udg_Global_Mdef2[udg_UDex] = udg_Global_Mdef2[udg_UDex] / 2
      elseif pv == 51 then
        set udg_Global_Mdef2[udg_UDex] = udg_Global_Mdef2[udg_UDex] * 2
        set udg_Global_Mdef5[udg_UDex] = udg_Global_Mdef5[udg_UDex] / 2
      elseif pv == 52 then
        set udg_Global_Mdef3[udg_UDex] = udg_Global_Mdef3[udg_UDex] * 2
        set udg_Global_Mdef1[udg_UDex] = udg_Global_Mdef1[udg_UDex] / 2
      elseif pv == 53 then
        set udg_Global_Mdef4[udg_UDex] = udg_Global_Mdef4[udg_UDex] * 2
        set udg_Global_Mdef3[udg_UDex] = udg_Global_Mdef3[udg_UDex] / 2
      elseif pv == 54 then
        set udg_Global_Mdef5[udg_UDex] = udg_Global_Mdef5[udg_UDex] * 2
        set udg_Global_Mdef3[udg_UDex] = udg_Global_Mdef3[udg_UDex] / 2
      endif
    endif
    if rnd < (10*udg_Difficulty) then
       if rnd == 0 then
           set udg_Global_Pdef[udg_UDex] = udg_Global_Pdef[udg_UDex] * 3 / 5
       elseif rnd == 1 then
           set udg_Global_Mdef1[udg_UDex] = udg_Global_Mdef1[udg_UDex] * 3 / 5
           set udg_Global_Mdef2[udg_UDex] = udg_Global_Mdef2[udg_UDex] * 3 / 5
           set udg_Global_Mdef3[udg_UDex] = udg_Global_Mdef3[udg_UDex] * 3 / 5
           set udg_Global_Mdef4[udg_UDex] = udg_Global_Mdef4[udg_UDex] * 3 / 5
           set udg_Global_Mdef5[udg_UDex] = udg_Global_Mdef5[udg_UDex] * 3 / 5
       elseif rnd == 2 then
           set udg_Global_Crit[udg_UDex] = udg_Global_Crit[udg_UDex] + 10
       elseif rnd == 3 then
           set udg_Global_DmgInc[udg_UDex] = udg_Global_DmgInc[udg_UDex] + 50
       elseif rnd == 4 then
           set udg_Global_DmgInc[udg_UDex] = udg_Global_DmgInc[udg_UDex] + 100
           set udg_Global_IncDmg[udg_UDex] = udg_Global_IncDmg[udg_UDex] + 100
       elseif rnd == 5 then
           set udg_Global_DmgRed[udg_UDex] = udg_Global_DmgRed[udg_UDex] + 35
       elseif rnd == 6 then
           set udg_Global_LifeSteal[udg_UDex] = udg_Global_LifeSteal[udg_UDex] + 5
       elseif rnd == 7 then
           call SetUnitMoveSpeed (u, GetUnitMoveSpeed(u) + 75)
           set udg_Global_IncDmg[udg_UDex] = udg_Global_IncDmg[udg_UDex] + 25
       elseif rnd == 8 then
           set udg_Global_LifeSteal[udg_UDex] = udg_Global_LifeSteal[udg_UDex] + 10
       elseif rnd == 9 then
           set udg_Global_Eva[udg_UDex] = udg_Global_Eva[udg_UDex] * 2
       endif
       set udg_Global_Exp[udg_UDex] = lv * 8 * exprate
    else
          set udg_Global_Exp[udg_UDex] = lv * 5 * exprate
    endif
       set udg_Global_AttLv[udg_UDex] = lv + udg_Difficulty * 25 - 25
       set udg_Global_DefLv[udg_UDex] = udg_Difficulty * 10 - 10
endif
    set u = null
endfunction

//===========================================================================
function InitTrig_Indexer_event takes nothing returns nothing
    set gg_trg_Indexer_event = CreateTrigger(  )
    call TriggerRegisterVariableEvent( gg_trg_Indexer_event, "udg_UnitIndexEvent", EQUAL, 1.00 )
    call TriggerAddCondition( gg_trg_Indexer_event, Condition( function Trig_Indexing_Conditions ) )
    call TriggerAddAction( gg_trg_Indexer_event, function Trig_Indexing_Actions )
endfunction



JASS:
function CreateDrop takes unit u, unit k returns nothing
    local integer ut = GetUnitTypeId(u)
    local integer boss = 0
    local integer lv = 0
    local integer da = LoadInteger(udg_Drop_Table, ut, 701) //drop amount
    local real dc = LoadReal(udg_Drop_Table, ut, 711) //drop chance
    local integer di
    local integer m = (udg_Difficulty / 2) + 1 //drop multiplier
    local integer i = 0
    local integer itemId
    local real rnd
    local item Gold
    local integer cvk = GetUnitUserData(k)
    local integer ic = 0//item drop count
    local item array it // item array
    if IsUnitType(u, UNIT_TYPE_HERO) then
        set lv = GetHeroLevel(u)
    else
        set lv = GetUnitLevel(u)
    endif

//---default drop---
    loop
        exitwhen i > da * m
        set rnd = GetRandomReal(0, 99.9999)
        if rnd < dc then
            set itemId = GetDefaultDropItem(ut)
            if itemId > 0 then
                set ic = ic + 1
                set it[ic] = CreateItem(itemId, GetUnitX(u), GetUnitY(u))
            endif
        endif
        set i = i + 1
    endloop
//---level depend drop---
    set da = LoadInteger(udg_Drop_Table, ut, 703) //drop amount
    set dc = LoadReal(udg_Drop_Table, ut, 713) //drop chance
    set i = 0
    if da == 0 then
        set da = 3
        set dc = 33
    endif
    loop
        exitwhen i > da * m
        set rnd = GetRandomReal(0, 99.9999)
        if rnd < dc then
            set itemId = GetLevelDropItem(lv / 20 + 1)
            if itemId > 0 then
                set ic = ic + 1
                set it[ic] = CreateItem(itemId, GetUnitX(u), GetUnitY(u))
            endif
        endif
        set i = i + 1
    endloop
//---specific cat drop, work like level depend just you can add same category for more different level unit
// basic example add if u add same category for all murloc unit so this could be commun drop betrween murlocs
//but here we add same categroy for peasant+murloc+ogre
    set da = LoadInteger(udg_Drop_Table, ut, 702) //drop amount
    set di = LoadInteger(udg_Drop_Table, ut, 710) //drop amount
    set dc = LoadReal(udg_Drop_Table, ut, 712) //drop chance
    set i = 0
    if da == 0 then
        set da = 3
        set dc = 33
    endif
    loop
        exitwhen i > da * m
        set rnd = GetRandomReal(0, 99.9999)
        if rnd < dc then
            set itemId = GetLevelDropItem(di)
            if itemId > 0 then
                set ic = ic + 1
                set it[ic] = CreateItem(itemId, GetUnitX(u), GetUnitY(u))
            endif
        endif
        set i = i + 1
    endloop
    set rnd = GetRandomReal(0, 99.9999)
    if rnd < 35 and IsUnitType(u, UNIT_TYPE_HERO) then
        call GenerateEQDrop (cvk, u)
    endif
    if rnd < 15 then
        set ic = ic + 1
        set Gold = CreateItem('gold', GetUnitX(u), GetUnitY(u))
        set i = R2I(GetRandomInt(lv, lv * lv + 5) * ((100 + udg_Stat_Gold_Bonus[GetUnitUserData(k)]) / 100.00) * m)
        call SetItemUserData(Gold, i)
        set it[ic] = Gold
        set Gold = null
    elseif rnd < 22 then
        call GenerateEQDrop (cvk, u)
    endif
    set i = 1
    loop
        exitwhen i > ic
        call AddItemRot (it[i], GetPlayerId(GetOwningPlayer(k)) + 1)
        call SetItemInvulnerable(it[i], true)
        set it[i] = null
        set i = i + 1
    endloop
endfunction

function Revive_Hero takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    local unit u = LoadUnitHandle(udg_Stat_Table, 8991, id)
    local player p = GetOwningPlayer(u)
    local integer pl = GetPlayerId(p) + 1
    local integer cv = GetUnitUserData(u)
    local integer w
    call RemoveSavedHandle(udg_Stat_Table, 8991, id)
    call ReviveHero(u, GetUnitX(u), GetUnitY(u), true)
    // we select the hero after he revived
    if GetLocalPlayer() == p then
        call ClearSelection()
        call SelectUnit(u, true)
    endif
        //--------------------------- here we must change to ranged if our hero was ranged before he died
    if LoadBoolean(udg_FSS, 631, GetUnitTypeId(u)) then
        set w = LoadInteger(udg_CItem_Table, GetHandleId(LoadItemHandle(udg_Stat_Table, cv, 3)), 3)
        if ( w==6 ) then
            if ( GetUnitTypeId( u ) == HERO_MELEE() ) then
                call SetPlayerAbilityAvailable( p, MELEE2RANGED_ID(), true )
                call IssueImmediateOrder( u, "metamorphosis" )
                call SetPlayerAbilityAvailable( p, MELEE2RANGED_ID(), false )
            endif
        else
            if ( GetUnitTypeId( u ) == HERO_RANGED() ) then
                call SetPlayerAbilityAvailable( p, MELEE2RANGED_ID(), true )
                call IssueImmediateOrder( u, "metamorphosis" )
                call SetPlayerAbilityAvailable( p, MELEE2RANGED_ID(), false )
            endif
        endif
    endif
    call PauseTimer(t)
    call DestroyTimer(t)
    set p = null
    set u = null
    set t = null
endfunction

function Revive_and_Respawn takes nothing returns nothing
    local unit du = GetDyingUnit()
    local unit ku = GetKillingUnit()
    local integer dutype = GetUnitTypeId(du)
    local integer dLv
    local real x = GetUnitX(du)
    local real y = GetUnitY(du)
    local real ang = GetUnitFacing(du)
    local player pd = GetOwningPlayer(du)
    local player pk = GetOwningPlayer(ku)
    local integer pld = GetPlayerId(pd) + 1
    local integer plk = GetPlayerId(pk) + 1
    local integer cvd = GetUnitUserData(du)
    local integer cvk = GetUnitUserData(ku)
    local integer exp
    local integer boss = 0
    local timer t
    set udg_CombatTimer[cvd] = 1
    if GetPlayerController(pd) == MAP_CONTROL_USER then
        if IsUnitType(du, UNIT_TYPE_HERO) then
            if udg_Inv_Unit[pld] == cvd then
                if udg_Camera_Lock[pld] > 0 then
                   if udg_Trader[pld] < 0 then
                      call WindowTransition (udg_Trader[pld], udg_Camera_Lock[udg_Trader[pld]], 0)
                   endif
                   call WindowTransition (pld, udg_Camera_Lock[pld], 0)
                endif
            endif
            set t = CreateTimer()
            call SaveUnitHandle(udg_Stat_Table, 8991, GetHandleId(t), du)
            call TimerStart(t, 5, false, function Revive_Hero)
            set t = null
        endif
    else
    //get the dying unit lv
        if not IsUnitType(du, UNIT_TYPE_HERO) then
            set dLv = GetUnitLevel(du)
        else
            set dLv = GetHeroLevel(du)
            set boss = 1
        endif
    //add exp
        if ku == udg_Hero[plk] then
            set exp = R2I((udg_Global_Exp[cvd] * ((100.00 + udg_Stat_Exp[cvk]) / 100.00)))
            call SuspendHeroXP(ku, false)
            call AddHeroXP(ku, exp, true)
            call SuspendHeroXP(ku, true)
            call FT_Ex (pk, pk, "+" + I2S(exp) + " exp", 2, du, 13, 0, 0, 255, 255, 90)
            if udg_Global_Hp4Kill[cvk] > 0 then
                call SetWidgetLife(ku, GetWidgetLife(ku) + udg_Global_Hp4Kill[cvk])
            endif
            if udg_Global_Mp4Kill[cvk] > 0 then
                call SetUnitState(ku, UNIT_STATE_MANA, GetUnitState(ku, UNIT_STATE_MANA) + udg_Global_Mp4Kill[cvk])
            endif
        endif
        if not IsUnitType(du, UNIT_TYPE_SUMMONED) then
            call CreateDrop(du, ku)
            call TriggerSleepAction(10)

            if boss == 0 then
                call RemoveUnit(du)
                call CreateUnit(pd, dutype, LoadReal(udg_Stat_Table, 8999, cvd), LoadReal(udg_Stat_Table, 8998, cvd), bj_RADTODEG * LoadReal(udg_Stat_Table, 8997, cvd))
            else
                call ReviveHero(du, LoadReal(udg_Stat_Table, 8999, cvd), LoadReal(udg_Stat_Table, 8998, cvd), false)
                call SetHeroLevel(du, LoadInteger(udg_Stat_Table, 8996, cvd), true)
            endif
        endif
    endif
    //call TriggerSleepAction(1)
    set du = null
    set ku = null
    set pd = null
    set pk = null
endfunction

//===========================================================================
function InitTrig_Revive_Respawn_Drop takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
        set i = i + 1
        exitwhen i == 15
    endloop
    call TriggerAddAction( t, function Revive_and_Respawn )
    set t = null
endfunction
Last edited:
Top