UserToDelete Posted June 27, 2015 Share Posted June 27, 2015 Hice este script para detectar la conexion que usa por segundo, pero la variante siempre se establece en 0, es decir, como si la resta diera 0, o algo asi lastSecond = 0 function net() if vu == nil and bu == nil then vu, bu = 0,0 end local networkData = getNetworkUsageData()["out"] for i, val in pairs(networkData["count"]) do if networkData["bits"][i] > 0 then vu = vu + networkData["bits"][i] end end setTimer(function () local networkData = getNetworkUsageData()["out"] for i, val in pairs(networkData["count"]) do if networkData["bits"][i] > 0 then bu = bu + networkData["bits"][i] end end lastSecond = bu - vu end, 1000,1) end Solucionado: lastSecond = 0 his = {} function net() vu = 0 local networkData = getNetworkUsageData()["out"] for i, val in pairs(networkData["count"]) do if networkData["bits"][i] > 0 then vu = vu + networkData["bits"][i] end end table.insert(his, vu) while (#his > 2) do table.remove(his, 1) lastSecond = (-his[1] + his[2])/1024 end end Basado en el trabajo de la comunidad de MTA:SA https://wiki.multitheftauto.com/wiki/GetNetworkStats PACKETLOSS_HISTORY_LENGTH = 60 -- Sample period in seconds packetlossHistory = {} packetlossAvg = 0 -- (Output) Average packet loss over last 60 seconds packetlossPeak = 0 -- (Output) Peak packet loss over last 60 seconds function samplePacketLoss() table.insert( packetlossHistory, getNetworkStats().packetlossLastSecond ) while( #packetlossHistory > PACKETLOSS_HISTORY_LENGTH ) do table.remove( packetlossHistory, 1 ) end packetlossAvg = 0 packetlossPeak = 0 for _,value in ipairs(packetlossHistory) do packetlossAvg = packetlossAvg + value packetlossPeak = math.max( packetlossPeak, value ) end packetlossAvg = packetlossAvg / #packetlossHistory end setTimer(samplePacketLoss,1000,0) Link to comment
Recommended Posts