|
用到全局变量 cache 类型游戏缓存
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 StoreInteger(udg_cache,"Player","number",GetPlayerId
(GetLocalPlayer())+1)
call TriggerSyncStart()
call SyncStoredInteger(udg_cache,"Player","number")
//同步每个玩家缓存为主机号
call TriggerSyncReady()
set p=GetStoredInteger(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
|
|