|
 |
|

September 23rd, 2009, 11:05 PM
|
 |
My world. Not yours.
|
|
Join Date: Jun 2008
Posts: 4,000
|
|
|
GetHost 2.0
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.
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), 'hfoo', 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
Last edited by Azlier; September 24th, 2009 at 09:14 PM.
|

September 23rd, 2009, 11:13 PM
|
 |
Is known to say things. That is all.
|
|
Join Date: Jul 2008
Location: <Insert JASS Joke Here>
Posts: 1,657
|
|
|
Missing initializer, Host variable is private, no GetHost() function, there's no GetTriggerPlayer() for regular unit events (unless that's not true and that's how it works?), and SELECTED is misspelled in the unit event line.
|

September 23rd, 2009, 11:14 PM
|
 |
My world. Not yours.
|
|
Join Date: Jun 2008
Posts: 4,000
|
|
|
Blah. I wish I checked it.
I hate not having WC3.
Also, GetOwningPlayer(GetTriggerUnit()) won't quite work. Does... GetTriggerPlayer work in selection cases like this?
If not, I'll need to use PlayerUnitEvents.
|

September 23rd, 2009, 11:18 PM
|
 |
Is known to say things. That is all.
|
|
Join Date: Jul 2008
Location: <Insert JASS Joke Here>
Posts: 1,657
|
|
Oh and your Initializer returns boolean, and host will return null until someone leaves, I believe...
Could you explain how this is supposed to work?
|

September 23rd, 2009, 11:19 PM
|
 |
My world. Not yours.
|
|
Join Date: Jun 2008
Posts: 4,000
|
|
|
Simple, really. When selecting a unit via triggers, delay actually kicks in for the firing of the selection event. The player with the absolute lowest delay (host) will be registered first.
>host will return null until someone leaves, I believe...
Can't... stop... FAILING!
|

September 23rd, 2009, 11:28 PM
|
 |
Is known to say things. That is all.
|
|
Join Date: Jul 2008
Location: <Insert JASS Joke Here>
Posts: 1,657
|
|
|
Yeah this really won't work, sorry Azlier. You need to use the player unit event in order to get a GetTriggerPlayer() to return an actual player. The selection thing can only really work if you are storing a different value for each player, which means that you have to use GetLocalPlayer() to select the unit locally so there's no net traffic.
|

September 23rd, 2009, 11:29 PM
|
 |
My world. Not yours.
|
|
Join Date: Jun 2008
Posts: 4,000
|
|
|
>The selection thing can only really work if you are storing a different value for each player,
...Hmm? If the game decides to wait, and fire all at once, it won't work. Experience shows that it doesn't do that, but if it does... I have another method to try. Azlier always has something up his sleeve!
>You need to use the player unit event in order to get a GetTriggerPlayer() to return an actual player.
So be it.
|

September 23rd, 2009, 11:32 PM
|
 |
Is known to say things. That is all.
|
|
Join Date: Jul 2008
Location: <Insert JASS Joke Here>
Posts: 1,657
|
|
Hmm it depends whether SelectUnit() actually sends any net traffic... I can't be sure. Anyway let me test it
|

September 23rd, 2009, 11:34 PM
|
 |
My world. Not yours.
|
|
Join Date: Jun 2008
Posts: 4,000
|
|
SelectUnit is unsynced at first, but it soon syncs itself out (I assume it takes the maximum delay time). SyncSelections does it immediately.
I'll soon need to patch this to work in the event that the host leaves and the players have filled selection groups.
|

September 23rd, 2009, 11:38 PM
|
 |
Is known to say things. That is all.
|
|
Join Date: Jul 2008
Location: <Insert JASS Joke Here>
Posts: 1,657
|
|
|
I just tested it in single player, it returns Player 16 as the host. Stand by for bnet test.
|

September 23rd, 2009, 11:39 PM
|
 |
My world. Not yours.
|
|
Join Date: Jun 2008
Posts: 4,000
|
|
That can't be good. Player 16 doesn't exist.
I know what you mean, however.
GetTriggerPlayer returns the owner of the unit?
How useless. I'll need to resort my other method. Tomorrow... tomorrow...
|

September 23rd, 2009, 11:44 PM
|
 |
Is known to say things. That is all.
|
|
Join Date: Jul 2008
Location: <Insert JASS Joke Here>
Posts: 1,657
|
|
|
Player 16, as in Player(15), since I'm using GetPlayerName().
|

September 23rd, 2009, 11:45 PM
|
 |
My world. Not yours.
|
|
Join Date: Jun 2008
Posts: 4,000
|
|
|
Ah. Other method it is, then. I hate Blizzard.
|

September 24th, 2009, 12:26 AM
|
|
Good Idea™
|
|
Join Date: Jul 2007
Location: Australia
Posts: 3,857
|
|
Keep it up guys, I'm sure you'll get this working. 
+rep
|

September 24th, 2009, 09:13 AM
|
 |
My world. Not yours.
|
|
Join Date: Jun 2008
Posts: 4,000
|
|
This is totally untested. It gets the player in Single Player, however. So I'll assume it works, but I still need real tests.
Jass:
library GetHost initializer Init
globals
private unit array U
private player Host = null
endglobals
constant function GetHost takes nothing returns player
return Host
endfunction
private function CalculateHost takes nothing returns boolean
if Host == null then
set Host = GetOwningPlayer(GetTriggerUnit())
endif
return false
endfunction
private function RecalculateHost takes nothing returns boolean
local integer i = 11
set Host = null
loop
if GetLocalPlayer() == Player(i) then
call SelectUnit(U[i], true)
call SelectUnit(U[i], false)
endif
exitwhen i == 0
set i = i - 1
endloop
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 11
call TriggerAddCondition(t, Condition(function CalculateHost))
loop
set U[i] = CreateUnit(Player(i), 'hfoo', 10000, 10000, 270)
call PauseUnit(U[i], true)
call TriggerRegisterUnitEvent(t, U[i], EVENT_UNIT_SELECTED)
if GetLocalPlayer() == Player(i) then
call SelectUnit(U[i], true)
call SelectUnit(U[i], false)
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
Last edited by Azlier; September 24th, 2009 at 10:02 AM.
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|