ou99孽缘 发表于 2010-12-14 18:34:04

网络延迟获取-jass版

通过以下代码可以获取同步网络延迟的数值,以下为全部代码,其中ms为自定义的全局整型变量,gc为自定义的全局游戏缓存变量,mb是自定义的全局多面板变量.Clock和DelayClock是自定义的全局计时器变量;不明白的同学请不要随便乱用额.可能引起掉线.
function FreshDelayTime takes nothing returns nothing

   local string s="|cff00ff00"

   if GetLocalPlayer()==Player(0) then

   call StoreInteger(gc,"GameTime","GetDelay",GetStoredInteger(gc,"GameTime","GetDelay")-1)

   endif

   if GetStoredInteger(gc,"GameTime","GetDelay")>500 then

   set s="|cffff0000"

   elseif GetStoredInteger(gc,"GameTime","GetDelay")>250 then

   set s="|cffffff00"

   endif

   call MultiboardSetTitleText(mb,"|cffffffff网络延迟: |r"+s+I2S(GetStoredInteger(gc,"GameTime","GetDelay"))+"|r |cffffffffms|r")

endfunction



function GetDelayTime takes nothing returns nothing

   if GetStoredInteger(gc,"GameTime","LastDelay")!=GetStoredInteger(gc,"GameTime","Delay") then

   call StoreInteger(gc,"GameTime","GetDelay",ms-GetStoredInteger(gc,"GameTime","Delay"))

   call StoreInteger(gc,"GameTime","LastDelay",GetStoredInteger(gc,"GameTime","Delay"))

   call FreshDelayTime()

   endif

endfunction



function DelayTime takes nothing returns nothing

   if GetLocalPlayer()==Player(0) then

   call StoreInteger(gc,"GameTime","Delay",ms)

   call SyncStoredInteger(gc,"GameTime","Delay")

   endif

endfunction



function TimeClock takes nothing returns nothing

   set ms=ms+1

endfunction



function ClockTime takes nothing returns nothing

   call TimerStart(Clock,0.001,true,function TimeClock)

   call TimerStart(CreateTimer(),1,true,function DelayTime)

   call TimerStart(DelayClock,0.001,true,function GetDelayTime)

endfunction


ou99孽缘 发表于 2010-12-14 18:35:38

{:6_306:}
路过拉
页: [1]
查看完整版本: 网络延迟获取-jass版