Jump to content

tempo para o onClientRender()


Recommended Posts

Salve.
Tenho um sistema de mostrar os FPS's na tela, que utiliza o onClientRender() pra atualizar, mas ele atualiza muito rápido* e nem da pra ver o FPS, por que ele fica variando entre 59~60~61, e não fica muito legível.
Existe alguma forma para definir o tempo para os FPS's atualizarem? Algo como 1 vez por segundo ou algo assim...
Pensei em setTimer, mas não consegui...

Código:

local fps = 0
function getCurrentFPS()
    return fps
end

local function updateFPS(msSinceLastFrame)
    fps = (1 / msSinceLastFrame) * 1000
end
addEventHandler("onClientPreRender", root, updateFPS)

function screenFPS()
    fps = math.floor(fps)

    local enviado    = getNetworkStats().packetsSent
    local recebido   = getNetworkStats().packetsReceived
    local packetLoss = getNetworkStats().packetlossTotal

    local mostrar = getElementData(localPlayer, "hud:informacoes")
    if mostrar == nil then setElementData(localPlayer, "hud:informacoes", true) end

    if mostrar == true then
        dxDrawText("FPS: "..fps, (screenW * 0.1555) - 1, (screenH * 0.0362) - 1, (screenW * 0.1992) - 1, (screenH * 0.0537) - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("FPS: "..fps, (screenW * 0.1555) + 1, (screenH * 0.0362) - 1, (screenW * 0.1992) + 1, (screenH * 0.0537) - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("FPS: "..fps, (screenW * 0.1555) - 1, (screenH * 0.0362) + 1, (screenW * 0.1992) - 1, (screenH * 0.0537) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("FPS: "..fps, (screenW * 0.1555) + 1, (screenH * 0.0362) + 1, (screenW * 0.1992) + 1, (screenH * 0.0537) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("FPS: "..fps, screenW * 0.1555, screenH * 0.0362, screenW * 0.1992, screenH * 0.0537, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("PING: "..getPlayerPing(localPlayer), (screenW * 0.1977) - 1, (screenH * 0.0362) - 1, (screenW * 0.2414) - 1, (screenH * 0.0537) - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("PING: "..getPlayerPing(localPlayer), (screenW * 0.1977) + 1, (screenH * 0.0362) - 1, (screenW * 0.2414) + 1, (screenH * 0.0537) - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("PING: "..getPlayerPing(localPlayer), (screenW * 0.1977) - 1, (screenH * 0.0362) + 1, (screenW * 0.2414) - 1, (screenH * 0.0537) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("PING: "..getPlayerPing(localPlayer), (screenW * 0.1977) + 1, (screenH * 0.0362) + 1, (screenW * 0.2414) + 1, (screenH * 0.0537) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        dxDrawText("PING: "..getPlayerPing(localPlayer), screenW * 0.1977, screenH * 0.0362, screenW * 0.2414, screenH * 0.0537, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
    end
end
addEventHandler ( "onClientRender", root, screenFPS )


Quem puder ajudar, ficaria grato.

Edited by SrPattif
Link to comment
  • Other Languages Moderators

Adicione isso no seu script.

local delayfps = 0

setTimer (function ()
    delayfps = fps
end, 1000, 0)

-- No seu dxDrawText, coloque delayfps no lugar de fps. Troque também no math.floor.
Edited by Lord Henry
  • Thanks 1
Link to comment

@SrPatiff O seguinte código pode ajudá-lo com o problema reportado:
 

local fps = 0
local showFPS_tick = 0

function getCurrentFPS()
    return fps
end

local function updateFPS(msSinceLastFrame)
    fps = (1 / msSinceLastFrame) * 1000
end
addEventHandler("onClientPreRender", root, updateFPS)

function screenFPS()
    fps = math.floor(fps)

    local enviado    = getNetworkStats().packetsSent
    local recebido   = getNetworkStats().packetsReceived
    local packetLoss = getNetworkStats().packetlossTotal
	local now = getTickCount()

    local mostrar = getElementData(localPlayer, "hud:informacoes")
    if mostrar == nil then setElementData(localPlayer, "hud:informacoes", true) end

    if mostrar == true then
		if (now >= showFPS_tick) then
			dxDrawText("FPS: "..fps, (screenW * 0.1555) - 1, (screenH * 0.0362) - 1, (screenW * 0.1992) - 1, (screenH * 0.0537) - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("FPS: "..fps, (screenW * 0.1555) + 1, (screenH * 0.0362) - 1, (screenW * 0.1992) + 1, (screenH * 0.0537) - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("FPS: "..fps, (screenW * 0.1555) - 1, (screenH * 0.0362) + 1, (screenW * 0.1992) - 1, (screenH * 0.0537) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("FPS: "..fps, (screenW * 0.1555) + 1, (screenH * 0.0362) + 1, (screenW * 0.1992) + 1, (screenH * 0.0537) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("FPS: "..fps, screenW * 0.1555, screenH * 0.0362, screenW * 0.1992, screenH * 0.0537, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("PING: "..getPlayerPing(localPlayer), (screenW * 0.1977) - 1, (screenH * 0.0362) - 1, (screenW * 0.2414) - 1, (screenH * 0.0537) - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("PING: "..getPlayerPing(localPlayer), (screenW * 0.1977) + 1, (screenH * 0.0362) - 1, (screenW * 0.2414) + 1, (screenH * 0.0537) - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("PING: "..getPlayerPing(localPlayer), (screenW * 0.1977) - 1, (screenH * 0.0362) + 1, (screenW * 0.2414) - 1, (screenH * 0.0537) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("PING: "..getPlayerPing(localPlayer), (screenW * 0.1977) + 1, (screenH * 0.0362) + 1, (screenW * 0.2414) + 1, (screenH * 0.0537) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			dxDrawText("PING: "..getPlayerPing(localPlayer), screenW * 0.1977, screenH * 0.0362, screenW * 0.2414, screenH * 0.0537, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
			showFPS_tick = now + 1000
		end
    end
end
addEventHandler ( "onClientRender", root, screenFPS )


Se não der certo, avise aqui quando puder.

  • Thanks 1
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...