Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lastFrameTime = 0
- local lastAvgUpdate = 0
- local longestFrameLength = 0
- local rollingAvg = 30
- local function OnUpdateServer()
- local time = Shared.GetTime()
- local frameLength = time - lastFrameTime
- if frameLength > longestFrameLength then
- longestFrameLength = frameLength
- end
- if time > lastAvgUpdate + 0.1 then
- local longestFrameFPS = 1 / longestFrameLength
- // map lower fps to even lower fps using dark magic
- // (this will become a percentage/score, this "wrong" value will not be presented)
- longestFrameFPS = 30 + (25 * (-30 + longestFrameFPS) / longestFrameFPS)
- rollingAvg = (rollingAvg * 0.995) + (0.005 * longestFrameFPS)
- longestFrameLength = 0
- lastAvgUpdate = time
- end
- lastFrameTime = time
- end
- Event.Hook("UpdateServer", OnUpdateServer)
- local function GetServerPerf()
- local fps = 30
- if Shared.GetTime() < 60 then
- fps = Server.GetFrameRate()
- else
- fps = rollingAvg
- end
- return math.max(0, math.min(100, math.floor(((fps / 30) * 100) + 0.5)))
- end
- local kKeyValueUpdateRate = 5
- local lastKeyValueUpdateTime = 0
- local function UpdateServerConfig()
- if Shared.GetSystemTime() - lastKeyValueUpdateTime >= kKeyValueUpdateRate then
- Server.SetKeyValue("performance", ToString(GetServerPerf()))
- lastKeyValueUpdateTime = Shared.GetSystemTime()
- end
- end
- Event.Hook("UpdateServer", UpdateServerConfig)
RAW Paste Data