GuiMoveElement

From Multi Theft Auto: Wiki
Revision as of 22:18, 21 May 2018 by KillerProject (talk | contribs) (Created page with "{{Useful Function}} <lowercasetitle/> __NOTOC__ This function moves the gui_element by using moveObject ==Syntax== <syntaxhighlight lang="lua"> guiMoveElement ( element guiEl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function moves the gui_element by using moveObject

Syntax

guiMoveElement ( element guiElement, int time, float targetx, float targety [, string strEasingType ] )

Required Arguments

  • guiElement: the GUI element that will be moved.
  • time: the time in milliseconds the GUI element will arrive at the destination.
  • targetx: the X value of the target position
  • targety: the Y value of the target position

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • strEasingType: the easing function to use for the interpolation (default is "Linear")

Code

Click to collapse [-]
Client
function guiMoveElement ( element, speed, x, y, type_ )
	local type_ = type_ or "Linear"
	if isElement ( element ) and tonumber ( speed ) and tonumber ( x ) and tonumber ( y ) and tostring ( type_ ) then
		if isElement ( getElementData ( element, "object" ) ) then
			local object = getElementData ( element, "object" )
			moveObject ( object, speed, x, y, -999, 0, 0, 0, type_ )
			local destroy = function ( old_object, old_gui )
				if isElement ( old_object ) then
					destroyElement ( old_object )
				end
				for i, gui_elements in ipairs ( table_ ) do
					if gui_elements[1] == old_gui then
						table.remove ( table_, i )
					end
				end
			end
			setTimer ( destroy, speed, 1, object, gui_element )
		else
			local p = { guiGetPosition ( element, false ) }
			local object = createObject ( 902, p[1], p[2], -999 )
			setElementData ( element, "object", object )
			setElementAlpha ( object, 0 )
			table.insert ( table_, (#table_)+1, { element, object } )
			guiMoveElement ( element, speed, x, y, type_ )
		end
	end
end
function r ()
	for i, gui_element in ipairs ( table_ ) do
		if isElement (gui_element[1]) and isElement (gui_element[2]) then
			local x, y = getElementPosition ( gui_element[2] )
			guiSetPosition ( gui_element[1], x, y, false )
		end
	end
end
addEventHandler ( "onClientRender", root, r )


Author: killerProject