[Tutorial] - How to make the game check who is the host

ragingspeedhorn

Is a Banned Asshole
Reaction score
94
I didn't knew such tutorial existed, I don't even have an account on that website. I actually only think I have visited it 1 or 2 times ever and that is long ago. This tutorial was made by me with guidance from my friend Zoxc :)
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
FYI, this isn't bug proof.
If the host is tabbed out from the game another player may have a faster response time and will be flagged as host by that function.

I suggest that you take the player that is flagged as host the most times out of 5 tests that are spread out a few seconds.
 

ragingspeedhorn

Is a Banned Asshole
Reaction score
94
Really? I have never experienced such problem, please post your suggestion on how to "spreading it out" as you say because I am not exactly sure what you mean :)
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
It is discussed in the thread that Evan posted, it also mentions the problem when the host leaves.

I suggest something like this:
1 variable
player udg_Host = null

JASS:
function GetHostId takes nothing returns integer
    //This stores the Id + 1 for each player.
    call StoreInteger(GameCache(), "missionKey", "key", GetPlayerId(GetLocalPlayer()) + 1)
    //Setup the TriggerSyncReady call.
    call TriggerSyncStart()
    //Sync the value of the entry for each player.
    //Each value will sync to the value of the host.
    call SyncStoredInteger(GameCache(), "missionKey", "key")
    //Wait until the Game Cache syncs the key for everyone.
    call TriggerSyncReady()
    //Return the synced value as a id.
    return GetStoredInteger(GameCache(), "missionKey", "key") - 1
endfunction

function GetHostAverage takes nothing returns nothing
    local integer array id
    local integer max = 0
    local integer t = 0
    local integer i = 0
    set udg_Host = null
    loop
         exitwhen i > 11
         set id<i> = 0
         set i = i + 1
    endloop
    set i = 0
    loop
         exitwhen i &gt; 5         
         set t = GetHostId()
         set id[t] = id[t] + 1
         if id[t] &gt; id[max] then
                set max = t
         endif
         set i = i + 1
         call TriggerSleepAction(1)       
    endloop
    set udg_Host = Player(max)
endfunction</i>


Completely untested ^^
The function GetHostAverage should be called at map init and when the host leaves the game.
If udg_Host is null then the function hasn't found a host.

Note: The GameCache function is unimplemented here and is left as an exercise to the reader. I suggest that you use a game cache that you already use in your map instead of creating a completely new one. If your map is gamecache free then you have no other choice of course.
 

ragingspeedhorn

Is a Banned Asshole
Reaction score
94
I am not that keen with jass but let me get this right, so when the host leaves the game run a similar check and it takes the second guy which joined the game?
 

ragingspeedhorn

Is a Banned Asshole
Reaction score
94
Hmm, I don't know how handy the part with picking a new "leader" after the original host is gone is, the host usually leaves for a reason (unless he lags out or something like that).

Anyways as said I am not the best jasser (actually I stink) so to get this new way of doing it to work I need to replace your lines of coding with the ones that I had and then call "GetHostAverage" instead of "gethost()" in the Map Inilization trigger and replace the variable I have now with your suggestion?

Just to make sure I got it right ^^
 

MrApples

Ultra Cool Member
Reaction score
78
If anything this is free trigger code... but seems more like your having a problem with it and this is a help thread.
 

ragingspeedhorn

Is a Banned Asshole
Reaction score
94
MrApples said:
If anything this is free trigger code... but seems more like your having a problem with it and this is a help thread.

Well I had no problem with the normal gethost() code, it worked fine for me and I didnt even knew that it could bug up untill I was told here, but since I am not the best at jass I just wanted to make sure I got everything right with the more efficient way the other guy gave. But yes this might be more of a free trigger code than tutorial so this should just be locked and trashed or something.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Well, if you add a 'How do this work' to the post then it's a tutorial ^^.
The theory behind this code is pretty interesting, I didn't know how the Sync functions worked before I read this function.

BTW, there is no need to close a thread just becuse it isn't a tutorial.
 

Grundy

Ultra Cool Member
Reaction score
35
another thing you can do is add a trigger for a player message event

e: player 1-12 types -check host as an exact match
c:
a: set udg_Host = Player( GetHostId() )

incase the host is tabbed out and someone else gets flagged as the host, when the host comes back in he can type "-check host" and he will be flagged as the host


wait...why does this not work for me? when i try to put this function in my map it highlights this line
call StoreInteger( GameCache(), "missionKey", "key", (GetPlayerId(GetLocalPlayer())+1) )
and it says "Expected a name"
 
L

Lordbevan

Guest
The JASS trigger isnt exact. U need to make ur own GameCache().
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top