Here are my functions
Spawns heroes to select from and initiates at timer.
EndHeroSelection function
the waits break the thread when called from the timer function. However, it works fine when triggered via all heroes select.
Spawns heroes to select from and initiates at timer.
JASS:
function Selection_time takes nothing returns nothing
local integer i = 1
local unit u = null
set i = 1
loop
exitwhen i > udg_numberofplayers
if (CheckPlayer(i-1)) then
if (g_selected<i>==false) then
set u = GroupPickRandomUnit(g_group)
call GroupRemoveUnit(g_group,u)
set udg_selection_hero<i>=u
call DisplayTimedTextToForce(GetPlayersAll(),4.0,g_playercolor<i>+GetPlayerName(Player(i-1))+"|r has picked "+EVENT+GetUnitName(u)+"|r.")
endif
endif
set i = i + 1
endloop
call BJDebugMsg("TEST")
call EndHeroSelection()
call BJDebugMsg("TEST2")
endfunction
selects heroes, and ends the selection when everyone has pick a hero.
function Trig_set_up_heroes_Actions takes nothing returns nothing
local integer i = 1
local integer index = 0
local integer imax=4
local integer a= 1
local location point = GetRectCenter(gg_rct_HS_start_point)
local location point2
local unit u = null
local string fx="Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl"
set g_timer= CreateTimer()
set g_group = CreateGroup()
call DisplayTextToForce(GetPlayersAll(),EVENT+"Select a Hero:|r Click on a hero you wish to play as.")
call DisplayTextToForce(GetPlayersAll(),HINT+"You may only pick a hero not selected by another player.|r")
call TriggerExecute(gg_trg_vision)
call Reveal(true)
loop
exitwhen i>udg_numberofplayers
set g_selected<i>=false
set i = i+1
endloop
set i = 1
loop
exitwhen i > imax
set a = 1
loop
exitwhen a > 4
set point2 = OffsetLocation(point, I2R( ModuloInteger(a-1, 4) * 200 ), I2R( i * -200 ))
call CreateNUnitsAtLoc( 1, udg_heroes[((i-1)*4)+a-1], Player(PLAYER_NEUTRAL_PASSIVE), point2, 270.00 )
call GroupAddUnit(g_group,GetLastCreatedUnit())
call UnitRemoveAbility(GetLastCreatedUnit(),039;Amov039;)
call UnitRemoveAbility(GetLastCreatedUnit(),039;Aatk039;)
call UnitAddAbility(GetLastCreatedUnit(),039;A999039;)
call special_effect(fx,point2)
set a = a + 1
endloop
call TriggerSleepAction(1.0)
set i = i + 1
endloop
set udg_selection_ready = true
call TimerStart(g_timer,30.00,false,function Selection_time)
set g_timerdialog=CreateTimerDialog(g_timer)
call TimerDialogDisplay(g_timerdialog,true)
call RemoveLocation(point)
endfunction</i></i></i></i>
JASS:
function Trig_selection_method_Func001Func001C takes integer i, unit u returns boolean
if ( not ( udg_selection_hero<i> == u ) ) then
return false
endif
return true
endfunction
function Trig_selection_method_Actions takes nothing returns nothing
local boolean bool = false
local unit u = GetTriggerUnit()
local player p = GetTriggerPlayer()
local integer i = 1
local integer imax = udg_numberofplayers
if (udg_selection_ready == true) then
if (IsUnitType(u, UNIT_TYPE_HERO)) then
loop
exitwhen i > imax
if ( Trig_selection_method_Func001Func001C(i, u) ) then
set bool = true
endif
set i = i + 1
endloop
if (g_selected[GetConvertedPlayerId(p)]==false) then
if (bool == false) then
call SetUnitOwner( udg_selection_hero[GetConvertedPlayerId(p)], Player(PLAYER_NEUTRAL_PASSIVE), true )
call SelectUnitForPlayerSingle( u, p )
call SetUnitOwner( u, p, true )
set udg_selection_hero[GetConvertedPlayerId(p)] = u
endif
endif
endif
endif
endfunction
function PickHero takes nothing returns nothing
local player p = GetOwningPlayer(GetSpellAbilityUnit())
local unit u = GetSpellAbilityUnit()
local integer i = 0
local boolean bool = true
local string fx="Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl"
local location point
local group g = CreateGroup()
if (g_selected[GetConvertedPlayerId(p)]==false) then
if (GetSpellAbilityId()==PICKHERO) then
set g_selected[GetConvertedPlayerId(p)]=true
call UnitRemoveAbility(u,PICKHERO)
call DisplayTimedTextToForce(GetPlayersAll(),99999,g_playercolor[GetConvertedPlayerId(p)]+GetPlayerName(Player(GetConvertedPlayerId(p)-1))+"|r has picked "+EVENT+GetUnitName(udg_selection_hero[GetConvertedPlayerId(p)])+"|r.")
loop
exitwhen i>udg_numberofplayers
if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
if (GetPlayerController(Player(i)) == MAP_CONTROL_USER) then
if (g_selected[i+1]==false) then
set bool = false
endif
endif
endif
set i = i + 1
endloop
//change into a seperate function
if (bool==true) then
call EndHeroSelection()
endif
endif
endif
endfunction
//===========================================================================
function InitTrig_selection_method takes nothing returns nothing
local trigger selection_method = CreateTrigger( )
local trigger changeoption = CreateTrigger( )
call TriggerRegisterPlayerSelectionEventBJ( selection_method, Player(0), true )
call TriggerRegisterPlayerSelectionEventBJ( selection_method, Player(1), true )
call TriggerRegisterPlayerSelectionEventBJ( selection_method, Player(2), true )
call TriggerRegisterPlayerSelectionEventBJ( selection_method, Player(3), true )
call TriggerRegisterPlayerSelectionEventBJ( selection_method, Player(4), true )
call TriggerRegisterPlayerSelectionEventBJ( selection_method, Player(5), true )
call TriggerAddAction( selection_method, function Trig_selection_method_Actions )
call TriggerRegisterPlayerUnitEventSimple( changeoption, Player(0), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterPlayerUnitEventSimple( changeoption, Player(1), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterPlayerUnitEventSimple( changeoption, Player(2), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterPlayerUnitEventSimple( changeoption, Player(3), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterPlayerUnitEventSimple( changeoption, Player(4), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterPlayerUnitEventSimple( changeoption, Player(5), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddAction( changeoption, function PickHero )
endfunction
</i>
EndHeroSelection function
JASS:
function EndHeroSelection takes nothing returns nothing
local integer i = 1
local location point
local string fx="Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl"
call PolledWait(2.0)
set i = 1
loop
exitwhen i>udg_numberofplayers
if (GetPlayerSlotState(Player(i-1)) == PLAYER_SLOT_STATE_PLAYING) then
if (GetPlayerController(Player(i-1)) == MAP_CONTROL_USER) then
set point = GetUnitLoc(udg_selection_hero<i>)
call special_effect(fx,point)
set g_selected<i>= true
call SetUnitOwner(udg_selection_hero<i>,Player(PLAYER_NEUTRAL_PASSIVE), true )
call SetUnitPositionLoc(udg_selection_hero<i>,GetRectCenter(gg_rct_hideheroes))
endif
endif
set i = i + 1
endloop
call DestroyTimer(g_timer)
call DestroyTimerDialog(g_timerdialog)
set g_timer=null
set g_timerdialog=null
call PolledWait(2.0)
call CinematicFilterGenericBJ( 1.00, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 100, 100, 100, 100.00, 0, 0, 0, 0 )
call PolledWait(1.1)
call Reveal(false)
set g_setting = 999
call UpdateSelector()
//return
endfunction</i></i></i></i>
the waits break the thread when called from the timer function. However, it works fine when triggered via all heroes select.