Dgs3DImageDetachFromElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Server client function}} This function detaches attached 3DImageElement from another element. ==Syntax== <syntaxhighlight lang="lua"> bool detachElements ( element the3DImageElement, [ element theAttachToElement ] ) </syntaxhighlight> {{OOP||element:3DImageDetachFromElement||3DImageAttachToElement}} ===Required Arguments=== *'''the3DImageElement:''' The element to be detached (the "child") ===Optional Arguments=== {{OptionalArg}} *'''theAttachToEl...")
 
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool detachElements ( element the3DImageElement, [ element theAttachToElement ] )
bool dgs3DImageDetachFromElement ( element the3DImageElement, [ element theAttachToElement ] )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[element]]:3DImageDetachFromElement||3DImageAttachToElement}}
{{OOP||[[element]]:3DImageDetachFromElement||3DImageAttachToElement}}
Line 22: Line 22:
'''Example 1:''' This example attaches a marker to a vehicle, and detaches it when it blows up:
'''Example 1:''' This example attaches a marker to a vehicle, and detaches it when it blows up:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
dgs = exports.dgs
if isVoiceEnabled() then
if isVoiceEnabled() then
    local dgs = exports.dgs
local micPNG = dxCreateTexture('assests/mic.png');
    local micPNG = dxCreateTexture('assests/mic.png');
local icons = {};
    local icons = {};
addEventHandler('onClientPlayerVoiceStart',root,
    addEventHandler('onClientPlayerVoiceStart',root,
function()
        function()
print('[Voice-System]: '..getPlayerName(source)..' started talking.')
            print('[Voice-System]: '..getPlayerName(source)..' started talking.')
local x,y,z = getElementPosition(source);
            local x,y,z = getElementPosition(source);
if ((source ~= localPlayer and isElementOnScreen(source)) or (localPlayer == source)) and not isElement(icons[source]) then
            if ((source ~= localPlayer and isElementOnScreen(source)) or (localPlayer == source)) and not isElement(icons[source]) then
icons[source] = dgs:dgsCreate3DImage(x,y,z+1.5,micPNG,tocolor(255,255,255,255),4,4,20);
                icons[source] = dgs:dgsCreate3DImage(x,y,z+1.5,micPNG,tocolor(255,255,255,255),4,4,20);
dgs:dgs3DImageAttachToElement( icons[source],localPlayer,0,0,1.5)
                dgs:dgs3DImageAttachToElement( icons[source],localPlayer,0,0,1.5)
end  
            end  
end
        end
)
    )
addEventHandler('onClientPlayerVoiceStop',root,
    addEventHandler('onClientPlayerVoiceStop',root,
function()  
        function()  
print('[Voice-System]: '..getPlayerName(source)..' Stoped talking.')
            print('[Voice-System]: '..getPlayerName(source)..' Stoped talking.')
if isElement(icons[source]) then
            if isElement(icons[source]) then
dgs:dgs3DImageDettachFromElement( icons[source],localPlayer);
                dgs:dgs3DImageDettachFromElement( icons[source],localPlayer);
destroyElement(icons[source]);
                destroyElement(icons[source]);
icons[source] = nil;
                icons[source] = nil;
end
            end
end
        end
)
    )
end
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Element functions}}
{{DGS 3D Image Functions}}

Latest revision as of 02:18, 12 August 2022

This function detaches attached 3DImageElement from another element.

Syntax

bool dgs3DImageDetachFromElement ( element the3DImageElement, [ element theAttachToElement ] )

OOP Syntax Help! I don't understand this!

Method: element:3DImageDetachFromElement(...)
Counterpart: 3DImageAttachToElement


Required Arguments

  • the3DImageElement: The element to be detached (the "child")

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.

  • theAttachToElement: The element you wish to detach from, will detach from the attached element if this isn't specified.

Returns

Returns true if the detaching was successful, false otherwise.

Example

Example 1: This example attaches a marker to a vehicle, and detaches it when it blows up:

dgs = exports.dgs

if isVoiceEnabled() then
	local micPNG = dxCreateTexture('assests/mic.png');
	local icons = {};
	addEventHandler('onClientPlayerVoiceStart',root,
		function()
			print('[Voice-System]: '..getPlayerName(source)..' started talking.')
			local x,y,z = getElementPosition(source);
			if ((source ~= localPlayer and isElementOnScreen(source)) or (localPlayer == source)) and not isElement(icons[source]) then
				icons[source] = dgs:dgsCreate3DImage(x,y,z+1.5,micPNG,tocolor(255,255,255,255),4,4,20);
				dgs:dgs3DImageAttachToElement( icons[source],localPlayer,0,0,1.5)
			end 
		end
	)
	addEventHandler('onClientPlayerVoiceStop',root,
		function() 
			print('[Voice-System]: '..getPlayerName(source)..' Stoped talking.')
			if isElement(icons[source]) then
				dgs:dgs3DImageDettachFromElement( icons[source],localPlayer);
				destroyElement(icons[source]);
				icons[source] = nil;
			end
		end
	)
end

See Also