Warcraft III resources & community, 2003–2006 · archived

How to make the game check who is the host

14 posts
#1

How to make the game check who is the host

[h1]How to make the game check who is the host.[/h1]

A tutorial by: ragingspeedhorn

Note: I did not discover this code, the original author is "Tennis" from www.wc3jass.com.

Many maps uses the "player1 (red) = guy who decides everything", that is annoying because the host might not want to play as red but still wants to control the stuff which the host sometimes can do (as an example, difficulty settings, player 1 (red) is in a large number of maps able to set the difficulty of the game through a dialog or something similar).

But what most people probably didn't knew is that with just a very small amount of custom scripts (Jass) and 1 variable you can detect who is the host.

So here it goes, the 3 easy steps on how to create the variable and make the custom scripts.


[h2]Step 1: The Variable.[/h2]

Create a new variable, name it "Host", set the variable type to "Player (player)", do not check out the Aray box and leave the initial value at none like I have done in the picture below.

http://www.hiveworkshop.com/forums/attachments/miscellaneous-tutorials-456/3756d1174391706-how-to-make-the-game-check-who-is-the-host-variable5xf.jpg


[h2]Step 2: Custom Script Header.[/h2]

Right, you have your variable now it is time to get the hardest part done. In the Trigger Editor you click at the top at the maps name like if it was any other trigger, in there you paste these lines of code (Make sure you paste it at the top):

function GetHost takes nothing returns nothing
    local gamecache g = InitGameCache("Map.w3v")
    call StoreInteger ( g, "Map", "Host", GetPlayerId(GetLocalPlayer ())+1)
    call TriggerSyncStart ()
    call SyncStoredInteger ( g, "Map", "Host" )
    call TriggerSyncReady ()
    set udg_Host = Player( GetStoredInteger ( g, "Map", "Host" )-1)
    call FlushGameCache( g )
    set g = null
endfunction


[h2]Step 3: Getting The Host.[/h2]

Now that you have the most of the work done you just need to make a last simple trigger where you set the event to Map initialization, conditions you leave untouched and in the actions you make a custom script like this: "Custom script: call GetHost()". Now it has checked who is the host and stored it in the variable, for further use you just need to address everything to the "Host" variable like you would usually do to Player 1 (red), it is as simple as that.

Start of the map
Events
Game - Elapsed game time is 0.02 seconds
Conditions
Actions
Custom script: call GetHost()


Final note: This is not 100% stable, the gethost() can fail sometimes and select another player, however that is quite rare.
#2
first of all thank u for the tutorial its quite handy to know which player is the host :)

now just a little tips for idiots like me lol make sure u create the variable "Host" with a capital H ... or else it doesnt work lol... sorry if to everyone here it seems obvious but to a new boy in map making like me its not obvious :)
#3
dixingfirst of all thank u for the tutorial its quite handy to know which player is the host :)


I am glad I could help, though the real guy to thank is "Tennis" since it was him who discovered this handy litle thing to begin with :)
#4
How do I create a varaible that is Player (player)? The closest I can make is just player -.-.

Does this require some sort of custom editor?
#5
Nope, it does not require any custom WE. I do not know why yours is not Player (player), is it in a foreign language?
#6
Mine just says Player too instead of Player(player). I'm using the USA, English version. It might be diffrent versions of map editor or are you in the UK?
#7
InsanebirdMine just says Player too instead of Player(player). I'm using the USA, English version. It might be diffrent versions of map editor or are you in the UK?


I am from Denmark, I am using the standard English version of Wc3 TFT.
#8
are you completey patched up? Mine in Alberta (Canada) has just player as well.
#9
Newest version of the WE and Wc3, well it does not matter anyways, it is the same thing I am pretty sure of :P
#10
Thx man I rly needed that...I think?
#11
Ok.. Thats a cool script..
But i dont understand what you mean with at the top of the scripts.. U mean in trigger coments? or in my variable? and what shall i do when i use the variable?


Please help, and please do it fast
#12
Ok.. Thats a cool script..
But i dont understand what you mean with at the top of the scripts.. U mean in trigger coments? or in my variable? and what shall i do when i use the variable?


Please help, and please do it fast.
Thank you for the help and the time.
#13
zero_ZXOk.. Thats a cool script..
But i dont understand what you mean with at the top of the scripts.. U mean in trigger coments? or in my variable? and what shall i do when i use the variable?


Please help, and please do it fast.
Thank you for the help and the time.


I mean the little map icon/name of map which is in top in the trigger editor, just above the yellow folders that organize the triggers. Paste the first line of code in there.
#14
Ah okay. Thank you so much.. :D
The conversation continued. After wc3sear.ch closed, 2 further replies were posted to this thread on The Hive Workshop. Read them there →