Jump to content

Draw PING / FPS


Recommended Posts

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

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
  • 3 weeks later...
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)

MngD4pX.png
Edited by STRANGEROUS
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...