|
function Trig_timedelay_Actions takes nothing returns nothing
local integer i=0
local integer p
local integer array nP
local timer t=CreateTimer()
local real array dt
local real delay
local integer Pnum=0
loop
exitwhen i>=12
set nP=0
set dt=0
set i=i+1
endloop
call DisplayTimedTextToPlayer(GetLocalPlayer(),.0,.0,20.,"正在检测主机及网络延时,请等待......")
set i=1
call TimerStart(t,20.,false,null)
loop
exitwhen i>5
set dt=TimerGetElapsed(t)
call Save(GetPlayerId(GetLocalPlayer())+1,udg_cache,"Player","number")
call TriggerSyncStart()
call SyncStoredInteger(udg_cache,"Player","number") //同步每个玩家缓存为主机号
call TriggerSyncReady()
set p=Load(udg_cache,"Player","number")-1
set nP[p]=nP[p]+1
call FlushStoredMission(udg_cache,"Player")
set dt=TimerGetElapsed(t)-dt //统计第i次延时抽样
call PauseTimer(t)
call PolledWait(1.)
set i=i+1
call ResumeTimer(t)
endloop
set i=0
loop
exitwhen i>=12
if nP[Pnum]<nPthen
set Pnum=i
endif
set i=i+1
endloop
call DestroyTimer(t)
set t=null
set delay=(dt[1]+dt[2]+dt[3]+dt[4]+dt[5])/5. //对5次抽样进行平均(当然越多抽样越好,但是要考虑时间)
call DisplayTimedTextToPlayer(GetLocalPlayer(),.0,.0,10.,"主机 : "+GetPlayerName(Player(Pnum)))
call DisplayTimedTextToPlayer(GetLocalPlayer(),.0,.0,10.,"网络延时 : "+I2S(R2I(delay*1000))+"ms")
endfunction
//===========================================================================
function InitTrig_timedelay takes nothing returns nothing
local integer n = 0
set gg_trg_timedelay = CreateTrigger( )
loop
exitwhen n>= 12
call TriggerRegisterPlayerKeyEventBJ( gg_trg_timedelay, Player(n), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
set n=n+1
endloop
call TriggerAddAction( gg_trg_timedelay, function Trig_timedelay_Actions )
endfunction
貌似是用的缓存 |
|