1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  4. The reforging of the races is complete. Come see the 14th Techtree Contest Results.
    Dismiss Notice
  5. It's time to choose your horse in the race - the 32nd Modeling Contest Poll is up!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Hostfinder

Discussion in '"Graveyard"' started by ragingspeedhorn, Sep 12, 2006.

  1. ragingspeedhorn

    ragingspeedhorn

    Joined:
    Apr 30, 2005
    Messages:
    6,521
    Resources:
    14
    Icons:
    5
    Maps:
    7
    Tutorials:
    2
    Resources:
    14
    by: ragingspeedhorn

    Note: I did not discover this code, the original author is "Tennis" from www.wc3jass.com. All credits go to him, this is only a guide on how you implement it.

    Description
    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.
    [​IMG]

    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):
    Code (vJASS):
    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.
    [​IMG]

    Final note: This is not 100% stable, the gethost() can fail sometimes and select another player, however that is quite rare.

    Edit by Pyritie: graveyarded due to duplicate
     
    Last edited by a moderator: May 27, 2009