[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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top