ClearElementVisibleTo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Category:Needs Checking]]
{{Needs_Checking|The example is outdated...i dont know how the element child system works..if someone could kindly fix it :) }}
__NOTOC__  
__NOTOC__  
This function clears any settings added by setElementVisibleTo and restores an element to its default visibility.  This does not work with all entities - [[vehicle]]s, [[player]]s and [[object]]s are exempt. This is because these objects are required for accurate sync (they're physical objects). This function is particularily useful for changing the visibility of markers, radar blips and radar areas.
{{Server function}}
This function clears any settings added by [[setElementVisibleTo]] and restores an [[element]] to its default [[visibility]].


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool clearElementVisibleTo ( element element )   
bool clearElementVisibleTo ( element theElement )   
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[element]]:clearVisibility|||}}


===Required Arguments===  
===Required Arguments===  
*'''element:''' The element in which you wish to restore to its default visibility
*'''theElement:''' The element in which you wish to restore to its default visibility


===Returns===
===Returns===
Line 20: Line 18:
This example clears any visibility settings after a player dies, so everyone can see his blip for a short period
This example clears any visibility settings after a player dies, so everyone can see his blip for a short period
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerWasted", root, "onPlayerWasted" ) --add an event handler for onPlayerSpawn
-- specify the getBlipAttachedTo function
function onPlayerWasted ( totalammo, killer, killerweapon, bodypart ) -- when a player dies
function getBlipAttachedTo( thePlayer )
local blips = getElementsByType( "blip" )
for k, theBlip in ipairs( blips ) do
if getElementAttachedTo( theBlip ) == thePlayer then
return theBlip
end
end
return false
end
 
function clearVisibilityWasted ( totalammo, killer, killerweapon, bodypart ) -- when a player dies
     clearElementVisibleTo ( getBlipAttachedTo ( source ) ) -- clear any visiblity settings of his blip
     clearElementVisibleTo ( getBlipAttachedTo ( source ) ) -- clear any visiblity settings of his blip
end
end
addEventHandler ( "onPlayerWasted", root, clearVisibilityWasted  ) --add an event handler for onPlayerWasted
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Element_functions}}
{{Element_functions}}

Latest revision as of 08:57, 3 August 2023

This function clears any settings added by setElementVisibleTo and restores an element to its default visibility.

Syntax

bool clearElementVisibleTo ( element theElement )   

OOP Syntax Help! I don't understand this!

Method: element:clearVisibility(...)


Required Arguments

  • theElement: The element in which you wish to restore to its default visibility

Returns

Returns true if the operation was successful, false otherwise.

Example

This example clears any visibility settings after a player dies, so everyone can see his blip for a short period

-- specify the getBlipAttachedTo function
function getBlipAttachedTo( thePlayer )
	local blips = getElementsByType( "blip" )
	for k, theBlip in ipairs( blips ) do
		if getElementAttachedTo( theBlip ) == thePlayer then
			return theBlip
		end
	end
	return false
end

function clearVisibilityWasted ( totalammo, killer, killerweapon, bodypart ) -- when a player dies
    clearElementVisibleTo ( getBlipAttachedTo ( source ) ) -- clear any visiblity settings of his blip
end
addEventHandler ( "onPlayerWasted", root, clearVisibilityWasted  ) --add an event handler for onPlayerWasted

See Also