Jump to content

[HELP] Scoreboard - FPS


India

Recommended Posts

I put "FPS" to scoreboard. but there is small problem but idk how to fix. FPS appears when player in game but but when someone join into the game, the FPS value does not appear and gives this WARNING:client.lua:98: Bad argument @'dxDrawText' [Expected string at argument 1, got boolean]

local sw, sh = guiGetScreenSize()

scoreboardColumns = {
	{ name = "İsim", width = 200, data = function (element) return getPlayerName ( element ) end },
	{ name = "Öldürmeler", width = 100, data = function (element) return ( getElementData ( element, "murders" ) or 0 ) end },
	{ name = "Zombi Öldürme", width = 99, data = function (element) return ( getElementData ( element, "zombieskilled" ) or 0 ) end },
	{ name = "Zaman", width = 65, data = function (element) return formatTimeFromMinutes(getElementData ( element, "alivetime" ) or 1 ) end },
	{ name = "Grup", width = 180, data = function (element) return getElementData ( element, "Group" ) or "None" end },
	{ name = "Ping", width = 40, data = function (element) return getPlayerPing ( element, "getPlayerPing" ) end },
    { name = "FPS", width = 40, data = function (element) return getElementData ( element, "FPS" ) end },
}

local serverName = "MTA:Turkey DayZ" -- название сервера
local topsize = 80 -- величина шляпы
--local playersize = topsize-30 -- высота одной строки
local playersize = 15 -- высота одной строки
local panelsize = 480 -- величина панели
--local panelsize = 600 -- величина панели

function calculateWidth()
	local width = 0
	for key, value in ipairs( scoreboardColumns ) do
		width = width + value.width
	end
	return width + 60
end 

local max_players = 0
local ploff = 0
local width = calculateWidth()
local baseX = sw/2-width/2
local baseY = sh/2-(panelsize+topsize)/2
 
bindKey ( "tab", "up", function () ploff = 0 end )
 
addEventHandler( "onClientRender", root,
    function()
		if not getKeyState( "tab" ) then return end
		if getElementData(getLocalPlayer(),"logedin") then
			dxDrawRectangle ( baseX, baseY, width, topsize, tocolor(32,32,32) )
			dxDrawText ( serverName, baseX+20, baseY+10, baseX+width, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold" )
			
			dxDrawRectangle ( baseX, baseY+topsize, width, panelsize, tocolor(0,0,0,150) )
			
			dxDrawLine ( baseX, baseY+30, baseX+width, baseY+30, tocolor(100,100,100),0.8 )
			dxDrawLine ( baseX, baseY+30, baseX, baseY+panelsize+topsize, tocolor(100,100,100),0.8 )
			dxDrawLine ( baseX, baseY+panelsize+topsize, baseX+width, baseY+panelsize+topsize, tocolor(100,100,100),0.8 )
			
			dxDrawLine ( baseX+40, baseY+30, baseX+40, baseY+panelsize+topsize, tocolor(100,100,100),0.8 )
			dxDrawText ( "№", baseX, baseY+60, baseX+40, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center" )
			local xoff = 60
			for i, v in ipairs ( scoreboardColumns ) do
				dxDrawLine ( baseX+xoff+v.width, baseY+30, baseX+xoff+v.width, baseY+panelsize+topsize, tocolor(100,100,100),0.8 )
				dxDrawText ( v.name, baseX+xoff, baseY+60, baseX+xoff+v.width, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center" )
				xoff = xoff+v.width
			end
			local playersTable = getElementsByType("player")

			local playerData = {}
    		for i=1, #playersTable do
				local player = playersTable[i]
				local playerKills = getElementData(player, "alivetime" ) or 0
				table.insert(playerData, {player, playerKills})
			end
			table.sort(playerData, function(a, b) return (tonumber(a[2]) or 0) > (tonumber(b[2]) or 0) end)
			--playersTable = {}
			--for i = 1, 40 do
			--	table.insert ( playersTable, localPlayer )
			--end
			--local playersTable = { localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer }
		
			dxDrawText ( "Oyuncu Sayısı: "..tostring(#playerData).."/"..tostring(max_players), baseX+20, baseY+10, baseX+width-20, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold", "right" )

			local maxNum = #playerData
			if maxNum > 30 then
				maxNum = 30
			end
			local tempoff = 0
			for i = 1, maxNum do
				if i == 4 or i == 11 then
					tempoff = tempoff+playersize
				end
				dxDrawLine ( baseX, baseY+topsize+playersize*i+tempoff, baseX+width, baseY+topsize+playersize*i+tempoff, tocolor(100,100,100),0.8 )
				dxDrawText ( i+ploff, baseX, baseY+topsize+playersize*(i-1)+tempoff, baseX+40, baseY+topsize+playersize*i+tempoff, tocolor(255,255,255), 1, "default-bold", "center", "center" )
				if playerData[i+ploff][1] == localPlayer then
				--if i == 10 then	
					dxDrawRectangle ( baseX, baseY+topsize+playersize*(i-1)+tempoff, width, playersize, tocolor(112,112,112,100) )
				end
				local xoff = 60
				for c, d in ipairs ( scoreboardColumns ) do
					local data = d.data(playerData[i+ploff][1])
					local r,g,b = 255,255,255
					if d.name == "Grup" and data == "None" then
						r,g,b = 255,0,0
						data = "Grubu Bulunmamaktadır"
					end
					dxDrawText ( data, baseX+xoff, baseY+topsize+playersize*(i-1)+tempoff, baseX+xoff+d.width, baseY+topsize+playersize*i+tempoff, tocolor(r,g,b), 1, "default-bold", "center", "center" )
					xoff = xoff+d.width
				end
			end
		end
	end
)

function PlayerScrollMenu (key,keyState,arg)
	if getElementData(localPlayer,"logedin") and getKeyState( "tab" ) then
		if ( keyState == "down" ) then
			if arg == "up" then
				if ploff > 0 then
					ploff=ploff-1
				end
			elseif arg == "down" then
				local playersTable = getElementsByType ( "player" )
				--local playersTable = { localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer }
				if ploff < #playersTable-30 then
					ploff = ploff+1
				end
			end
		end
	end
end
bindKey ( "mouse_wheel_up", "down", PlayerScrollMenu, "up" )
bindKey ( "mouse_wheel_down", "down", PlayerScrollMenu, "down" )

function formatTimeFromMinutes(value)
	if value then
		local hours = math.floor(value/60)
		local minutes = math.round(((value/60) - math.floor(value/60))*100/(100/60))
		if minutes < 10 then minutes = "0"..minutes end
		value = hours..":"..minutes
		return value
	end
	return true
end

function math.round(number, decimals, method)
    decimals = decimals or 0
    local factor = 10 ^ decimals
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
    else return tonumber(("%."..decimals.."f"):format(number)) end
end

function sendMaxPlayersOnServer (players)
	max_players = players
end

addEvent("sendMaxPlayersOnServer",true)
addEventHandler("sendMaxPlayersOnServer",getLocalPlayer(),sendMaxPlayersOnServer)

 

Link to post

Replace the FPS line in the table with this to prevent the errors.

{ name = "FPS", width = 40, data = function (element) return getElementData ( element, "FPS" ) or "N/A" end },

It doesn't show the FPS at first because the player just joined and it will take some time to start measuring it.
So if there is no value set for the data "FPS" then it will show "N/A" instead.

Edited by SpecT
  • Like 1
Link to post
1 hour ago, SpecT said:

Replace the FPS line in the table with this to prevent the errors.


{ name = "FPS", width = 40, data = function (element) return getElementData ( element, "FPS" ) or "N/A" end },

It doesn't show the FPS at first because the player just joined and it will take some time to start measuring it.
So if there is no value set for the data "FPS" then it will show "N/A" instead.

Thank you ^^

Link to post

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...