[Release] Display FPS in game

Screenshot

Download

Github

3 Likes

Ummm… Doesn’t steam already have a built-in FPS counter???

I released it for this guy :v

Nice mate :o

Yes.


Looks good.

I think a good way to expand it would be having a config for it to change colour. Something like the below.

local useColors = true -- Do you want the FPS to change color based on the FPS.


if useColors then
    if fps > 0 and fps < 12 then
        displayText("~c~FPS: ~r~" .. fps, 0, 255, 255, 255, 255, 0.5, 0.0)
    elseif fps > 0 and fps < 30 then
        displayText("~c~FPS: ~o~" .. fps, 0, 255, 255, 255, 255, 0.5, 0.0)
    elseif fps > 0 and fps < 1000 then
        displayText("~c~FPS: " .. fps, 0, 255, 255, 255, 255, 0.5, 0.0)
    end
else
    if fps > 0 and fps < 1000 then
        displayText("~c~FPS: " .. fps, 0, 255, 255, 255, 255, 0.5, 0.0)
    end
end

Also made it default grey as its not as in-the-way.

4 Likes

You my sir have literally made a resouce that sucks fsp by showing fps! :smiley:
https://gyazo.com/b5f104e581e1c6a47f68346fef461b57
I dont really see the use for this, but if you really need to have the fps displayed and not want to use cl_drawfps 1, atleast make it js based so it wont be so resource heavy.

2 Likes

Its not horrible. Could be improved a little.

It must draw text and check fps every frame, so it will be heavy :confused:

__resource.lua

description "Time And Date Display"
client_script "timeAndDateDisplay_client.lua"

timeAndDateDisplay_client.lua

local displayTime = true
local useMilitaryTime = true
local displayDayOfWeek = true
local displayDate = true
local displayFps = true

local timeAndDateString = nil
local hour
local minute
local dayOfWeek
local month
local dayOfMonth
local year

local rgb = {r = 255, g = 153, b = 102}
local prevtime = GetGameTimer()
local prevframes = GetFrameCount()
local fps = -1

Citizen.CreateThread(function()
	while true do
		Wait(1)
		timeAndDateString = "~r~Time:"
		
		if displayTime == true then
			CalculateTimeToDisplay()
			timeAndDateString = timeAndDateString .. " ~w~" .. hour .. "~r~:~w~" .. minute .. "~r~ | "
		end
		if displayDayOfWeek == true then
			CalculateDayOfWeekToDisplay()
			timeAndDateString = timeAndDateString .. "~w~" .. dayOfWeek .. "~r~ | "
		end
		if displayDate == true then
			CalculateDateToDisplay()
			timeAndDateString = timeAndDateString .. "~w~" .. month .. "~r~/~w~" .. dayOfMonth .. "~r~/~w~" .. year .. "~r~ | ~w~"
		end
		if displayFps == true then
			CalculateDateToDisplay()
			timeAndDateString = timeAndDateString .. "~w~" .. fps .. " ~r~FPS ~r~"
		end

		SetTextFont(4)
		SetTextProportional(1)
		SetTextScale(0.50, 0.50)
		SetTextColour(255, 255, 255, 255)
		SetTextDropshadow(0, 0, 0, 0, 255)
		SetTextEdge(1, 0, 0, 0, 255)
		SetTextDropShadow()
		SetTextOutline()
		SetTextRightJustify(true)
		SetTextWrap(0.1,0.93)
		SetTextEntry("STRING")
		
		AddTextComponentString(timeAndDateString)
		DrawText(0.01, 0.01)
		
	end
end)

function CalculateTimeToDisplay()
	hour = GetClockHours()
	minute = GetClockMinutes()

	if useMilitaryTime == false then
		if hour == 0 or hour == 24 then
			hour = 12
		elseif hour >= 13 then
			hour = hour - 12
		end
	end

	if hour <= 9 then
		hour = "0" .. hour
	end
	if minute <= 9 then
		minute = "0" .. minute
	end
end

function CalculateDayOfWeekToDisplay()
	dayOfWeek = GetClockDayOfWeek()
	
	if dayOfWeek == 0 then
		dayOfWeek = "Sunday"
	elseif dayOfWeek == 1 then
		dayOfWeek = "Monday"
	elseif dayOfWeek == 2 then
		dayOfWeek = "Tuesday"
	elseif dayOfWeek == 3 then
		dayOfWeek = "Wednesday"
	elseif dayOfWeek == 4 then
		dayOfWeek = "Thursday"
	elseif dayOfWeek == 5 then
		dayOfWeek = "Friday"
	elseif dayOfWeek == 6 then
		dayOfWeek = "Saturday"
	end
end

function CalculateDateToDisplay()
	month = GetClockMonth()
	dayOfMonth = GetClockDayOfMonth()
	year = 2018
	
	if month == 0 then
		month = "1"
	elseif month == 1 then
		month = "2"
	elseif month == 2 then
		month = "3"
	elseif month == 3 then
		month = "4"
	elseif month == 4 then
		month = "5"
	elseif month == 5 then
		month = "6"
	elseif month == 6 then
		month = "7"
	elseif month == 7 then
		month = "8"
	elseif month == 8 then
		month = "9"
	elseif month == 9 then
		month = "10"
	elseif month == 10 then
		month = "11"
	elseif month == 11 then
		month = "12"
	end
end

Citizen.CreateThread(function()	  
        
        while not NetworkIsPlayerActive(PlayerId()) or not NetworkIsSessionStarted() do	        
            Citizen.Wait(250)
            prevframes = GetFrameCount()
            prevtime = GetGameTimer()            
	end

        while true do		 
            curtime = GetGameTimer()
	        curframes = GetFrameCount()	   
		
	    if((curtime - prevtime) > 1000) then
		    fps = (curframes - prevframes) - 1				
		    prevtime = curtime
		    prevframes = curframes
	    end

            if IsGameplayCamRendering() and fps >= 0 then
	            PrintText(fps .. " FPS")
            end            
            Citizen.Wait(1)		
       end	
end)

function PrintText(text)
	SetTextEntry("STRING")
end

Capture

3 Likes
  • May I add this is not my work original creator is

Can anyone knows where can i find this hud?

Nice but you could just press F8 and type cl_drawfps true

can someone make it diplay ingame ping

How do i get this to work tho?
Do i need to put in a certain directory??

how to setup. Can you help me