• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

How to make the game check who is the host

Status
Not open for further replies.

How to make the game check who is the host.


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.


Step 1: The Variable.


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.

3756d1174391706-how-to-make-the-game-check-who-is-the-host-variable5xf.jpg



Step 2: Custom Script Header.


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):

JASS:
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

Step 3: Getting The Host.


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.
 

Attachments

  • variable5xf.jpg
    variable5xf.jpg
    13.4 KB · Views: 5,895
Last edited by a moderator:
Status
Not open for further replies.
Top