fps_cnt = 0
fps = 0
fps_ms = 0
fps_hud = GenerateHud()

addhook("second","fpsDraw")
function fpsDraw()
	if SERVER_DATA["fps_enabled"] then
		Hudtxt(fps_hud, "Server FPS: "..fps, 15, 100)
	end
end

addhook("always","fpsAlways")
function fpsAlways()
	if SERVER_DATA["fps_enabled"] then
		fps_cnt = fps_cnt + 1
		if Millisecs() - fps_ms >= 1000 then
			fps_ms = Millisecs()
			fps = fps_cnt
			fps_cnt = 0
		end
	end
end

function FpsButton()
	if SERVER_DATA["fps_enabled"] then
		return "Frames per second hud|Enabled"
	end
	return "Frames per second hud|Disabled"
end

function FpsToggle()
	if SERVER_DATA["fps_enabled"] then
		SERVER_DATA["fps_enabled"] = nil
		Freehud(0, fps_hud)
	else
		SERVER_DATA["fps_enabled"] = true
	end
end
CreateSetting(FpsButton, FpsToggle)