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. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  5. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  6. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  7. The results are out! Check them out.
    Dismiss Notice
  8. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  9. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  10. 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

ATTT v1.15.w3x
Variables
Initialization
Initialization
RGB Colors Setup
LeaderBoard Setup
Game Play
Claim
Build New Square
Detection
Win Detection
Turns
AFK Enable
AFK Timeout
GameStart
Restart
Map Startup RM
Set Markers
Dialog SetUp
Player Leaves
Misc.
Shapes
GF
Clear Msg
Camera Change
ToggleSound
Music
Music Off
Allow Attack Sound
Set Idle
Lumber and Food Clock
Banner
Banner End
Banner Loop
Resources
Dialog PnF
SimError
Table Bribe
Outdated/Unused
Coord Check
Animation Check
Remove Markers
Debug
Debug Enable
Dialog Setup2
Map Startup
PnF Dialog
Untitled Trigger 009
Build New Square Old
Order Id Detector
Detection3
Remove Item
Wrong Turn
AutoGen Board
Dialog Setup
Dialog Click
Untitled Trigger 001
Untitled Trigger 001 Copy
Untitled Trigger 002
Untitled Trigger 002 Copy
Untitled Trigger 003
Untitled Trigger 004
Untitled Trigger 006
Untitled Trigger 007
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.
//TESH.scrollpos=0
//TESH.alwaysfold=0
native UnitAlive takes unit u returns boolean
Name Type Is Array Initial Value
Banner_Boolean boolean Yes
Banner_Caster unit Yes
Banner_Dummy unit Yes
Banner_MaxIndex integer No
colorEnd string No
DoNotAllowAFKTimer boolean No
LeaderBoard leaderboard No
playerColors string Yes
RGBColors1 integer Yes
RGBColors2 integer Yes
RGBColors3 integer Yes
subStr string No
TempBoolean boolean No
TempFloat texttag No
TempForce force No
TempGroup group No
TempInteger integer No
TempInteger2 integer No
TempInteger3 integer No
TempLoc location No
TempPlayer player No
TempPoint location No
TempPoint2 location No
TempReal real No
TempReal2 real No
TempReal3 real No
TempReal4 real No
tempString string No
TempString string No
TempUnit unit Yes
TempUnit2 unit No
Initialization
  Events
    Time - Elapsed game time is 0.00 seconds
  Conditions
  Actions
    Visibility - Disable fog of war
    Visibility - Disable black mask
    Melee Game - Use melee time of day (for all players)
    Set playerColors[0] = |c00ff0303
    Set playerColors[1] = |c000042ff
    Set playerColors[2] = |c001ce6b9
    Set playerColors[3] = |c00540081
    Set playerColors[4] = |c00fffc01
    Set playerColors[5] = |c00feba0e
    Set playerColors[6] = |c0020c000
    Set playerColors[7] = |cffe55bb0
    Set playerColors[8] = |cffc0c0c0
    Set playerColors[9] = |cffb0e2ff
    Set playerColors[10] = |cff006400
    Set playerColors[11] = |cff8b4513
    Set playerColors[12] = |cff800000
    Set colorEnd = |r
    Quest - Create a Required quest titled How to Play: with the description It is similar to tic-tac-toe. You need 4 in a row to win.Players take turns claiming markers and growing the board by building unclaimed markers. After claiming a marker, the player gets to expand the board by building ALONG a side of any existing marker. (i.e. not diagonally, the newly built marker must touch a side, not just a vertex.)Read about encapulsation in the next section., using icon path ReplaceableTextures\CommandButtons\BTNSelectHeroOff.blp
    Quest - Create a Required quest titled How to Play Cont. with the description Encapsulation: If upon building a marker, an empty space is surrounded on all SIDES by a marker then the building player will instantly be given a claimed marker at that empty space.Unclaimed Markers: They collectively make up the game board (grid). Each turn a player must build one.Claimed Markers: They are markers that have been claimed by a player, connecting four results in a win. A player is able to claim at least one marker a turn.Empty Spaces: They are patches of grass that do not contain either an unclaimed or claimed marker, these are relevant in encapsulation., using icon path ReplaceableTextures\CommandButtons\BTNSelectHeroOff.blp
    Quest - Create a Required quest titled Useful Commands: with the description -afk : Puts the current turn on a "shot clock" where the turn will end in 60 seconds, not moving results in randomly generated moves. This is disabled when shot clock is on by default.-cam : Takes a value between 1000 and 8000. (zooms in and out) The default is 1650.-clear : Removes all messages from your screen.-togglesound on/off : Toggles the sounds played when your turn starts, or will end soon.-music on/off : Toggle of the Warcraft III Power of the Horde song. (Storm, Earth and Fire)., using icon path ReplaceableTextures\CommandButtons\BTNRallyPoint.blp
    Quest - Create a Optional quest titled Credits: with the description Thanks to all my buddies who've helped test my maps :DAlex, Atzy, BoB (Tim), Bong (Kc), Bryce, Chen, Cole, Dave, Dustin, Hoe (Timothy), Jon, Kia, Merlin (Joshua), Mini (Eric), PeNguyen (Peter), Ron, Soulhacker (Syed), Tena (Keegan), using icon path ReplaceableTextures\CommandButtons\BTNSorceressMaster.blp
    Quest - Create a Optional quest titled Resource Credits: with the description PurgeandFire: Dialog Wrapper SnippetBribe: TableVex: SimErrorWietlol: for guidance on coding win detection and help on creating different board shapesDr Super Good: for guidance on how to go about detecting winsGhostWolf: for guidance and help on creating different board shapesHive in general :D, using icon path ReplaceableTextures\CommandButtons\BTNSorceressMaster.blp
    Quest - Create a Optional quest titled Dedication: with the description This game is dedicated to our dear friend who was taken from us before his time. May he rest in peace., using icon path ReplaceableTextures\CommandButtons\BTNScrollUber.blp
    Custom script: call SetTerrainFogEx( 1, 0, 10000., 0., 0.00, 0.00, 0.00 )
    -------- Removes the Fog at high zoom outs --------
    Set TempPoint = (Center of (Playable map area))
    For each (Integer TempInteger) from 1 to 12, do (Actions)
      Loop - Actions
        Set TempPlayer = (Player(TempInteger))
        Camera - Pan camera for TempPlayer to TempPoint over 0 seconds
    Custom script: call RemoveLocation(udg_TempPoint)
    Custom script: call CreateDialog2()
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_RGB_Colors_Setup_Actions takes nothing returns nothing
    set udg_RGBColors1[0] = 255 // red
    set udg_RGBColors2[0] = 3
    set udg_RGBColors3[0] = 3
   
    set udg_RGBColors1[1] = 0 // blue
    set udg_RGBColors2[1] = 66
    set udg_RGBColors3[1] = 255
   
    set udg_RGBColors1[2] = 28 // teal
    set udg_RGBColors2[2] = 230
    set udg_RGBColors3[2] = 185
   
    set udg_RGBColors1[3] = 84 // purp
    set udg_RGBColors2[3] = 0
    set udg_RGBColors3[3] = 129
   
    set udg_RGBColors1[4] = 255 // yellow
    set udg_RGBColors2[4] = 252
    set udg_RGBColors3[4] = 1
   
    set udg_RGBColors1[5] = 254 // orange
    set udg_RGBColors2[5] = 186
    set udg_RGBColors3[5] = 14
   
    set udg_RGBColors1[6] = 32 // green
    set udg_RGBColors2[6] = 192
    set udg_RGBColors3[6] = 0
   
    set udg_RGBColors1[7] = 229 // pink
    set udg_RGBColors2[7] = 91
    set udg_RGBColors3[7] = 176
   
    set udg_RGBColors1[8] = 75 // gray
    set udg_RGBColors2[8] = 90
    set udg_RGBColors3[8] = 75
   
    set udg_RGBColors1[9] = 75 // light blue
    set udg_RGBColors2[9] = 175
    set udg_RGBColors3[9] = 255
   
    set udg_RGBColors1[10] = 0 // dark green
    set udg_RGBColors2[10] = 40
    set udg_RGBColors3[10] = 0
   
    set udg_RGBColors1[11] = 139  // brown
    set udg_RGBColors2[11] = 69
    set udg_RGBColors3[11] = 19
endfunction

//===========================================================================
function InitTrig_RGB_Colors_Setup takes nothing returns nothing
    set gg_trg_RGB_Colors_Setup = CreateTrigger(  )
    call TriggerAddAction( gg_trg_RGB_Colors_Setup, function Trig_RGB_Colors_Setup_Actions )
endfunction

 
 
Checks if the player attempting to move is the proper player // No longer needed, cannot click on markers when its not your turn.

Creates a marker for where the player moved

Checks to see if the moving player just won

SH.scrollpos=0
//TESH.alwaysfold=0
globals

integer array wins
leaderboard leaderBoard

endglobals

function LeaderBoardSetUp takes nothing returns nothing
    local player p
    local integer i = 0
    set leaderBoard = CreateLeaderboard()
    call LeaderboardSetLabel(leaderBoard, "Wins")
    loop
        exitwhen i > 11
        set p = Player(i)
        if IsPlaying(p) == true then
            set wins[i] = 0
            call PlayerSetLeaderboard(Player(i), leaderBoard)
            call LeaderboardAddItem(leaderBoard, GetPlayerName(Player(i)), wins[i], Player(i))
            call LeaderboardSetSizeByItemCount(leaderBoard, LeaderboardGetItemCount(leaderBoard))
        endif
        set i = i + 1
    endloop
    call LeaderboardDisplay(leaderBoard, true)
endfunction


//===========================================================================
function InitTrig_LeaderBoard_Setup takes nothing returns nothing
    set gg_trg_LeaderBoard_Setup = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_LeaderBoard_Setup, .01 )
    call TriggerAddAction( gg_trg_LeaderBoard_Setup, function LeaderBoardSetUp )
endfunction

 
Checks to make sure selected site is allowed

Checks if the new square encloses a square and gives it to the closing player
 
SH.scrollpos=0
//TESH.alwaysfold=0
function Claim_Conditions takes nothing returns boolean
    if GetSpellAbilityId() == 'A000' then
        return true
    else
        return false
    endif
endfunction

function Claim_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = Player(playerNumberOfWhoseTurn)
    local integer i = unitIdForMarkers[playerNumberOfWhoseTurn]
    local integer i2 = 0
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit u2 = CreateUnit(p, i, GetUnitX(u), GetUnitY(u), 270)
        call UnitRemoveAbility(u2, 'Amov')
        call UnitAddType(u2, UNIT_TYPE_PEON)
        call GroupAddUnit(lastMove, u2)
        call SetUnitX(u2, x)
        call SetUnitY(u2, y)
        call PauseUnit(u, true)
       if GetLocalPlayer() == p then
            call ClearSelection()
            call SelectUnit(builders[GetPlayerId(p)], true)
        endif
        set extraTurn = 1
        call Winner(p, u, u2, x, y)
        call SetUnitAnimationByIndex(u, 1)
       
    set p = null
    set u = null
    set u2 = null
endfunction

function InitTrig_Claim takes nothing returns nothing
    local trigger myTrigger = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( myTrigger, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(myTrigger, Condition(function Claim_Conditions))
        call TriggerAddAction( myTrigger, function Claim_Actions )
endfunction
Checks for all the possible win conditions. Fingers crossed.
//TESH.scrollpos=4
//TESH.alwaysfold=0
//Checks every 90 degrees if there is a structure to allow building, otherwise aborts building.
// Not sure exactly why it works even when the lines are not perfect i.e building one on the line of 2 others [][]
// See Pic.                      

    globals
        boolean isEncaps = false
    endglobals
                                                                             
function BuildNewSquare_Conditions takes nothing returns boolean
    local unit u = GetConstructingStructure()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local player p = GetOwningPlayer(u)
        if AllowBuilding(x,y) == true then
            call UnitRemoveAbility(u, 'Amov')
            call SetUnitOwner(u, Player(PLAYER_NEUTRAL_PASSIVE), true)
            call GroupAddUnit(lastMove, u)
            call TurnClaimOn()
            call TurnBuildOff(p)
            set extraTurn = -1
            set isEncaps = true
            call DetectEncapsulation(p, x, y)
            set isEncaps = false
            call NextTurn()
           
        else
            call SimError(p, "Unable to build there, select a spot that connects along a side")
            call KillUnit(u)
        endif
        set u = null
        set p = null
    return true
endfunction


function InitTrig_Build_New_Square takes nothing returns nothing
        set gg_trg_Build_New_Square = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_Build_New_Square, EVENT_PLAYER_UNIT_CONSTRUCT_START )
        call TriggerAddCondition(gg_trg_Build_New_Square, Condition(function BuildNewSquare_Conditions))
endfunction



local integer i = udg_PlayerNumberOfWhoseTurn
local integer i2 = 0
local player p2
local player p
loop
exitwhen i2 > 11
set p2 = Player(i2)
if GetLocalPlayer() == p2 and i2 == i then
call EnableSelect(true, true)
// call BJDebugMsg("Allowed playing for " + GetPlayerName(p2))
else
call EnableSelect(false, true)
call ClearSelection()
call SelectUnit(udg_Builders[GetPlayerId(p2)], true)
// call BJDebugMsg("Blocked for " + GetPlayerName(p2))
endif
set i2 = i2 + 1
endloop
set p2 = null
 
SH.scrollpos=0
//TESH.alwaysfold=0
library Detection

function BuildingsOnly takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)
endfunction

function IsSpotFilled takes real x, real y returns boolean
    local boolean result = false
    local group g = CreateGroup()
    call GroupEnumUnitsInRange(g, x, y, 10., Condition(function BuildingsOnly))

    set result = FirstOfGroup(g) != null

    call DestroyGroup(g)
    set g = null
    return result
endfunction

function IsSpotSurrounded takes real x, real y returns boolean
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 4
   
        if i == 0 then
            set x2 = x
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x
            set y2 = y - grid
        elseif i == 2 then
            set x2 = x + grid
            set y2 = y
        elseif i == 3 then
            set x2 = x - grid
            set y2 = y
        endif
   
        if not IsSpotFilled(x2, y2) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function AllowBuilding takes real x, real y returns boolean
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 4
   
        if i == 0 then
            set x2 = x
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x
            set y2 = y - grid
        elseif i == 2 then
            set x2 = x + grid
            set y2 = y
        elseif i == 3 then
            set x2 = x - grid
            set y2 = y
        endif
   
        if IsSpotFilled(x2, y2) then
            return true
        endif
   
        set i = i + 1
    endloop

    return false
endfunction

function DetectEncapsulation takes player pl, real x, real y returns nothing
    local unit u
    local integer i = 0
    local real x2
    local real y2
    local real grid = 128.

    loop
        exitwhen i >= 4
   
        if i == 0 then
            set x2 = x
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x
            set y2 = y - grid
        elseif i == 2 then
            set x2 = x + grid
            set y2 = y
        elseif i == 3 then
            set x2 = x - grid
            set y2 = y
        endif
   
        if IsSpotSurrounded(x2, y2) == true and IsSpotFilled(x2, y2)== false then
            set u = CreateUnit(pl, 'h002', x2, y2, 270)
            call SetUnitOwner(u, Player(PLAYER_NEUTRAL_PASSIVE), true)
            call SetUnitAnimationByIndex(u, 1)
            call SetUnitX(u, x2)
            call SetUnitY(u, y2)
            call IssueImmediateOrder(u, "channel")
        endif
   
        set i = i + 1
    endloop
    set u = null
endfunction

 function DetectAllowBuilding takes real x, real y returns unit u
    local real x2
    local real y2
    local unit u
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 4
   
        if i == 0 then
            set x2 = x
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x
            set y2 = y - grid
        elseif i == 2 then
            set x2 = x + grid
            set y2 = y
        elseif i == 3 then
            set x2 = x - grid
            set y2 = y
        endif
   
        if IsSpotFilled(x2, y2) == false then
            set u = CreateUnit(Player(playerNumberOfWhoseTurn), 'h00H', x2, y2, 270)
            return u
        endif
   
        set i = i + 1
    endloop
    set u = null
    return u
endfunction
 
 endlibrary
 
Add Cleanup of Toggling the build
SH.scrollpos=590
//TESH.alwaysfold=0
library WinDetection requires Turns, GF

function ClaimMarkersOnly takes nothing returns boolean // Outdated, was checking if own unit was ally lol.
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_SAPPER) and IsUnitAlly(GetFilterUnit(), GetOwningPlayer(GetFilterUnit() ))
endfunction

function IsSpotMarked takes player p, real x, real y, integer i returns boolean
    local boolean result = false
    local group g = CreateGroup()
    local group g2 = CreateGroup()
    local unit u
    call GroupEnumUnitsInRange(g, x, y, 10., null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
            if IsUnitType(u, UNIT_TYPE_SAPPER) and IsUnitAlly(u, p) == true then
                call GroupAddUnit(g2, u)
            else
            endif
            call GroupRemoveUnit(g, u)
    endloop
    set result = FirstOfGroup(g2) != null
        if i == 0 then
            //
        elseif i == 1 then
            call SetUnitVertexColor( FirstOfGroup(g2), 0, 0, 0, 255 )
            call SetAnimation(FirstOfGroup(g2))
        endif
    call DestroyGroup(g)
    call DestroyGroup(g2)
    set u = null
    set g = null
    set g2 = null
    return result
endfunction


function IsMarkInChain takes player p, real x, real y, integer j returns boolean // Checks 3 above
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0


    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x
            set y2 = y + (grid*2)
        elseif i == 2 then
            set x2 = x
            set y2 = y + (grid*3)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain2 takes player p, real x, real y, integer j returns boolean // checks 2 above 1 below
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x
            set y2 = y + (grid*2)
        elseif i == 2 then
            set x2 = x
            set y2 = y - grid
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain3 takes player p, real x, real y, integer j returns boolean // Checks 1 above 2 below
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x
            set y2 = y - grid
        elseif i == 2 then
            set x2 = x
            set y2 = y - (grid*2)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain4 takes player p, real x, real y, integer j returns boolean // Checks 3 below
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x
            set y2 = y - grid
        elseif i == 1 then
            set x2 = x
            set y2 = y - (grid*2)
        elseif i == 2 then
            set x2 = x
            set y2 = y - (grid*3)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain5 takes player p, real x, real y, integer j returns boolean // Checks 3 to the right
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x + (grid*1)
            set y2 = y
        elseif i == 1 then
            set x2 = x + (grid*2)
            set y2 = y
        elseif i == 2 then
            set x2 = x + (grid*3)
            set y2 = y
        endif
   
        if not IsSpotMarked (p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain6 takes player p, real x, real y, integer j returns boolean // Checks 2 to the right 1 left
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x + grid
            set y2 = y
        elseif i == 1 then
            set x2 = x + grid*2
            set y2 = y
        elseif i == 2 then
            set x2 = x - grid
            set y2 = y
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain7 takes player p, real x, real y, integer j returns boolean // Checks 1 to the right 2 left
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x + grid
            set y2 = y
        elseif i == 1 then
            set x2 = x - grid
            set y2 = y
        elseif i == 2 then
            set x2 = x - (grid*2)
            set y2 = y
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain8 takes player p, real x, real y, integer j returns boolean // Checks 3 left
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x - grid
            set y2 = y
        elseif i == 1 then
            set x2 = x - (grid*2)
            set y2 = y
        elseif i == 2 then
            set x2 = x - (grid*3)
            set y2 = y
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain9 takes player p, real x, real y, integer j returns boolean // Checks 3 to the Right Diagonal (/)
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x + grid
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x + (grid*2)
            set y2 = y + (grid*2)
        elseif i == 2 then
            set x2 = x + (grid*3)
            set y2 = y + (grid*3)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain10 takes player p, real x, real y, integer j returns boolean // Checks 2 to the Right diagonal (/) 1 left
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x + grid
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x + (grid*2)
            set y2 = y + (grid*2)
        elseif i == 2 then
            set x2 = x - grid
            set y2 = y - grid
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain11 takes player p, real x, real y, integer j returns boolean // Checks 1 to the Right Diagonal (/) 2 left
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x + grid
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x - grid
            set y2 = y - grid
        elseif i == 2 then
            set x2 = x - (grid*2)
            set y2 = y - (grid*2)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain12 takes player p, real x, real y, integer j returns boolean // Checks 3 to the left diagonal (/)
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x - grid
            set y2 = y - grid
        elseif i == 1 then
            set x2 = x - (grid*2)
            set y2 = y - (grid*2)
        elseif i == 2 then
            set x2 = x - (grid*3)
            set y2 = y - (grid*3)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain13 takes player p, real x, real y, integer j returns boolean // Checks 3 to the Left diagonal (\)
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x - grid
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x - (grid*2)
            set y2 = y + (grid*2)
        elseif i == 2 then
            set x2 = x - (grid*3)
            set y2 = y + (grid*3)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction
function IsMarkInChain14 takes player p, real x, real y, integer j returns boolean // Checks 2 to the left diagonal 1 right (\)
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x - grid
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x - (grid*2)
            set y2 = y + (grid*2)
        elseif i == 2 then
            set x2 = x + grid
            set y2 = y - grid
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain15 takes player p, real x, real y, integer j returns boolean // Checks 1 to the left diagonal 2 right (\)
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x - grid
            set y2 = y + grid
        elseif i == 1 then
            set x2 = x + grid
            set y2 = y - grid
        elseif i == 2 then
            set x2 = x + (grid*2)
            set y2 = y - (grid*2)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function IsMarkInChain16 takes player p, real x, real y, integer j returns boolean // Checks 3 Right diagonal (\)
    local real x2
    local real y2
    local real grid = 128.
    local integer i = 0

    loop
        exitwhen i >= 3
   
        if i == 0 then
            set x2 = x + grid
            set y2 = y - grid
        elseif i == 1 then
            set x2 = x + (grid*2)
            set y2 = y - (grid*2)
        elseif i == 2 then
            set x2 = x + (grid*3)
            set y2 = y - (grid*3)
        endif
   
        if not IsSpotMarked(p, x2, y2, j) then
            return false
        endif
   
        set i = i + 1
    endloop

    return true
endfunction

function WinningChain takes player p, real x, real y, integer j returns integer
    if IsMarkInChain(p, x, y, j) then
        return 1
    elseif IsMarkInChain2(p, x, y, j) then
        return 2
    elseif IsMarkInChain3(p, x, y, j) then
        return 3
    elseif IsMarkInChain4(p, x, y, j) then
        return 4
    elseif IsMarkInChain5(p, x, y, j) then
        return 5
    elseif IsMarkInChain6(p, x, y, j) then
        return 6
    elseif IsMarkInChain7(p, x, y, j) then
        return 7
    elseif IsMarkInChain8(p, x, y, j) then
        return 8
    elseif IsMarkInChain9(p, x, y, j) then
        return 9
    elseif IsMarkInChain10(p, x, y, j) then
        return 10
    elseif IsMarkInChain11(p, x, y, j) then
        return 11
    elseif IsMarkInChain12(p, x, y, j) then
        return 12
    elseif IsMarkInChain13(p, x, y, j) then
        return 13
    elseif IsMarkInChain14(p, x, y, j) then
        return 14
    elseif IsMarkInChain15(p, x, y, j) then
        return 15
    elseif IsMarkInChain16(p, x, y, j) then
        return 16
    endif
    return 0
endfunction

function Winner takes player p, unit u, unit u2, real x, real y returns nothing
        local integer j
        local integer i2 = 0
        local integer pId = GetPlayerId(p)
        //local string s
            set j = WinningChain(p, x, y, 0)
            if j != 0 then
                if j == 1 then
                    call IsMarkInChain(p, x, y, 1)
                elseif j == 2 then
                    call IsMarkInChain2(p, x, y, 1)
                elseif j == 3 then
                    call IsMarkInChain3(p, x, y, 1)
                elseif j == 4 then
                    call IsMarkInChain4(p, x, y, 1)
                elseif j == 5 then
                    call IsMarkInChain5(p, x, y, 1)
                elseif j == 6 then
                    call IsMarkInChain6(p, x, y, 1)
                elseif j == 7 then
                    call IsMarkInChain7(p, x, y, 1)
                elseif j == 8 then
                    call IsMarkInChain8(p, x, y, 1)
                elseif j == 9 then
                    call IsMarkInChain9(p, x, y, 1)
                elseif j == 10 then
                    call IsMarkInChain10(p, x, y, 1)
                elseif j == 11 then
                    call IsMarkInChain11(p, x, y, 1)
                elseif j == 12 then
                    call IsMarkInChain12(p, x, y, 1)
                elseif j == 13 then
                    call IsMarkInChain13(p, x, y, 1)
                elseif j == 14 then
                    call IsMarkInChain14(p, x, y, 1)
                elseif j == 15 then
                    call IsMarkInChain15(p, x, y, 1)
                elseif j == 16 then
                    call IsMarkInChain16(p, x, y, 1)
            endif
                call TurnClaimOff()
                call SetUnitVertexColor( u2, 0, 0, 0, 255 )
                call SetAnimation(u2)
                call SetUnitAnimationByIndex(u, 1)
                set hideMsg = true
                set preGame = true
                call TimerEnd2()
                call ClearTextMessages()
                set turns = turns + extraTurn
                call SetGoldToTurns(true)
                call WinSound(u2)
                call PanCameraToTimed(x, y, 0.)  
                loop
                exitwhen i2 > 11
                    call DisplayTimedTextToPlayer(Player(i2), 1, 1, 20., udg_playerColors[pId] + GetPlayerName(p) + udg_colorEnd + " has won the game!")
                    call DisplayTimedTextToPlayer(Player(i2), 1, 1, 20., "That game lasted " + udg_playerColors[5] + I2S(turns) + udg_colorEnd + " turns.")
                    call DisplayTimedTextToPlayer(Player(i2), 1, 1, 20., udg_playerColors[12] + "The game will restart in 20 seconds" + udg_colorEnd)
                    set i2 = i2 + 1
                endloop
                set wins[pId] = wins[pId] + 1
                call LeaderboardSetItemValue(leaderBoard, LeaderboardGetPlayerIndex(leaderBoard, p), wins[pId])
                call TriggerSleepAction(15.)
                call TriggerExecute(gg_trg_Restart)
                return
            else
                if isEncaps == true then
                else
                    call TurnClaimOff()
                endif
            endif
            call TurnBuildOn(p)
endfunction

 endlibrary
 
function GameStartCleanUp takes nothing returns nothing
local integer i = 0
local group g
local boolean check
call PauseTimer(startDelay)
call DestroyTimer(startDelay)
call DestroyTimerDialog(td)
call RemoveUnit(Tavern)
call EnableSelect(true, true) // I think this is necessary, although I haven't needed it. How? If a new game starts players ought to be prevented, haven't had the problem though? Why. // TRIGGER SELECTION SO ITS FINE LOL.
// set udg_TooLate = true Wont need if i update dialogs to PnF style
call RemoveSelectors()
call AutoSelect()
call BoardSetUp()
call SetGoldToTurns(false)
set g = CreateBuilders()
set check = AtleastTwo(g)
set udg_PreGame = false
set count = 0
if check == true then
call TurnSelect()
call PreventPlay()
set t = null
set t2 = null
set b = null
call DestroyGroup(g)
set g = null
else
call BJDebugMsg(udg_playerColors[0] + "Error" + udg_colorEnd + " Not enough people are playing, must be at least" + udg_playerColors[4] + " 2")
//Rerun starting functions
set t = null
set t2 = null
set b = null
call DestroyGroup(g)
set g = null
call TriggerExecute(gg_trg_Restart)
endif
//endif
endfunction
 
ESH.scrollpos=64
//TESH.alwaysfold=0
library Turns requires AFKTimers

    globals
   
    integer turns = 0
    integer extraTurn
    group lastMove = CreateGroup()
    group lastMove2 = CreateGroup()
    boolean hideMsg = false
   
    endglobals

function PreventPlay takes nothing returns nothing

    local integer i = playerNumberOfWhoseTurn
    local integer i2 = 0
    local force f = CreateForce()
    local player p
    loop
    exitwhen i2 > 11
        set p = Player(i2)
        if i2 == i then
            call ForceAddPlayer(f, p)
        else
        endif
        set i2 = i2 + 1
    endloop        
   
    if (IsPlayerInForce(GetLocalPlayer(), f)) then
            call EnableSelect(true, true)
    else
            call EnableSelect(false, true)
    endif
    set i2 = 0
    loop
        exitwhen i2 > 11
            set p = Player(i2)
                if GetLocalPlayer() == p then
                    call ClearSelection()
                    call SelectUnit(builders[GetPlayerId(p)], true)
                endif
            set i2 = i2 + 1
    endloop
    call DestroyForce(f)
    set f = null
    set p = null

endfunction


function TurnBuildOn takes player p returns nothing
    call ReviveHero(toggleBuilding[GetPlayerId(p)], 0, 0, false)
endfunction

function TurnBuildOff takes player p returns nothing
    call KillUnit(toggleBuilding[GetPlayerId(p)])
endfunction

function TurnClaimOff takes nothing returns nothing
    call SetPlayerAbilityAvailable(Player(PLAYER_NEUTRAL_PASSIVE), 'A000', false)
endfunction

function TurnClaimOn takes nothing returns nothing
    call SetPlayerAbilityAvailable(Player(PLAYER_NEUTRAL_PASSIVE), 'A000', true)
endfunction

function ClearMsg takes nothing returns nothing
    local integer i = 0
    if afkMsg == false then
        call ClearTextMessages()
    else
        set afkMsg = false
    endif
    loop
        exitwhen i > 11
       
        call DisplayTimedTextToPlayer(Player(i), 0,0, 100., "It is now " + udg_playerColors[playerNumberOfWhoseTurn] + GetPlayerName(Player(playerNumberOfWhoseTurn)) + udg_colorEnd + "'s turn.")
       
        set i = i + 1
    endloop
endfunction            
           
function SetPlayerTurn takes nothing returns nothing
    local integer i = playerNumberOfWhoseTurn + 1
    if i == 12 then
        set i = 0
    endif
    loop
        if IsPlaying(Player(i)) == true and spectating[i] == 1 then
            set playerNumberOfWhoseTurn = i
            call TurnClaimOn()
            call TurnBuildOff(Player(i))
            call ClearMsg()
            if shouldSound[playerNumberOfWhoseTurn] == true then
                if shotClockDuration == 60. then
                    if GetLocalPlayer() == Player(i) then
                        call StartSound(gg_snd_TurnStart2)
                        call SetSoundVolume(gg_snd_TurnStart2, 200)
                    endif
                endif
            endif
            return
        else
            set i = i + 1
                if i == 12 then
                    set i = 0
                endif
        endif
    endloop
endfunction

function SetGoldToTurns takes boolean b returns nothing
    local player p
    local integer i = 0
    local integer i2 = -1000000
    loop
        exitwhen i > 11
        set p = Player(i)
        if b == true then
        // Sets Gold to the number of turns
            call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, turns)
        else
        // Sets Gold to 0 for a restart
            call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, i2)
        set turns = 0
        endif
        set i = i + 1
    endloop
    set p = null
endfunction

function LastMove takes nothing returns nothing
   local unit u    
       loop
            set u = FirstOfGroup(lastMove)
            exitwhen u == null
                call SetUnitVertexColor(u, udg_RGBColors1[playerNumberOfWhoseTurn], udg_RGBColors2[playerNumberOfWhoseTurn], udg_RGBColors3[playerNumberOfWhoseTurn], 255)
            call GroupRemoveUnit(lastMove, u)
            call GroupAddUnit(lastMove2, u)
        endloop
endfunction


function LastMove2 takes nothing returns nothing
    local unit u
        loop
           set u = FirstOfGroup(lastMove2)
           exitwhen u == null
                call SetUnitVertexColor(u, 255, 255, 255, 255)
                call GroupRemoveUnit(lastMove2, u)
        endloop
    set u = null
endfunction        


function NextTurn takes nothing returns nothing
    call TimerEnd()
    set turns = turns + 1
    call SetGoldToTurns(true)
    call TurnBuildOff(Player(playerNumberOfWhoseTurn))
    call TurnClaimOn()
    call LastMove2()
    if hideMsg == false then
        call LastMove()
        call SetPlayerTurn()
    if shotClockDuration != 60. then
        call ShotClock()
    endif
    endif
    call PreventPlay()
  //  if shotClockDuration != 60. then
      //  call ShotClock()
  //  endif
endfunction


endlibrary
 
#ofRounds/TimePerRound/PowerUps?/Mode?

Z,X,+, diamond, rectangle
 
ESH.scrollpos=72
//TESH.alwaysfold=0
library AFKTimers initializer init requires AFKTimeOut

globals

timer shotClock
timerdialog shotClockTD
private integer count = 0
boolean afkTimerAlreadyOn = false
real shotClockDuration = 60.
boolean afkMsg = false
boolean array shouldSound


endglobals
   
function ShotClockCleanUp takes nothing returns nothing
    local integer i = 0
    local integer i2 = 0
    local real x = 0
        call PauseTimer(shotClock)
        call DestroyTimer(shotClock)
        call DestroyTimerDialog(shotClockTD)
            if UnitAlive(toggleBuilding[playerNumberOfWhoseTurn]) ==  false then
                call ClaimRandomMark()
                set i2 = 1
            endif
            call BuildRandomMark()
            if hideMsg == false then
                call ClearTextMessages()
            else
                set x = 1
            endif
            loop
                exitwhen i > 11
                    if i2 == 1 then
                        call DisplayTimedTextToPlayer(Player(i), x, x, 100., udg_playerColors[playerNumberOfWhoseTurn] + GetPlayerName(Player(playerNumberOfWhoseTurn)) + udg_colorEnd + " did not move in time, a marker was claimed and another built randomly.")
                    else
                        call DisplayTimedTextToPlayer(Player(i), x, x, 100., udg_playerColors[playerNumberOfWhoseTurn] + GetPlayerName(Player(playerNumberOfWhoseTurn)) + udg_colorEnd + " did not move in time, a random marker was built randomly.")
                    endif
                set i = i + 1
            endloop
            set afkMsg = true
            set afkTimerAlreadyOn = false
    set shotClock = null
    set shotClockTD = null
endfunction

function ShotClock takes nothing returns nothing
    set afkTimerAlreadyOn = true
    set shotClock = CreateTimer()
    set shotClockTD = CreateTimerDialog(shotClock)
    call TimerStart(shotClock, shotClockDuration, true, function ShotClockCleanUp)
    call TimerDialogDisplay(shotClockTD, true)
    call TimerDialogSetTitle(shotClockTD, udg_playerColors[playerNumberOfWhoseTurn] +"Turn randomized in..." + udg_colorEnd)
    if shouldSound[playerNumberOfWhoseTurn] == true then
        if GetLocalPlayer() == Player(playerNumberOfWhoseTurn) then
            call StartSound( gg_snd_TurnEnd)
            call SetSoundVolume( gg_snd_TurnEnd, 1000)
        endif
    endif
   
endfunction

function AllowAFKTimer takes nothing returns boolean
    if preGame == true then
        call DisplayTextToPlayer(GetTriggerPlayer(), 0 ,0, udg_playerColors[0] + "Error" + udg_colorEnd + " The game has not yet started, you cannot start an afk timer")
        return false
    else
        if afkTimerAlreadyOn == false then
            return true
        else
            call DisplayTextToPlayer(GetTriggerPlayer(), 0 ,0, udg_playerColors[0] + "Error" + udg_colorEnd + " The shot clock is already running")
            return false
        endif
    endif
endfunction

function TimerEnd takes nothing returns nothing
    if afkTimerAlreadyOn == true then
        if TimerGetRemaining(shotClock) != 0. then
            call PauseTimer(shotClock)
            call DestroyTimer(shotClock)
            call DestroyTimerDialog(shotClockTD)
            set afkTimerAlreadyOn = false
            set shotClock = null
            set shotClockTD = null
        else
            call ShotClockCleanUp()
        endif
    endif

endfunction    

function TimerEnd2 takes nothing returns nothing
    if afkTimerAlreadyOn == true then
        call PauseTimer(shotClock)
        call DestroyTimer(shotClock)
        call DestroyTimerDialog(shotClockTD)
        set afkTimerAlreadyOn = false
        set shotClock = null
        set shotClockTD = null
    endif
   
endfunction    

function init takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i > 11
        set shouldSound[i] = true
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_AFK_Enable takes nothing returns nothing
    set gg_trg_AFK_Enable = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(0), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(1), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(2), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(3), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(4), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(5), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(6), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(7), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(8), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(9), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(10), "-afk", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_AFK_Enable, Player(11), "-afk", true )
    call TriggerAddCondition(gg_trg_AFK_Enable, Condition(function AllowAFKTimer))
    call TriggerAddAction( gg_trg_AFK_Enable, function ShotClock )
endfunction

endlibrary
 
SH.scrollpos=0
//TESH.alwaysfold=0
library AFKTimeOut requires Detection

function BuildRandomMark takes nothing returns nothing
    local boolean b = false
    local real x
    local real y
    local real x2
    local real y2
    local unit u
    local unit u2
    local group g = CreateGroup()
        call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Condition(function BuildingsOnly))
        loop
            exitwhen b == true
            set u = FirstOfGroup(g)
            call GroupRemoveUnit(g, u)
            set x = GetUnitX(u)
            set y = GetUnitY(u)
            set u2 = DetectAllowBuilding(x, y)
            if u2 != null then
                call UnitAddAbility(u2, 'AIbl')
                call UnitApplyTimedLife(u2, 'BTLF', 1.)
                set x2 = GetUnitX(u2)
                set y2 = GetUnitY(u2)
                call IssueBuildOrderById(u2, 852619, x2, y2)
                set b = true
            endif
         
        endloop
    call DestroyGroup(g)
    set u = null
    set u2 = null
    set g = null
endfunction

function ClaimRandomMark takes nothing returns nothing
    local boolean b = false
    local unit u
    local group g = CreateGroup()
        call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Condition(function BuildingsOnly))
       
        loop
            exitwhen b == true
            set u = FirstOfGroup(g)
            call GroupRemoveUnit(g, u)
            if not IsUnitPaused(u) then
                call IssueImmediateOrder(u, "channel")
                set b = true
            endif
        endloop

        call DestroyGroup(g)
        set g = null
        set u = null
endfunction

endlibrary
 
SH.scrollpos=0
//TESH.alwaysfold=0
function Reset takes nothing returns nothing
    call RemoveUnit( GetEnumUnit() )
endfunction

function ResetMarkers takes nothing returns nothing

// the unit id is what is set when unitmarker chosen // 0 is null
    local integer i = 0
        loop
        exitwhen i > 11
            set unitIdForMarkers[i] = 0
            set i = i + 1
        endloop
endfunction


function SetFalse takes nothing returns nothing
   
 // false is no // true is yes  
    local integer i = 0
        loop
        exitwhen i > 11
            set startEarly[i] = false
            set i = i + 1
        endloop
endfunction    

function ResetSpectate takes nothing returns nothing

// 0 = yes // 1 = no
    local integer i = 0
        loop
        exitwhen i > 11
            set spectating[i] = 0
            set i = i + 1
        endloop
endfunction

function RemoveAll takes nothing returns nothing
    local integer i = 0
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
    call ForGroup(g, function Reset )
    call DestroyGroup(g)
    set g = null
    loop
        exitwhen i > 11
            call KillUnit(toggleBuilding[i])
            set toggleBuilding[i] = null
            set i = i + 1
    endloop
    call SetGoldToTurns(false)
    set hideMsg = false
    set preGame = true
    call DestroyGroup(lastMove)
    call DestroyGroup(lastMove2)
    set lastMove = null
    set lastMove2 = null
    set lastMove = CreateGroup()
    set lastMove2 = CreateGroup()
    call TurnClaimOn()
    call ResetSpectate()
    call ResetMarkers()
    call SetFalse()
    call CreateDialog2()
   
endfunction

function InitTrig_Restart takes nothing returns nothing
    set gg_trg_Restart = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Restart, function RemoveAll )
endfunction

 
 
Music
  Events
    Player - Player 1 (Red) types a chat message containing -music on as An exact match
    Player - Player 2 (Blue) types a chat message containing -music on as An exact match
    Player - Player 3 (Teal) types a chat message containing -music on as An exact match
    Player - Player 4 (Purple) types a chat message containing -music on as An exact match
    Player - Player 5 (Yellow) types a chat message containing -music on as An exact match
    Player - Player 6 (Orange) types a chat message containing -music on as An exact match
    Player - Player 7 (Green) types a chat message containing -music on as An exact match
    Player - Player 8 (Pink) types a chat message containing -music on as An exact match
    Player - Player 9 (Gray) types a chat message containing -music on as An exact match
    Player - Player 10 (Light Blue) types a chat message containing -music on as An exact match
    Player - Player 11 (Dark Green) types a chat message containing -music on as An exact match
    Player - Player 12 (Brown) types a chat message containing -music on as An exact match
  Conditions
  Actions
    Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
    Sound - Play ZStormEarthFire <gen>
    Sound - Set music volume to 100%
    Custom script: endif
Music Off
  Events
    Player - Player 1 (Red) types a chat message containing -music off as An exact match
    Player - Player 2 (Blue) types a chat message containing -music off as An exact match
    Player - Player 3 (Teal) types a chat message containing -music off as An exact match
    Player - Player 4 (Purple) types a chat message containing -music off as An exact match
    Player - Player 5 (Yellow) types a chat message containing -music off as An exact match
    Player - Player 6 (Orange) types a chat message containing -music off as An exact match
    Player - Player 7 (Green) types a chat message containing -music off as An exact match
    Player - Player 8 (Pink) types a chat message containing -music off as An exact match
    Player - Player 9 (Gray) types a chat message containing -music off as An exact match
    Player - Player 10 (Light Blue) types a chat message containing -music off as An exact match
    Player - Player 11 (Dark Green) types a chat message containing -music off as An exact match
    Player - Player 12 (Brown) types a chat message containing -music off as An exact match
  Conditions
  Actions
    Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
    Sound - Stop music Immediately
    Sound - Set music volume to 0.00%
    Custom script: endif
 
Set Idle
  Events
    Unit - A unit Finishes construction
  Conditions
    (Unit-type of (Triggering unit)) Equal to Marker
  Actions
    Custom script: call SetUnitAnimationByIndex(GetTriggerUnit(), 1)
Lumber and Food Clock
  Events
    Time - Every 1.00 seconds of game time
  Conditions
  Actions
    Player Group - Pick every player in (All players) and do (Actions)
      Loop - Actions
        Set TempPlayer = (Picked player)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            (TempPlayer Food used) Greater than or equal to 59
          Then - Actions
            Player - Set TempPlayer Food used to 0
            Player - Add 1 to TempPlayer Current lumber
          Else - Actions
            Player - Add 1 to TempPlayer Food used
Banner
  Events
    Unit - A unit Starts the effect of an ability
  Conditions
    (Ability being cast) Equal to Banner
  Actions
    Set Banner_MaxIndex = (Banner_MaxIndex + 1)
    Set TempPoint = (Target point of ability being cast)
    Set Banner_Caster[Banner_MaxIndex] = (Triggering unit)
    Unit - Create 1 Banner for (Owner of Banner_Caster[Banner_MaxIndex]) at TempPoint facing Default building facing degrees
    Set Banner_Dummy[Banner_MaxIndex] = (Last created unit)
    Set Banner_Boolean[Banner_MaxIndex] = False
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Banner_MaxIndex Equal to 1
      Then - Actions
        Trigger - Turn on Banner_Loop <gen>
      Else - Actions
    Custom script: call RemoveLocation(udg_TempPoint)
Banner End
  Events
    Unit - A unit Stops casting an ability
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Banner
  Actions
    Set TempUnit2 = (Triggering unit)
    For each (Integer TempInteger) from 1 to Banner_MaxIndex, do (Actions)
      Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            TempUnit2 Equal to Banner_Caster[TempInteger]
          Then - Actions
            Set Banner_Boolean[TempInteger] = True
          Else - Actions
Banner Loop
  Events
    Time - Every 0.05 seconds of game time
  Conditions
  Actions
    For each (Integer TempInteger) from 1 to Banner_MaxIndex, do (Actions)
      Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Banner_Boolean[TempInteger] Equal to True
          Then - Actions
            Unit - Kill Banner_Dummy[TempInteger]
            Unit - Remove Banner_Dummy[TempInteger] from the game
            Set Banner_Boolean[TempInteger] = Banner_Boolean[Banner_MaxIndex]
            Set Banner_Caster[TempInteger] = Banner_Caster[Banner_MaxIndex]
            Set Banner_Dummy[TempInteger] = Banner_Dummy[Banner_MaxIndex]
            Set TempInteger = (TempInteger - 1)
            Set Banner_MaxIndex = (Banner_MaxIndex - 1)
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              If - Conditions
                Banner_MaxIndex Equal to 0
              Then - Actions
                Trigger - Turn off (This trigger)
              Else - Actions
          Else - Actions
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Clear_Msg_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    if GetLocalPlayer() == p then
        call ClearTextMessages()
    endif
    set p = null
endfunction

//===========================================================================
function InitTrig_Clear_Msg takes nothing returns nothing
    set gg_trg_Clear_Msg = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(0), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(1), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(2), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(3), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(4), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(5), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(6), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(7), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(8), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(9), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(10), "-clear", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Clear_Msg, Player(11), "-clear", false )
    call TriggerAddAction( gg_trg_Clear_Msg, function Trig_Clear_Msg_Actions )
endfunction

 
//TESH.scrollpos=0
//TESH.alwaysfold=0
function ChangeCamera takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local string s = GetEventPlayerChatString()
    local string s2 = SubString(s, 5, StringLength(s))
    local real zoom = S2R(s2)
    local real zoom2 = 0.
    if zoom < 1000.00 or zoom > 8000.00 then
        set zoom = 1650
        call DisplayTextToPlayer(p, 0, 0, udg_playerColors[0] + ( "Error" + ( udg_colorEnd + "Your entered value was too small or large please choose something between 1000 and 8000. Resetting to Default (1650).")))
    endif
    if zoom > 3000. then
        set zoom2 = 10000.
    else
        set zoom2 = 5000.
    endif
    if GetLocalPlayer() == p then
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, zoom, 0)
        call SetCameraField(CAMERA_FIELD_FARZ, zoom2, 0)
    endif
    set p = null
endfunction

//===========================================================================
function InitTrig_Camera_Change takes nothing returns nothing
    set gg_trg_Camera_Change = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(0), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(1), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(2), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(3), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(4), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(5), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(6), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(7), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(8), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(9), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(10), "-cam", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_Camera_Change, Player(11), "-cam", false )
    call TriggerAddAction( gg_trg_Camera_Change, function ChangeCamera )
endfunction

 
//TESH.scrollpos=0
//TESH.alwaysfold=0
function ToggleSound takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local string s = GetEventPlayerChatString()
    local string s2 = SubString(s, 13, StringLength(s))
       
        if s2 == "on" then
            set shouldSound[GetPlayerId(p)] = true
            call DisplayTextToPlayer(p, 0, 0, "You have toggled Turn Sounds " + udg_playerColors[4] + "on" + udg_colorEnd)
        elseif s2 == "off" then
            set shouldSound[GetPlayerId(p)] = false
            call DisplayTextToPlayer(p, 0, 0, "You have toggled Turn Sounds " + udg_playerColors[4] + "off" + udg_colorEnd)
        else
            call DisplayTextToPlayer(p, 0, 0, udg_playerColors[0] + ( "Error" + ( udg_colorEnd + "You have entered an unacceptable command.  Try either on or off.")))
        endif
    set p = null
endfunction

//===========================================================================
function InitTrig_ToggleSound takes nothing returns nothing
    set gg_trg_ToggleSound = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(0), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(1), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(2), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(3), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(4), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(5), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(6), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(7), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(8), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(9), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(10), "-togglesound", false )
    call TriggerRegisterPlayerChatEvent( gg_trg_ToggleSound, Player(11), "-togglesound", false )
    call TriggerAddAction( gg_trg_ToggleSound, function ToggleSound )
endfunction

 
Coord Check
  Events
    Player - Player 1 (Red) Selects a unit
  Conditions
    (Unit-type of (Triggering unit)) Equal to Marker
  Actions
    Game - Display to (All players) the text: (String((X of (Position of (Triggering unit)))))
    Game - Display to (All players) the text: (String((Y of (Position of (Triggering unit)))))
 
Remove Markers
  Events
    Player - Player 1 (Red) types a chat message containing 10 as An exact match
  Conditions
  Actions
    Unit Group - Pick every unit in (Units currently selected by Player 1 (Red)) and do (Actions)
      Loop - Actions
        Unit - Remove (Picked unit) from the game
SH.scrollpos=0
//TESH.alwaysfold=0
function StopAttack takes nothing returns nothing
    local unit u = GetAttacker()
    call PauseUnit(u, true)
    call IssueImmediateOrder(u, "stop")
    call PauseUnit(u, false)
    set u = null
endfunction

function InitTrig_Allow_Attack_Sound takes nothing returns nothing
    local trigger myTrigger = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( myTrigger, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddAction( myTrigger, function StopAttack)
endfunction

 
 
Dialog Needs to be destroyed -- Currently leaks...
 
CleanUp Still needs Auto select unittype if none is chosen.

 
 
Untitled Trigger 009
  Events
    Unit - A unit Begins construction
  Conditions
  Actions
    Game - Display to (All players) the text: ((String((X of (Position of (Triggering unit))))) + (String((Y of (Position of (Triggering unit))))))
Checks to make sure selected site is allowed

Checks if the new square encloses a square and gives it to the closing player
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Dialog /* v.1.1.0.0
**************************************************
*
*   A struct wrapper for easy dialog creation.
*
**************************************************
*
*/
 requires Table  /* [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url]
*
**************************************************
*
*   struct Dialog
*
*       static method create() returns thistype
*          
*           Creates a new dialog and returns its instance.
*
*       method operator title= takes string s
*
*           Sets the title message for the dialog.
*
*       method addButton( string text, integer hotkey ) returns button
*
*           Adds a button to the dialog that reads <text>.
*           The hotkey serves as a shortcut to press a dialog
*           button. Example input: 'a', 'b', 512 (esc).
*
*       method display( player p, boolean flag )
*          
*           Shows/hides a dialog for a particular player.
*
*       method displayAll( boolean flag )
*
*           Shows/hides a dialog for all players.
*
*       method clear()
*  
*           Clears a dialog of its message and buttons.
*
*       method destroy()
*
*           Destroys a dialog and its instance.
*
*   -- Event API --
*
*       method registerClickEvent( boolexpr b )
*
*           Registers when a dialog button is clicked.
*
*       static method getClickedDialog() returns Dialog
*       static method getClickedButton() returns button
*       static method getPlayer() returns player
*
*            Event responses.
*
**************************************************
*
*   Constants - Credits to DysfunctionaI for the list!
*/

    globals
        constant integer KEY_SPACEBAR          = 32
       
        /* Number Pad */
        constant integer KEY_NUMPAD_0          = 257
        constant integer KEY_NUMPAD_1          = 258
        constant integer KEY_NUMPAD_2          = 259
        constant integer KEY_NUMPAD_3          = 260
        constant integer KEY_NUMPAD_4          = 261
        constant integer KEY_NUMPAD_5          = 262
        constant integer KEY_NUMPAD_6          = 263
        constant integer KEY_NUMPAD_7          = 264
        constant integer KEY_NUMPAD_8          = 265
        constant integer KEY_NUMPAD_9          = 266
        constant integer KEY_NUMPAD_PLUS       = 267
        constant integer KEY_NUMPAD_MINUS      = 268
        constant integer KEY_NUMPAD_ASTERISK   = 269
        constant integer KEY_NUMPAD_SLASH      = 270
        constant integer KEY_NUMPAD_PERIOD     = 271
       
        constant integer KEY_EQUALS            = 272
        constant integer KEY_MINUS             = 273
        constant integer KEY_LEFT_BRACKET      = 274
        constant integer KEY_RIGHT_BRACKET     = 275
        constant integer KEY_BACKSLASH         = 276
        constant integer KEY_SEMICOLON         = 277
        constant integer KEY_APOSTROPHE        = 278
        constant integer KEY_COMMA             = 279
        constant integer KEY_PERIOD            = 280  
        constant integer KEY_SLASH             = 281
        constant integer KEY_ESCAPE            = 512
        constant integer KEY_BACKSPACE         = 514
       
        /* Arrows */
        constant integer KEY_LEFT_ARROW        = 516
        constant integer KEY_UP_ARROW          = 517
        constant integer KEY_RIGHT_ARROW       = 518
        constant integer KEY_DOWN_ARROW        = 519
       
        constant integer KEY_INSERT            = 520
        constant integer KEY_DELETE            = 521
        constant integer KEY_HOME              = 522
        constant integer KEY_END               = 523
        constant integer KEY_PAGE_UP           = 524
        constant integer KEY_PAGE_DOWN         = 525
        constant integer KEY_CAPS_LOCK         = 526
        constant integer KEY_NUM_LOCK          = 527
        constant integer KEY_SCROLL_LOCK       = 528
        constant integer KEY_PAUSE             = 529
       
        /* Function Buttons */
        constant integer KEY_F1                = 768
        constant integer KEY_F2                = 769
        constant integer KEY_F3                = 770
        constant integer KEY_F4                = 771
        constant integer KEY_F5                = 772
        constant integer KEY_F6                = 773
        constant integer KEY_F7                = 774
        constant integer KEY_F8                = 775
        constant integer KEY_F9                = 776
        constant integer KEY_F10               = 777
        constant integer KEY_F11               = 778
        constant integer KEY_F12               = 779
    endglobals
/*
**************************************************/


    globals
        private Table instance = 0
    endglobals
   
    private module DialogInit
        private static method onInit takes nothing returns nothing
            set instance = Table.create()
        endmethod
    endmodule

    struct Dialog
        private dialog dg
        private trigger click
        private string msg
       
        static method getClickedDialog takes nothing returns thistype
            return instance[GetHandleId(GetClickedDialog())]
        endmethod
        static method getClickedButton takes nothing returns button
            return GetClickedButton()
        endmethod
        static method getPlayer takes nothing returns player
            return GetTriggerPlayer()
        endmethod
       
        method operator title= takes string text returns nothing
            call DialogSetMessage(this.dg, text)
            set this.msg = text
        endmethod
       
        method addButton takes string text, integer hotkey returns button
            return DialogAddButton(this.dg, text, hotkey)
        endmethod
       
        method display takes player p, boolean flag returns nothing
            call DialogDisplay(p, this.dg, flag)
            call DialogSetMessage(this.dg, this.msg)
        endmethod
        method displayAll takes boolean flag returns nothing
            call DialogDisplay(GetLocalPlayer(), this.dg, flag)
            call DialogSetMessage(this.dg, this.msg)
        endmethod
       
        method clear takes nothing returns nothing
            call DialogClear(this.dg)
            set this.msg = ""
        endmethod
       
        method registerClickEvent takes boolexpr b returns nothing
            if this.click == null then
                set instance[GetHandleId(this.dg)] = this
                set this.click = CreateTrigger()
                call TriggerRegisterDialogEvent(this.click, this.dg)
            endif
            call TriggerAddCondition(this.click, b)
        endmethod
       
        method destroy takes nothing returns nothing
            debug if this.dg == null then
            debug     call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "[Dialog] Attempted to destroy null dialog.")
            debug endif
           
            if this.click != null then
                call DestroyTrigger(this.click)
                call instance.remove(GetHandleId(this.dg))
                set this.click = null
            endif
           
            call DialogClear(this.dg)
            call DialogDestroy(this.dg)
            set this.dg = null
            call this.deallocate()
        endmethod
   
        static method create takes nothing returns thistype
            local thistype this = thistype.allocate()
            set this.dg = DialogCreate()
            return this
        endmethod
       
        implement DialogInit
    endstruct
   
endlibrary
//TESH.scrollpos=11
//TESH.alwaysfold=0
library SimError initializer init
//**************************************************************************************************
//*
//*  SimError
//*
//*     Mimic an interface error message
//*       call SimError(ForPlayer, msg)
//*         ForPlayer : The player to show the error
//*         msg       : The error
//*    
//*     To implement this function, copy this trigger and paste it in your map.
//* Unless of course you are actually reading the library from wc3c's scripts section, then just
//* paste the contents into some custom text trigger in your map.
//*
//**************************************************************************************************

//==================================================================================================
    globals
        private sound error
    endglobals
    //====================================================================================================

    function SimError takes player ForPlayer, string msg returns nothing
        set msg="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00"+msg+"|r"
        if (GetLocalPlayer() == ForPlayer) then
            call ClearTextMessages()
            call DisplayTimedTextToPlayer( ForPlayer, 0.52, 0.96, 2.00, msg )
            call StartSound( error )
        endif
    endfunction

    private function init takes nothing returns nothing
         set error=CreateSoundFromLabel("InterfaceError",false,false,false,10,10)
         //call StartSound( error ) //apparently the bug in which you play a sound for the first time
                                    //and it doesn't work is not there anymore in patch 1.22
    endfunction
   
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 4.1.0.1.
   
    One map, one hashtable. Welcome to NewTable 4.1.0.1
   
    This newest iteration of Table introduces the new HashTable struct.
    You can now instantiate HashTables which enables the use of large
    parent and large child keys, just like a standard hashtable. Previously,
    the user would have to instantiate a Table to do this on their own which -
    while doable - is something the user should not have to do if I can add it
    to this resource myself (especially if they are inexperienced).
   
    This library was originally called NewTable so it didn't conflict with
    the API of Table by Vexorian. However, the damage is done and it's too
    late to change the library name now. To help with damage control, I
    have provided an extension library called TableBC, which bridges all
    the functionality of Vexorian's Table except for 2-D string arrays &
    the ".flush(integer)" method. I use ".flush()" to flush a child hash-
    table, because I wanted the API in NewTable to reflect the API of real
    hashtables (I thought this would be more intuitive).
   
    API
   
    ------------
    struct Table
    | static method create takes nothing returns Table
    |     create a new Table
    |    
    | method destroy takes nothing returns nothing
    |     destroy it
    |    
    | method flush takes nothing returns nothing
    |     flush all stored values inside of it
    |    
    | method remove takes integer key returns nothing
    |     remove the value at index "key"
    |    
    | method operator []= takes integer key, $TYPE$ value returns nothing
    |     assign "value" to index "key"
    |    
    | method operator [] takes integer key returns $TYPE$
    |     load the value at index "key"
    |    
    | method has takes integer key returns boolean
    |     whether or not the key was assigned
    |
    ----------------
    struct TableArray
    | static method operator [] takes integer array_size returns TableArray
    |     create a new array of Tables of size "array_size"
    |
    | method destroy takes nothing returns nothing
    |     destroy it
    |
    | method flush takes nothing returns nothing
    |     flush and destroy it
    |
    | method operator size takes nothing returns integer
    |     returns the size of the TableArray
    |
    | method operator [] takes integer key returns Table
    |     returns a Table accessible exclusively to index "key"
*/

   
globals
    private integer less = 0    //Index generation for TableArrays (below 0).
    private integer more = 8190 //Index generation for Tables.
    //Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
   
    private hashtable ht = InitHashtable()
    private key sizeK
    private key listK
endglobals
   
private struct dex extends array
    static method operator size takes nothing returns Table
        return sizeK
    endmethod
    static method operator list takes nothing returns Table
        return listK
    endmethod
endstruct
   
private struct handles extends array
    method has takes integer key returns boolean
        return HaveSavedHandle(ht, this, key)
    endmethod
    method remove takes integer key returns nothing
        call RemoveSavedHandle(ht, this, key)
    endmethod
endstruct
   
private struct agents extends array
    method operator []= takes integer key, agent value returns nothing
        call SaveAgentHandle(ht, this, key, value)
    endmethod
endstruct
   
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
    method operator [] takes integer key returns $TYPE$
        return Load$FUNC$(ht, this, key)
    endmethod
    method operator []= takes integer key, $TYPE$ value returns nothing
        call Save$FUNC$(ht, this, key, value)
    endmethod
    method has takes integer key returns boolean
        return HaveSaved$SUPER$(ht, this, key)
    endmethod
    method remove takes integer key returns nothing
        call RemoveSaved$SUPER$(ht, this, key)
    endmethod
endstruct
private module $TYPE$m
    method operator $TYPE$ takes nothing returns $TYPE$s
        return this
    endmethod
endmodule
//! endtextmacro
   
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
    method operator [] takes integer key returns $TYPE$
        return Load$FUNC$Handle(ht, this, key)
    endmethod
    method operator []= takes integer key, $TYPE$ value returns nothing
        call Save$FUNC$Handle(ht, this, key, value)
    endmethod
    method has takes integer key returns boolean
        return HaveSavedHandle(ht, this, key)
    endmethod
    method remove takes integer key returns nothing
        call RemoveSavedHandle(ht, this, key)
    endmethod
endstruct
private module $TYPE$m
    method operator $TYPE$ takes nothing returns $TYPE$s
        return this
    endmethod
endmodule
//! endtextmacro
   
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
   
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
   
struct Table extends array
   
    // Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
    implement realm
    implement integerm
    implement booleanm
    implement stringm
    implement playerm
    implement widgetm
    implement destructablem
    implement itemm
    implement unitm
    implement abilitym
    implement timerm
    implement triggerm
    implement triggerconditionm
    implement triggeractionm
    implement eventm
    implement forcem
    implement groupm
    implement locationm
    implement rectm
    implement boolexprm
    implement soundm
    implement effectm
    implement unitpoolm
    implement itempoolm
    implement questm
    implement questitemm
    implement defeatconditionm
    implement timerdialogm
    implement leaderboardm
    implement multiboardm
    implement multiboarditemm
    implement trackablem
    implement dialogm
    implement buttonm
    implement texttagm
    implement lightningm
    implement imagem
    implement ubersplatm
    implement regionm
    implement fogstatem
    implement fogmodifierm
    implement hashtablem
   
    method operator handle takes nothing returns handles
        return this
    endmethod
   
    method operator agent takes nothing returns agents
        return this
    endmethod
   
    //set this = tb[GetSpellAbilityId()]
    method operator [] takes integer key returns Table
        return LoadInteger(ht, this, key) //return this.integer[key]
    endmethod
   
    //set tb[389034] = 8192
    method operator []= takes integer key, Table tb returns nothing
        call SaveInteger(ht, this, key, tb) //set this.integer[key] = tb
    endmethod
   
    //set b = tb.has(2493223)
    method has takes integer key returns boolean
        return HaveSavedInteger(ht, this, key) //return this.integer.has(key)
    endmethod
   
    //call tb.remove(294080)
    method remove takes integer key returns nothing
        call RemoveSavedInteger(ht, this, key) //call this.integer.remove(key)
    endmethod
   
    //Remove all data from a Table instance
    method flush takes nothing returns nothing
        call FlushChildHashtable(ht, this)
    endmethod
   
    //local Table tb = Table.create()
    static method create takes nothing returns Table
        local Table this = dex.list[0]
       
        if this == 0 then
            set this = more + 1
            set more = this
        else
            set dex.list[0] = dex.list[this]
            call dex.list.remove(this) //Clear hashed memory
        endif
       
        debug set dex.list[this] = -1
        return this
    endmethod
   
    // Removes all data from a Table instance and recycles its index.
    //
    //     call tb.destroy()
    //
    method destroy takes nothing returns nothing
        debug if dex.list[this] != -1 then
            debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
            debug return
        debug endif
       
        call this.flush()
       
        set dex.list[this] = dex.list[0]
        set dex.list[0] = this
    endmethod
   
    //! runtextmacro optional TABLE_BC_METHODS()
endstruct
   
//! runtextmacro optional TABLE_BC_STRUCTS()
   
struct TableArray extends array
   
    //Returns a new TableArray to do your bidding. Simply use:
    //
    //    local TableArray ta = TableArray[array_size]
    //
    static method operator [] takes integer array_size returns TableArray
        local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
        local TableArray this = tb[0]         //The last-destroyed TableArray that had this array size
       
        debug if array_size <= 0 then
            debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
            debug return 0
        debug endif
       
        if this == 0 then
            set this = less - array_size
            set less = this
        else
            set tb[0] = tb[this]  //Set the last destroyed to the last-last destroyed
            call tb.remove(this)  //Clear hashed memory
        endif
       
        set dex.size[this] = array_size //This remembers the array size
        return this
    endmethod
   
    //Returns the size of the TableArray
    method operator size takes nothing returns integer
        return dex.size[this]
    endmethod
   
    //This magic method enables two-dimensional[array][syntax] for Tables,
    //similar to the two-dimensional utility provided by hashtables them-
    //selves.
    //
    //ta[integer a].unit[integer b] = unit u
    //ta[integer a][integer c] = integer d
    //
    //Inline-friendly when not running in debug mode
    //
    method operator [] takes integer key returns Table
        static if DEBUG_MODE then
            local integer i = this.size
            if i == 0 then
                call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
                return 0
            elseif key < 0 or key >= i then
                call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
                return 0
            endif
        endif
        return this + key
    endmethod
   
    //Destroys a TableArray without flushing it; I assume you call .flush()
    //if you want it flushed too. This is a public method so that you don't
    //have to loop through all TableArray indices to flush them if you don't
    //need to (ie. if you were flushing all child-keys as you used them).
    //
    method destroy takes nothing returns nothing
        local Table tb = dex.size[this.size]
       
        debug if this.size == 0 then
            debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
            debug return
        debug endif
       
        if tb == 0 then
            //Create a Table to index recycled instances with their array size
            set tb = Table.create()
            set dex.size[this.size] = tb
        endif
       
        call dex.size.remove(this) //Clear the array size from hash memory
       
        set tb[this] = tb[0]
        set tb[0] = this
    endmethod
   
    private static Table tempTable
    private static integer tempEnd
   
    //Avoids hitting the op limit
    private static method clean takes nothing returns nothing
        local Table tb = .tempTable
        local integer end = tb + 0x1000
        if end < .tempEnd then
            set .tempTable = end
            call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
        else
            set end = .tempEnd
        endif
        loop
            call tb.flush()
            set tb = tb + 1
            exitwhen tb == end
        endloop
    endmethod
   
    //Flushes the TableArray and also destroys it. Doesn't get any more
    //similar to the FlushParentHashtable native than this.
    //
    method flush takes nothing returns nothing
        debug if this.size == 0 then
            debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
            debug return
        debug endif
        set .tempTable = this
        set .tempEnd = this + this.size
        call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
        call this.destroy()
    endmethod
   
endstruct
   
//NEW: Added in Table 4.0. A fairly simple struct but allows you to do more
//than that which was previously possible.
struct HashTable extends array

    //Enables myHash[parentKey][childKey] syntax.
    //Basically, it creates a Table in the place of the parent key if
    //it didn't already get created earlier.
    method operator [] takes integer index returns Table
        local Table t = Table(this)[index]
        if t == 0 then
            set t = Table.create()
            set Table(this)[index] = t //whoops! Forgot that line. I'm out of practice!
        endif
        return t
    endmethod

    //You need to call this on each parent key that you used if you
    //intend to destroy the HashTable or simply no longer need that key.
    method remove takes integer index returns nothing
        local Table t = Table(this)[index]
        if t != 0 then
            call t.destroy()
            call Table(this).remove(index)
        endif
    endmethod
   
    //Added in version 4.1
    method has takes integer index returns boolean
        return Table(this).has(index)
    endmethod
   
    //HashTables are just fancy Table indices.
    method destroy takes nothing returns nothing
        call Table(this).destroy()
    endmethod
   
    //Like I said above...
    static method create takes nothing returns thistype
        return Table.create()
    endmethod

endstruct

endlibrary
Removes the item upon buying
 
// Gets the Player Number of whose turn it is then decides whether to display error message.
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Hello_Actions takes nothing returns nothing
    local group g = CreateGroup()
    local unit u
    local string s = GetEventPlayerChatString()
    local integer i = S2I(s)
    call GroupEnumUnitsOfPlayer(g, Player(0), null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call GroupRemoveUnit(g, u)
        call SetUnitAnimationByIndex(u, i)
    endloop
endfunction

//===========================================================================
function InitTrig_Animation_Check takes nothing returns nothing
    set gg_trg_Animation_Check = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Animation_Check, Player(0), "", false )
    call TriggerAddAction( gg_trg_Animation_Check, function Trig_Hello_Actions )
endfunction

 
AutoGen Board
  Events
  Conditions
  Actions
    For each (Integer TempInteger) from 1 to 100, do (Actions)
      Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            TempInteger2 Equal to 10
          Then - Actions
            Set TempInteger2 = 0
            Set TempReal2 = 0.00
            Set TempPoint = (Center of (Playable map area))
            Unit - Create 1 for Neutral Passive at TempPoint facing Default building facing degrees
            Set TempUnit[1] = (Last created unit)
            Custom script: call SetUnitAnimationByIndex(udg_TempUnit[1], 1)
            Custom script: call UnitRemoveAbility(udg_TempUnit[1], 'Amov')
            Custom script: call SetUnitX(udg_TempUnit[1], GetUnitX(udg_TempUnit[0]) + udg_TempReal * Cos(bj_DEGTORAD * udg_TempReal2))
            Custom script: call SetUnitY(udg_TempUnit[1], GetUnitY(udg_TempUnit[0]) + udg_TempReal * Sin(bj_DEGTORAD * udg_TempReal2))
            Set TempInteger2 = (TempInteger2 + 1)
            Set TempUnit[0] = TempUnit[1]
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              If - Conditions
                TempBoolean Equal to False
              Then - Actions
                Set TempBoolean = True
                Set TempReal2 = 90.00
              Else - Actions
                Set TempBoolean = False
                Set TempReal2 = 270.00
            Custom script: call RemoveLocation(udg_TempPoint)
          Else - Actions
        Set TempPoint = (Center of (Playable map area))
        Unit - Create 1 for Neutral Passive at TempPoint facing Default building facing degrees
        Set TempUnit[1] = (Last created unit)
        Custom script: call SetUnitAnimationByIndex(udg_TempUnit[1], 1)
        Custom script: call UnitRemoveAbility(udg_TempUnit[1], 'Amov')
        Custom script: call SetUnitX(udg_TempUnit[1], GetUnitX(udg_TempUnit[0]) + udg_TempReal * Cos(bj_DEGTORAD * udg_TempReal2))
        Custom script: call SetUnitY(udg_TempUnit[1], GetUnitY(udg_TempUnit[0]) + udg_TempReal * Sin(bj_DEGTORAD * udg_TempReal2))
        Set TempUnit[0] = TempUnit[1]
        Set TempInteger2 = (TempInteger2 + 1)
        Custom script: call RemoveLocation(udg_TempPoint)
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Debug

function Debug takes string s returns nothing
    //call BJDebugMsg("fired")
    if udg_DebugMode == true then
        call DisplayTimedTextToForce(udg_DebugForce, 300., s)
    endif
endfunction

endlibrary
//TESH.scrollpos=2
//TESH.alwaysfold=0
function Trig_Debug_Enable_Actions takes nothing returns nothing
    if udg_DebugForce == null then
        set udg_DebugForce = CreateForce()
        set udg_DebugMode = true
    endif
   
    if IsPlayerInForce(GetTriggerPlayer(), udg_DebugForce) == false then
        call ForceAddPlayer(udg_DebugForce, GetTriggerPlayer())
        call DisplayTextToPlayer(GetTriggerPlayer(), 0 , 0, "You will now get debug messages")
        else
        call ForceRemovePlayer(udg_DebugForce, GetTriggerPlayer())
        call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, "You will no longer get debug messages")
        if CountPlayersInForceBJ(udg_DebugForce) <= 0 then
        call DestroyForce(udg_DebugForce)
        set udg_DebugForce = null
        set udg_DebugMode = false
        endif
    endif
   
   
   
endfunction

//===========================================================================
function InitTrig_Debug_Enable takes nothing returns nothing
    set gg_trg_Debug_Enable = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(0), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(1), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(2), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(3), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(4), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(5), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(6), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(7), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(8), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(9), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(10), "-debug", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_Debug_Enable, Player(11), "-debug", true )
    call TriggerAddAction( gg_trg_Debug_Enable, function Trig_Debug_Enable_Actions )
endfunction

 
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Dialog222 //initializer CreateDialog

    globals
        private button array buttons
    endglobals
   
function IsPlaying takes player p returns boolean
    if ( GetPlayerController(p) == MAP_CONTROL_USER ) and ( GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING ) then
        return true
    endif
    return false
endfunction
   
function WhichButton takes nothing returns boolean
        local dialog d = GetClickedDialog()
        local button  b  = GetClickedButton()
        local group g = CreateGroup()
        local unit u
        local player p = GetTriggerPlayer()
        local integer i = GetPlayerId(p)
       
        if b == buttons[0] then
            if udg_TooLate == true then
                set udg_Spectating[i] = 0
                call DisplayTextToPlayer(p, 0, 0, "You were too late, you will be able to play next game")
            else
                set udg_Spectating[i] = 1
            endif
        elseif b == buttons[1] then
            set udg_StartEarly[i] = true
            set udg_Spectating[i] = 0
            set g = GetUnitsOfPlayerMatching(p, null)
            loop
                set u = FirstOfGroup(g)
                exitwhen u == null
                    call GroupRemoveUnit(g, u)
                    call RemoveUnit(u)
            endloop
        endif      
        call DialogDisplay(p, d, false)
        call DestroyGroup(g)
        set b = null
        set u = null
        set g = null
        return false
endfunction
   

function ShowDialog takes nothing returns nothing
        local dialog d = DialogCreate()
        local integer i = 0
        local trigger t = CreateTrigger()
        local player p
        call DialogSetMessage(d, "Welcome to Advanced Tic-Tac-Toe\n          Would you like to play?")
        set buttons[0] = DialogAddButton(d,"Yes " + "[Y]", 'Y')
        set buttons[1] = DialogAddButton(d,"No, I'll Observe (Lasts 1 Game) " + "[N]", 'N')
       
        loop
        exitwhen i > 11
            set p = Player(i)
            if IsPlaying(p) == true then
            call DialogDisplay(p, d, true)
            else
            endif
        set i = i + 1
endloop
        call TriggerRegisterDialogEvent(t, d)
        call TriggerAddCondition(t, Condition(function WhichButton))
        set d = null
        set t = null
        set p = null
endfunction

function CreateDialog takes nothing returns nothing
        call TimerStart(CreateTimer(), 0, false, function ShowDialog)
endfunction

endlibrary
//TESH.scrollpos=162
//TESH.alwaysfold=0
library GameStart requires Turns

globals

private timer t
private timer t2
private timerdialog b
private unit Tavern
private group selectors
private integer count = 0

endglobals

function TurnSelect takes nothing returns nothing
    local integer i = GetRandomInt(0, 11)
    set udg_PlayerNumberOfWhoseTurn = i
   
    loop
        if IsPlaying(Player(i)) == true and udg_Spectating[i] == 1 then
            set udg_PlayerNumberOfWhoseTurn = i
            call BJDebugMsg(udg_playerColors[udg_PlayerNumberOfWhoseTurn] + GetPlayerName(Player(udg_PlayerNumberOfWhoseTurn)) + udg_colorEnd + " was randomly selected to go first")
            return
        else
            if i == 11 then
                set i = GetRandomInt(0, 10)
            else
                set i = i + 1
            endif
        endif
    endloop
endfunction
   

   
   
function AtleastTwo takes group g returns boolean
    local integer i = 0
    local unit u
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
            call GroupRemoveUnit(g, u)
            set i = i + 1    
    endloop
    if i >= 2 then
        set u = null
        return true
    else
        set u = null
        return false
    endif
endfunction

function BoardSetUp takes nothing returns nothing
    local unit u
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', 0, 0, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', 0, 128, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', -128, 128, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', 128, 128, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', -128, 0, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', 128, 0, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', -128, -128, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', 128, -128, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'h002', 0, -128, 270)
        call SetUnitAnimationByIndex(u, 1)
        call UnitRemoveAbility(u, 'Amov')
    set u = null
endfunction

function AutoSelect takes nothing returns nothing
    local integer i = 0
    local integer i2 = GetRandomInt(1, 12)
    local integer Garithos = 'h003'
    local integer PitLord = 'h007'
    local integer Rexxar = 'h005'
    local integer Tinker = 'h006'
    local integer BladeMaster = 'h00B'
    local integer Balnazzar = 'h00A'
    local integer Maiev = 'h001'
    local integer Sylvanas = 'h009'
    local integer Jaina = 'h00F'
    local integer Tyrande = 'h00E'
    local integer Alchemist = 'h00C'
    local integer Antonidas = 'h00D'

    local integer whichMarker
    loop
        exitwhen i > 11
        if udg_UnitIdForMarkers[i] == 0 then
            if i2 == 1 then
                set whichMarker = Garithos
            elseif i2 == 2 then
                set whichMarker = PitLord
            elseif i2 == 3 then
                set whichMarker = Rexxar
            elseif i2 == 4 then
                set whichMarker = Tinker
            elseif i2 == 5 then
                set whichMarker = BladeMaster
            elseif i2 == 6 then
                set whichMarker = Balnazzar
            elseif i2 == 7 then
                set whichMarker = Maiev
            elseif i2 == 8 then
                set whichMarker = Sylvanas
            elseif i2 == 9 then
                set whichMarker = Jaina
            elseif i2 == 10 then
                set whichMarker = Tyrande
            elseif i2 == 11 then
                set whichMarker = Alchemist
            elseif i2 == 12 then
                set whichMarker = Antonidas
            endif
        set udg_UnitIdForMarkers[i] = whichMarker
        call DisplayTextToPlayer(Player(i), 0,0, "You randomed " + udg_playerColors[6] + GetObjectName(whichMarker) + udg_colorEnd + " as your marker.")
        endif
        set i = i + 1
    endloop

endfunction

function StartEarly takes nothing returns boolean
    local integer i = 0
    local integer i2 = 0
        loop
        exitwhen i > 11
            if udg_StartEarly[i] == true then
                set i2 = i2 + 1
            else        
            endif
            if i2 == 12 then
            //call BJDebugMsg("Everyone picked, going early")
            return true
            endif
        set i = i + 1
        endloop
 return false      

endfunction

function RemoveSelectors takes nothing returns nothing
    local unit u
        loop
            set u = FirstOfGroup(selectors)
            exitwhen u == null
            call RemoveUnit(u)
            call GroupRemoveUnit(selectors, u)
        endloop
    call DestroyGroup(selectors)
    set u = null
    set selectors = null

endfunction

function CreateBuilders takes nothing returns group
    local integer i = 0
    local unit u2
    local group g = CreateGroup()
       loop
        exitwhen i > 11
                if IsPlaying(Player(i)) and udg_Spectating[i] == 1 then
                    set u2 = CreateUnit(Player(i), 'h004', 0, 0, 270)
                    set udg_Builders[GetPlayerId(Player(i))] = u2
                    call GroupAddUnit(g, u2)
                    call SelectUnitForPlayerSingle(u2, Player(i))
                    set udg_ToggleBuilding[GetPlayerId(Player(i))] = CreateUnit(Player(i), 'H008', 0, 0 , 270)
                    call KillUnit(udg_ToggleBuilding[GetPlayerId(Player(i))])
                endif
        set i = i + 1
        endloop
    set u2 = null
    return g
endfunction

function CleanUpStart takes nothing returns nothing
    local integer i = 0
    local group g
    local boolean check
    set count = count + 1
    call EnableSelect(true, true) // I think this is necessary, although I haven't needed it.  How? If a new game starts players ought to be prevented, haven't had the problem though? Why.
    if StartEarly() == true or count == 30 then
        set udg_TooLate = true
        call RemoveUnit(Tavern)
        call PauseTimer(t)
        call DestroyTimer(t)
        call PauseTimer(t2)
        call DestroyTimer(t2)
        call DestroyTimerDialog(b)
        call RemoveSelectors()
        call AutoSelect()
        call BoardSetUp()
        call SetGoldToTurns(false)
        set g = CreateBuilders()        
        set check = AtleastTwo(g)
        set udg_PreGame = false
        set count = 0
        set check = true
        if check == true then
            call TurnSelect()
            call PreventPlay()
        set t = null
        set t2 = null
        set b = null
        call DestroyGroup(g)
        set g = null
        else
            call BJDebugMsg(udg_playerColors[0] + "Error" + udg_colorEnd + " Not enough people are playing, must be at least" + udg_playerColors[4] + " 2")
                //Rerun starting functions
            set t = null
            set t2 = null
            set b = null
            call DestroyGroup(g)
            set g = null
            call TriggerExecute(gg_trg_Restart)
        endif
    endif
endfunction


function GameStart takes nothing returns nothing
    local unit u
    local integer i = 0
    set selectors = CreateGroup()
    set Tavern = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'n000', 0, 0, 270)
    set t = CreateTimer()
    set t2 = CreateTimer()
    set b = CreateTimerDialog(t2)
    call TimerStart(t, 1., true, function CleanUpStart)
    call TimerStart(t2, 30., false, null)
    call TimerDialogDisplay(b, true)
    call TimerDialogSetTitle(b, "Time To Pick")
    loop
        exitwhen i > 11
        if IsPlaying(Player(i)) then
            set u = CreateUnit(Player(i), 'h000', 0, 0, 270)
            call GroupAddUnit(selectors, u)
            call SelectUnitForPlayerSingle(Tavern, Player(i))
        else
            set udg_StartEarly[i] = true
        endif
        set i = i + 1
    endloop
    set u = null
endfunction


endlibrary
Untitled Trigger 002
  Events
    Player - Player 1 (Red) skips a cinematic sequence
    Player - Player 1 (Red) types a chat message containing 2 as An exact match
  Conditions
  Actions
    Set TempPlayer = Player 1 (Red)
    Custom script: if GetLocalPlayer() == udg_TempPlayer then
    Custom script: call EnableSelect(false, true)
    Custom script: endif
    Set TempPlayer = Player 2 (Blue)
    Custom script: if GetLocalPlayer() == udg_TempPlayer then
    Custom script: call EnableSelect(true, true)
    Custom script: endif
Untitled Trigger 002 Copy
  Events
    Player - Player 1 (Red) types a chat message containing 1 as An exact match
  Conditions
  Actions
    Set TempPlayer = Player 1 (Red)
    Custom script: if GetLocalPlayer() == udg_TempPlayer then
    Custom script: call EnableSelect(true, true)
    Custom script: endif
    Set TempPlayer = Player 2 (Blue)
    Custom script: if GetLocalPlayer() == udg_TempPlayer then
    Custom script: call EnableSelect(false, true)
    Custom script: endif
Untitled Trigger 003
  Events
  Conditions
  Actions
    Leaderboard - Create a leaderboard for (All players) titled 3
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Untitled_Trigger_006_Actions takes nothing returns nothing
call BJDebugMsg("Order ID: " + I2S(GetIssuedOrderId()))
endfunction

//===========================================================================
function InitTrig_Order_Id_Detector takes nothing returns nothing
    set gg_trg_Order_Id_Detector = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Id_Detector, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Id_Detector, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Id_Detector, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_Order_Id_Detector, function Trig_Untitled_Trigger_006_Actions )
endfunction

 
Untitled Trigger 006
  Events
    Time - Elapsed game time is 1.00 seconds
  Conditions
  Actions
    Custom script: call Solo()
    Custom script: call GameStart2()
    Custom script: call CreateDialog2()
    Custom script: call BoardSetUpRM()
Untitled Trigger 007
  Events
  Conditions
  Actions