System GetDelay

cleeezzz

The Undead Ranger.
Reaction score
268
GetDelay v1.0c

Requirements:
-NewGen
(OPTIONAL)
-Vex's dummy model, (Attached)

JASS:

//  ____      _   ____       _             
// / ___| ___| |_|  _ \  ___| | __ _ _   _ 
//| |  _ / _ \ __| | | |/ _ \ |/ _` | | | |
//| |_| |  __/ |_| |_| |  __/ | (_| | |_| |
// \____|\___|\__|____/ \___|_|\__,_|\__, |
//                                   |___/ 
// GetDelay v1.0c
//
//  By cleeezzz, saw792, Jesus4Lyf, and Azlier
//
//  What does it do?
//         -Gets the delay/response time between the host and the players
//        
//    Pros
//         -Don't know, you get the delay (Delay from player to host and then host to player
//
//    Cons
//         -A non-locust unit has to be created somewhere in the map
//         -Calling this function as a player is trying to cast a target spell will cancel target selection
//         -Adding onto the previous con, it is not recommended to check delay with a periodic timer
//
//  How to use:
//         -Set DUMMYID to the raw id of the dummy unit that will detect clicks, DO NOT USE THIS UNIT FOR ANYTHING ELSE.
//         -Whenever you want to refresh everyone's delay, call the function DelayCalc like this --> call DelayCalc(), in GUI, Custom Script: call DelayCalc()
//         -To retrieve a player's delay, use GetDelay(whichplayer) like this --> call GetDelay(Player(0)), which gives the delay of player 1, in GUI, i recommend creating a real variable, Custom Script: set udg_real = GetDelay(Player(0))
//
//  How to import:
//         - Either create a unit specifically for this system, or copy the Dummy unit the map
//         - Create a trigger named GetDelay.
//         - Convert it to custom text and replace the whole trigger text with this.
//
library GetDelay initializer Init
  
globals
    //VALUES BELOW CAN BE MODIFIED
    private constant integer DUMMYID = 'h000'//Can not have locust..., preferably set to Vex's model, dummy.mdx
    private boolean TO_AND_FROM_HOST = false //Gets the time to ping from the player to the host and back. Set to false for just player to host. (Basically half of to and from)
    private real MULTIPLIER = 1000. //If 1000., returns delay in Milliseconds, if 1., returns in Seconds.
    //DO NO MODIFY BEYOND THIS LINE
    private real array D
    private group g = CreateGroup()
    private timer T = CreateTimer()
    private real Game_maxX
    private real Game_maxY
    private unit dummy
endglobals
  
function DelayCalc takes nothing returns nothing
    local integer i = 0
    local unit fog
    if TimerGetRemaining(T) == 0 then
        call ShowUnit(dummy,true)
        loop
            exitwhen i == 12
            call SetUnitOwner(dummy,Player(i),true)
            call GroupClear(g)
            call GroupEnumUnitsSelected(g, Player(i),null)
            if GetLocalPlayer() == Player(i) then    
                call ClearSelection()
                call SelectUnit(dummy, true)
                call ClearSelection()
                loop
                    set fog = FirstOfGroup(g)
                    exitwhen fog == null
                    call SelectUnit(fog, true)
                    call GroupRemoveUnit(g,fog)
                endloop
            endif
            set i = i + 1
        endloop
        call TimerStart(T, 5, false, null)
    endif
endfunction
  
function GetDelay takes player p returns real
    return D[GetPlayerId(p)]
endfunction
  
  //====================================================
private function Conditions takes nothing returns boolean
    if GetUnitTypeId(GetTriggerUnit()) == DUMMYID then
        if TimerGetElapsed(T) != 0 then
            if TO_AND_FROM_HOST == true then
                set D[GetPlayerId(GetTriggerPlayer())] = TimerGetElapsed(T)*MULTIPLIER
            else
                set D[GetPlayerId(GetTriggerPlayer())] = (TimerGetElapsed(T)/2)*MULTIPLIER
            endif
            if GetLocalPlayer() == GetTriggerPlayer() then
                call ShowUnit(dummy,false)
            endif
        endif
    endif
    return false
endfunction
  
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger() 
    set Game_maxX = GetRectMaxX(bj_mapInitialPlayableArea)+50.00
    set Game_maxY = GetRectMaxY(bj_mapInitialPlayableArea)+50.00
    set dummy = CreateUnit(Player(13), DUMMYID, Game_maxX, Game_maxY, 0) 
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SELECTED)
    call TriggerAddCondition(t, Condition(function Conditions))
endfunction
  
endlibrary


CHANGELOG:
1.0c
  • System now creates a universal dummy that is reused. It is shown and hidden to prevent players from selecting it when not checking delay.
  • Added Detail to implementation about dummy unit
1.0b
  • Dummy now spawns slightly outside map bounds (no need for user configuration)
  • Added a Boolean TO_AND_FROM_HOST, if true, returns ping from player to host and back, if false, returns half the ping (or just one way ping)
  • Added a Real MULTIPLIER, if set to 1000., delay will be returned in Milliseconds, if set to 1., delay will be returned in Seconds
1.0 - Initial Release

EXAMPLE USAGE:
JASS:
scope Delay initializer Init

private function Actions takes nothing returns nothing
    local real d
    set d = GetDelay(GetTriggerPlayer())
    call DisplayTextToPlayer( GetTriggerPlayer(),0.,0.,"|cffffcc00Your Delay: |r" + R2S(d) + "|cffffcc00 seconds|r")
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    local integer i
    set i = 0
    loop
        exitwhen i == 12
        call TriggerRegisterPlayerChatEvent( trig, Player(i), "-delay", true )
        set i = i + 1
    endloop
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

scope RD initializer Init
   
private function Actions takes nothing returns nothing
    call DelayCalc()
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic(trig, 10.)
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


The example refreshes delay every 10 seconds and displays delay whenever a player types "-delay"

I don't believe this needs a test map, but oh well.
 

Attachments

  • dummy.mdx
    34.2 KB · Views: 322
  • GetDelay v1.0.w3x
    27.9 KB · Views: 293
  • GetDelay v1.0b.w3x
    28.2 KB · Views: 290
  • GetDelay v1.0c.w3x
    28.5 KB · Views: 351

Troll-Brain

You can change this now in User CP.
Reaction score
85
Are you sure that it works as intended ?
Did you compare it with a tool that give you the real delay ?
Because AFAIK selections got by themselves some delay.
 
Reaction score
341
Are you sure that it works as intended ?
Did you compare it with a tool that give you the real delay ?
Because AFAIK selections got by themselves some delay.

It's not like it needs to be 100% accurate, as long as you get the general idea and the outcome isn't too far off.
 

cleeezzz

The Undead Ranger.
Reaction score
268
selections do have a delay of about .15 ish through my tests. anything above is the delay. but it is a true delay because thats how long it takes for the character to respond, not purely the response time of the connections (those would be slightly faster)

>Did you compare it with a tool that give you the real delay ?

ping tools create a lot of misunderstandings about latency and ping. some are LC ping style (pings cut in half). you may think 300 lat/ping is high, but 300/1000 is only .3 of a second. sure they are faster no matter which tool you use. 1 because of the selection delay but if you think about it, if theres a selection delay, that counts as the delay to control your character as well.
 

cleeezzz

The Undead Ranger.
Reaction score
268
no effects on gameplay, it deselects your current selections and instantly reselects, no visible changes

btw, jesus, can you go on chat lmao.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I suggest to put the dummy unit outside the playable map area (but not outside the entire map) with functions SetUnitX/Y instead of using 2 real constants.
 

RaiJin

New Member
Reaction score
40
I suggest to put the dummy unit outside the playable map area (but not outside the entire map) with functions SetUnitX/Y instead of using 2 real constants.

qft this is a good idea but don't make it to far out or it'll crash
 

cleeezzz

The Undead Ranger.
Reaction score
268
leftover from another trig, i think i deleted it in the test map though, not sure.
 

Nestharus

o-o
Reaction score
84
So, to get the actual delay, you'd do host delay - user delay?

I heard from a few people who tried this that they were getting delays of 700+ when they were host =).
 

Nestharus

o-o
Reaction score
84
Hmmmmm, well.

After talking with Sevion in chat, it sounds like this works for the most part : D

While it is cool, I'm not sure how it would be applied o-o.

I mean, it'd be interesting for a player to get to know their own delay, but I don't see how it'd help or take away from a map ; ).
 

Sevion

The DIY Ninja
Reaction score
424
When we tested (me Cleeezzz and Renny), I felt it was inaccurate :-/ But I'm not sure if it was the same sys. I got ~700+ delay times. It felt more like 300.
 

Sevion

The DIY Ninja
Reaction score
424
I thought so. It seemed like the delays were doubled :-/

Plus he kept going on about something with pings being halved.
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Bump for Approval. (I was asked to by Cleeezzz.)

Edit: Pssh, don't lie, you hinted at it.
 

cleeezzz

The Undead Ranger.
Reaction score
268
i never asked for the bump, anyway, updated to 1.0b
CHANGELOG:
1.0b

* Dummy now spawns slightly outside map bounds (no need for user configuration)
* Added a Boolean TO_AND_FROM_HOST, if true, returns ping from player to host and back, if false, returns half the ping (or just one way ping)
* Added a Real MULTIPLIER, if set to 1000., delay will be returned in Milliseconds, if set to 1., delay will be returned in Seconds

Test Map uploaded, it is set up to show delay in milliseconds.
 
General chit-chat
Help Users

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top