Azlier
Old World Ghost
- Reaction score
- 461
This gets the host of a game. Remember that rather unreliable game cache syncing version? This is faster, and possible more reliable.
But, GetHost does not work on Map Initialization. Using TriggerRegisterHostDetected will fire any triggers registered to it immediately after a host is found. GetHost can be used in those triggers.
OnHostDetect is much the same, but it takes and fires a code variable instead. This action cannot be undone. The code must return a boolean, preferably false.
GetHost returns the host of a game. Once again, it doesn't work on map initialization.
Requires Event.
But, GetHost does not work on Map Initialization. Using TriggerRegisterHostDetected will fire any triggers registered to it immediately after a host is found. GetHost can be used in those triggers.
OnHostDetect is much the same, but it takes and fires a code variable instead. This action cannot be undone. The code must return a boolean, preferably false.
GetHost returns the host of a game. Once again, it doesn't work on map initialization.
Requires Event.
JASS:
library GetHost initializer Init requires Event
globals
private unit array U
private player Host = null
private trigger OnDetect = CreateTrigger()
private group Group = CreateGroup()
private unit Enummed = null
private Event Ev
endglobals
constant function GetHost takes nothing returns player
return Host
endfunction
function OnHostDetect takes code c returns nothing
call TriggerAddCondition(OnDetect, Condition(c))
endfunction
function TriggerRegisterHostDetected takes trigger t returns nothing
call Ev.register(t)
endfunction
private function CalculateHost takes nothing returns boolean
if Host == null then
set Host = GetOwningPlayer(GetTriggerUnit())
call TriggerEvaluate(OnDetect)
call Ev.fire()
endif
return false
endfunction
private function FindSelected takes nothing returns boolean
if Enummed == null then
set Enummed = GetFilterUnit()
endif
return false
endfunction
private function RecalculateHost takes nothing returns boolean
local integer i
if GetTriggerPlayer() == Host then
set i = 11
set Host = null
loop
set Enummed = null
call GroupEnumUnitsSelected(Group, Player(i), Filter(function FindSelected))
if GetLocalPlayer() == Player(i) then
call SelectUnit(Enummed, false)
call SelectUnit(U<i>, true)
call SelectUnit(U<i>, false)
call SelectUnit(Enummed, true)
endif
exitwhen i == 0
set i = i - 1
endloop
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 11
set Ev = Event.create()
call TriggerAddCondition(t, Condition(function CalculateHost))
loop
set U<i> = CreateUnit(Player(i), 039;hfoo039;, 10000, 10000, 270)
call PauseUnit(U<i>, true)
call TriggerRegisterUnitEvent(t, U<i>, EVENT_UNIT_SELECTED)
set Enummed = null
call GroupEnumUnitsSelected(Group, Player(i), Filter(function FindSelected))
if GetLocalPlayer() == Player(i) then
call SelectUnit(Enummed, false)
call SelectUnit(U<i>, true)
call SelectUnit(U<i>, false)
call SelectUnit(Enummed, true)
endif
exitwhen i == 0
set i = i - 1
endloop
set t = CreateTrigger()
set i = 11
loop
call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_LEAVE)
exitwhen i == 0
set i = i - 1
endloop
call TriggerAddCondition(t, Condition(function RecalculateHost))
endfunction
endlibrary</i></i></i></i></i></i></i>