• 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.

[Snippet] GetLatency (Ping)

Use the function to find out how long it takes for a player to communicate with the host (ping).

JASS:
library GetLatency requires TimerUtils

    globals
        private gamecache Cache = InitGameCache(SCOPE_PREFIX)
    endglobals
    
    function GetLatency takes nothing returns integer
        local timer t = NewTimer()
        local real elapsed
        
        call TimerStart(t, 0.006, true, null)
        call FlushGameCache(Cache)
        call StoreInteger (Cache, "0", "0", GetPlayerId(GetLocalPlayer()))
        call TriggerSyncStart()
        call SyncStoredInteger(Cache, "0", "0")
        call TriggerSyncReady()
        call GetStoredInteger (Cache, "0", "0")
        call FlushStoredMission(Cache ,"0")
        
        set elapsed = TimerGetElapsed(t)
        call ReleaseTimer(t)
        
        return R2I(elapsed * 1000)
    endfunction
    
endlibrary

I really need someone to test this online, I'm not 100% sure it works.
 
Last edited:
It pauses the thread, but it doesn't wait until a synchronization is complete.

When does it fail to wait for the synchronization? Just curious, I haven't stress tested it. I just know it works consistently with a small number of synchronizations (at least on LAN, I haven't tested it on BNet).

edit: Nvm, explained in chat.
 
Last edited:
Top