Jump to content

Custom loadingbar/loading notifications


Dzsozi (h03)

Recommended Posts

Hello! I have created a little loading thingy, I would like to make a custom loading indicator and also use it in other scripts, for example if your fps is under 20 then it would show the loading indicator. But I would like to make some kind of ID for the created notifications, or something to identify the which notification I would like to remove and which I would like to keep showing. How can I do that and what would be the most efficient way to do this? Here's my script:

local screenWidth, screenHeight = guiGetScreenSize()

local textFont = "default-bold"

local showLoadingBar = false
local str_
local iconRotation = 0

function dxDrawLoadingBar(str, state)
	str_ = str
	showLoadingBar = state
end
addEvent("drawLoadingBar", true)
addEventHandler("drawLoadingBar", root, dxDrawLoadingBar)

dxDrawLoadingBar("pálya betöltése", true)
setTimer(function()
	dxDrawLoadingBar("karakter betöltése", true)
	dxDrawLoadingBar("pálya betöltése", false)
	setTimer(function()
		dxDrawLoadingBar("betöltés", true)
		setTimer(function()
			dxDrawLoadingBar(false)
		end, 5000, 1)
	end, 5000, 1)
end, 2500, 1)

addEventHandler("onClientRender", root, function()
	if showLoadingBar then
		local textWidth = -5
		local textHeight = 18.75
		if str_ and str_ ~= "" then
			textWidth = dxGetTextWidth(str_, 1.25, textFont)
			textHeight = dxGetFontHeight(1.25, textFont)
		else
			textWidth = -5
			textHeight = 18.75
		end
	
		local loadingWidth, loadingHeight = 16, 16
		iconRotation = iconRotation - 5
		if (iconRotation < 0) then
			iconRotation = 360
		end
		
		local barSizeX, barSizeY = textWidth + 25 + loadingWidth, textHeight + 10
		local barPosX, barPosY = screenWidth - 20 - barSizeX, screenHeight - 20 - barSizeY
		
		dxDrawRectangle(barPosX, barPosY, barSizeX, barSizeY, tocolor(0, 0, 0, 180))
		if str_ then
			dxDrawText(str_, barPosX + textWidth + loadingWidth + 20, barPosY + 5, barPosX + textWidth + loadingWidth + 20, barPosY + 5, tocolor(200, 0, 100, 255), 1.25, textFont, "right", "top", false, false, false, true, true)
		end
		
		dxDrawImage(barPosX + 10, barPosY + textHeight/2 - 2.5, loadingWidth, loadingHeight, "images/spinner.png", iconRotation, 0, 0, tocolor(200, 0, 100, 255))
	end
end)

And an example for my problem:

addEventHandler("onClientRender", root, function()
	if getElementData(localPlayer, "playerfps") <= 20 then
		dxDrawLoadingBar("", true)
	else
		dxDrawLoadingBar("", false)
	end
end)

addEventHandler("onClientRender", root, function()
	if isTransferBoxActive() then
		dxDrawLoadingBar("lodaing", true)
	else
		dxDrawLoadingBar("loading", false)
	end
end)

If I delete the transferbox part then the whole thing works, I get the loading notification if my fps is under a specified number, for example under 20, and if it's above 20 then the notification is gone, so it works, but if I have the transferbox part then the notification of the fps won't show up, because I have the else dxDrawLoadingBar(false) part (since the transferbox is not always active). I was thinking about identifying the loadingbars by the string given, so if the string is the same with the string of the drawn notification I could disable only that loading notification. I hope you know what I mean, it's kinda hard to explain.

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