• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

GetGameHost

This snippet retrieves the game host of a lobby. Credits for the idea of the method go to TriggerHappy (so I am told).

GUI users: Create a global named GameHost and change the GameHost in the code to udg_GameHost.

Lua:
if Debug then Debug.beginFile "GetGameHost" end
do
    --=============================================================================================================================================================
    --Retrieves the game host and stores it in the global GameHost. The game host is not available directly after map initialization, but only after one sync cycle.
    --=============================================================================================================================================================

    local startTime = os.clock()

    local timeDeltas = {}

    local function SyncTimeDelta()
        if BlzGetTriggerSyncPrefix() ~= "SyncTimeDelta" then
            return
        end

        local data = BlzGetTriggerSyncData()

        local playerId, delta = data:match("(\x25d+),(.+)")
        timeDeltas[tonumber(playerId)] = delta

        local player
        for i = 0, bj_MAX_PLAYER_SLOTS - 1 do
            player = Player(i)
            if not timeDeltas[i] and GetPlayerSlotState(player) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(player) == MAP_CONTROL_USER then
                return
            end
        end

        local highestDelta
        local highestId
        for playerId, delta in pairs(timeDeltas) do
            if not highestDelta or delta > highestDelta then
                highestDelta = delta
                highestId = playerId
            end
        end

        GameHost = Player(highestId)
        DestroyTrigger(GetTriggeringTrigger())
    end

    local old = MarkGameStarted
    MarkGameStarted = function()
        old()

        local trig = CreateTrigger()
        for i = 0, bj_MAX_PLAYER_SLOTS - 1 do
            BlzTriggerRegisterPlayerSyncEvent(trig, Player(i), "SyncTimeDelta", false)
        end
        TriggerAddAction(trig, SyncTimeDelta)

        local endTime = os.clock()
        local delta = endTime - startTime

        BlzSendSyncData("SyncTimeDelta", GetPlayerId(GetLocalPlayer()) .. ",".. tostring(delta))
    end
end
Contents

GetGameHost (Binary)

Reviews
Wrda
Works as expected. Approved
Top