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 = 039;h000039;//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
- 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
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.