SetElementVisibleTo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 4: Line 4:
}}
}}
{{Needs_Checking|'''*''' I tried to make a blip visible to 1 player but it doesn't work unless I use getRootElement() [[User:Norby89|Norby89]] 10:20, 3 August 2007 (CDT)
{{Needs_Checking|'''*''' I tried to make a blip visible to 1 player but it doesn't work unless I use getRootElement() [[User:Norby89|Norby89]] 10:20, 3 August 2007 (CDT)
}}
{{Needs_Checking|'''*''' I tried to hide a marker from 1 player but I have to make the marker especially visible to this player before (tested on DP2)
[[User:mvol|mvol]] 21:51, 20 January 2008 (CDT)
}}
}}


Line 37: Line 40:
-- Then make the marker visible again, but only to someguy
-- Then make the marker visible again, but only to someguy
setElementVisibleTo ( myMarker, someguy, true )
setElementVisibleTo ( myMarker, someguy, true )
end
</syntaxhighlight>
The following example show how to hide the marker on 'someguy' from 'anotherguy'
<syntaxhighlight lang="lua">
-- Find the player called someguy
local someguy = getPlayerFromNick ( "someguy" )
local anotherguy = getPlayerFromNick ( "anotherguy" )
-- If the player was found then
if ( someguy ) then
-- Get the player's position into the variables x, y and z
x, y, z = getElementPosition ( someguy )
-- Create a marker at the player's position
myMarker = createMarker ( x, y, z )
-- First off make the marker visible especially to 'anotherguy'
setElementVisibleTo ( myMarker, anotherguy, true )
-- Then hide it
setElementVisibleTo ( myMarker, anotherguy, false )
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 20:56, 20 January 2008

Dialog-information.png This article needs checking.

Reason(s): Can an element only be visible to one element (and its children) at a time? If so, do we need clearElementVisibleTo? If not, surely we need to remove the root element before using this function?
Dialog-information.png This article needs checking.

Reason(s): * I tried to make a blip visible to 1 player but it doesn't work unless I use getRootElement() Norby89 10:20, 3 August 2007 (CDT)
Dialog-information.png This article needs checking.

Reason(s): * I tried to hide a marker from 1 player but I have to make the marker especially visible to this player before (tested on DP2)

mvol 21:51, 20 January 2008 (CDT)


This function can change an element's visibility. This does not work with all entities - vehicles, players and objects 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.

Syntax

bool setElementVisibleTo ( element theElement, element visibleTo, bool visible )

Required Arguments

  • theElement: The element you want to control the visibility of.
  • visibleTo: The element you wish the element to be visible or invisible to. Any child elements that are players will also be able to see the element. See visibility.
  • visible: Whether you are making it visible or invisible to the player.

Returns

Returns true if the element's visibility was changed successfully, false otherwise, for example if you are trying to change the visibility of a vehicle, player or object.

Example

This example creates a marker and makes it only visibile to the player called 'someguy'.

-- Find the player called someguy
local someguy = getPlayerFromNick ( "someguy" )
-- If the player was found then
if ( someguy ) then
	-- Get the player's position into the variables x, y and z
	x, y, z = getElementPosition ( someguy )
	-- Create a marker at the player's position
	myMarker = createMarker ( x, y, z )
	-- First off make the marker invisible to the whole dimension
	setElementVisibleTo ( myMarker, getRootElement ( ), false )
	-- Then make the marker visible again, but only to someguy
	setElementVisibleTo ( myMarker, someguy, true )
end

The following example show how to hide the marker on 'someguy' from 'anotherguy'

-- Find the player called someguy
local someguy = getPlayerFromNick ( "someguy" )
local anotherguy = getPlayerFromNick ( "anotherguy" )
-- If the player was found then
if ( someguy ) then
	-- Get the player's position into the variables x, y and z
	x, y, z = getElementPosition ( someguy )
	-- Create a marker at the player's position
	myMarker = createMarker ( x, y, z )
	-- First off make the marker visible especially to 'anotherguy'
	setElementVisibleTo ( myMarker, anotherguy, true )
	-- Then hide it
	setElementVisibleTo ( myMarker, anotherguy, false )
end

See Also