MTA.Castiel Posted June 3, 2022 Share Posted June 3, 2022 Hi, i need a little help with this I'm trying to have the PING update every second the same way FPS does using the same or similar type of method. local sx_, sy_ = guiGetScreenSize() local sx, sy = sx_/1280, sy_/720 local screenW, screenH = guiGetScreenSize() --------------------------- -- Draw PING --------------------------- addEventHandler('onClientRender', root, function() local ping = getPlayerPing(localPlayer) --local currentTick = getTickCount() --local elapsedTime = currentTick - lastTick --if elapsedTime >= 1000 then --return ping --end dxDrawText("PING: "..ping, 1180*sx, 620*sy, 0*sx, 0*sy, tocolor(255, 255, 255), 1*sx, 1*sy, "default-bold", "center", "top", false, false, false, true, false) end) --------------------------- -- Draw FPS --------------------------- local FPSLimit, lastTick, framesRendered, FPS = 60, getTickCount(), 1, 1 addEventHandler('onClientRender', root, function() local currentTick = getTickCount() local elapsedTime = currentTick - lastTick if elapsedTime >= 1000 then FPS = framesRendered lastTick = currentTick framesRendered = 1 else framesRendered = framesRendered + 1 end if FPS > FPSLimit then FPS = FPSLimit end dxDrawText("FPS: "..FPS, 1280*sx, 620*sy, 0*sx, 0*sy, tocolor(255, 255, 255), 1*sx, 1*sy, "default-bold", "center", "top", false, false, false, true, false) end) Link to comment
AndresTVz Posted June 3, 2022 Share Posted June 3, 2022 local sx_, sy_ = guiGetScreenSize() local sx, sy = sx_/1280, sy_/720 local screenW, screenH = guiGetScreenSize() --------------------------- -- Draw PING --------------------------- function drawPing() local ping = getPlayerPing(localPlayer) dxDrawText("PING: "..ping, 1180*sx, 620*sy, 0*sx, 0*sy, tocolor(255, 255, 255), 1*sx, 1*sy, "default-bold", "center", "top", false, false, false, true, false) end --------------------------- -- Draw FPS --------------------------- local FPSLimit, lastTick, framesRendered, FPS = 60, getTickCount(), 1, 1 function drawFps() local currentTick = getTickCount() local elapsedTime = currentTick - lastTick if elapsedTime >= 1000 then FPS = framesRendered lastTick = currentTick framesRendered = 1 else framesRendered = framesRendered + 1 end if FPS > FPSLimit then FPS = FPSLimit end dxDrawText("FPS: "..FPS, 1280*sx, 620*sy, 0*sx, 0*sy, tocolor(255, 255, 255), 1*sx, 1*sy, "default-bold", "center", "top", false, false, false, true, false) end addEventHandler("onClientResourceStart", root, function() addEventHandler("onClientRender", root, drawPing) addEventHandler("onClientRender", root, drawFps) end) Try now Link to comment
MTA.Castiel Posted June 3, 2022 Author Share Posted June 3, 2022 (edited) The PING still seems to update inconsistently Edited June 3, 2022 by MTA.Castiel Link to comment
STRANGEROUS Posted June 19, 2022 Share Posted June 19, 2022 (edited) local fps, fpsTick = 0, 0 function getCurrentFPS() return fps end local function getUpdateFPS(ms) local now = getTickCount() if (now >= fpsTick) then fps = (1 / ms) * 1000 fpsTick = now + 1000 end end addEventHandler("onClientPreRender", root, getUpdateFPS) addEventHandler('onClientRender', root, function() local getFPS = math.floor(getCurrentFPS()) dxDrawText("FPS: "..getFPS, 1280*sx, 620*sy, 0*sx, 0*sy, tocolor(255, 255, 255), 1*sx, 1*sy, "default-bold", "center", "top", false, false, false, true, false) end) Edited June 19, 2022 by STRANGEROUS Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now