GuiLabelAddEffect

From Multi Theft Auto: Wiki
Revision as of 08:24, 30 April 2018 by X1AhMeD,-09 (talk | contribs)
Jump to navigation Jump to search


This function add an effect to any gui-label.

  • NOTE: This is made to be used clientside!.

Syntax

bool guiLabelAddEffect ( gui-element label, string effect )

Required Arguments

  • label: The label you want to add effects to it.
  • effect: The effect you want ( now the function support 2 effects only ( outline , shadow )

Returns

Returns the label that created as an effect if the effect labels have created, false otherwise.

Code

Click to collapse [-]
Clientside script
function guiLabelAddEffect(label, effect)
	local nlab = {}
	local checkTimer = {}
	if label and getElementType(label) == "gui-label" then
		if effect and tostring(effect) and effect:len() > 3 then
			local position = { guiGetPosition(label, false) }
			local size = { guiGetSize(label, false) }
			if effect:lower() == "shadow" then
				nlab[1] = guiCreateLabel(position[1] + 1, position[2] + 1, size[1] + 1, size[2] + 1, guiGetText(label), false, getElementParent(label) and getElementParent(label) or nil)
				guiLabelSetColor(nlab[1], 0, 0, 0)
			elseif effect:lower() == "outline" then
				for i = 1, 4 do
					x, y, w, h = (i == 1 or i == 2 and 1 or -1), (i == 1 or i == 3 and 1 or -1), (i == 1 or i == 2 and 1 or -1), (i == 1 or i == 3 and 1 or -1)
					nlab[i] = guiCreateLabel(position[1] + x, position[2] + y, size[1] + w, size[2] + h, guiGetText(label), false, getElementParent(label) and getElementParent(label) or nil)
					guiLabelSetColor(nlab[i], 0, 0, 0)
				end
			end
		end
	end
	if #nlab > 0 then
		if label then
			if isTimer(checkTimer[label]) then killTimer(checkTimer[label]) end
			checkTimer[label] = setTimer(function()
				for _,nlabel in ipairs(nlab) do
					guiSetVisible(nlabel, guiGetVisible(label))
				end
				if not isElement(label) then
					killTimer(checkTimer[label])
					for i = 1, #nlab do
						destroyElement(nlab[i])
					end
				end
			end, 100, 0)
		end
		if #nlab == 1 then
			return nlab[1]
		elseif #nlab == 4 then
			return nlab[1], nlab[2], nlab[3], nlab[4]
		end
	else
		return false
	end
end

Author: #x1AhMeD,-09

Example

This example add shadow effect to the label.

addEventHandler("onClientResourceStart", resourceRoot,
    function()
      myLabel = guiCreateLabel(350, 100, 50, 50, "Hello World", false)
    end 
)

addCommandHandler("effect", 
    function()
      if myLabel then
         guiLabelAddEffect(myLabel, "shadow")
      end
    end 
)