SetElementVisibleTo: Difference between revisions
No edit summary |
m (→See Also) |
||
(15 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server function}} | {{Server function}} | ||
This function can change an [[element]]'s [[visibility]]. This | This function can change an [[element]]'s [[visibility]]. | ||
This function only works with the following elements. | |||
* [[Marker]]s | |||
* [[Blip]]s | |||
* [[Radararea]]s | |||
Visibility settings of lower elements in the element tree override higher ones - if visibility for root is set to false and for a player is set to true, it will be visible to the player. | |||
If you want to clear all visibility settings of an [[element]], try [[clearElementVisibleTo]] | |||
Setting visibility for one element will also set visibility for all of its children.<br/> | |||
Order of '''setElementVisibleTo''' calls doesn't matter. | |||
==Syntax== | ==Syntax== | ||
Line 10: | Line 20: | ||
bool setElementVisibleTo ( element theElement, element visibleTo, bool visible ) | bool setElementVisibleTo ( element theElement, element visibleTo, bool visible ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:setVisibleTo||isElementVisibleTo}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 30: | Line 41: | ||
-- Create a marker at the player's position | -- Create a marker at the player's position | ||
myMarker = createMarker ( x, y, z ) | myMarker = createMarker ( x, y, z ) | ||
-- | |||
setElementVisibleTo ( myMarker, | -- Then make the marker invisible to the whole dimension (root for the first) | ||
-- | setElementVisibleTo ( myMarker, root, false ) | ||
-- Set marker visibility to true for someguy | |||
setElementVisibleTo ( myMarker, someguy, true ) | setElementVisibleTo ( myMarker, someguy, true ) | ||
-- The order in which you do the visibility changes does not matter, but ideally trues should be set before falses in order to prevent a momentary flicker. | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The following example shows how to | The following example shows how to make the marker visible to everyone except anotherguy | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- Find the player called someguy | -- Find the player called someguy | ||
Line 48: | Line 62: | ||
-- Create a marker at the player's position | -- Create a marker at the player's position | ||
myMarker = createMarker ( x, y, z ) | myMarker = createMarker ( x, y, z ) | ||
-- First | attachElements(myMarker, someguy) | ||
setElementVisibleTo ( myMarker, | |||
-- Then hide it | -- First make sure everyone is able to see the marker, this line is unnecessary in this case as root visibility is set to true by default behaviour | ||
setElementVisibleTo ( myMarker, anotherguy, false ) | setElementVisibleTo ( myMarker, root, true ) | ||
-- Then hide it from anotherguy | |||
setElementVisibleTo ( myMarker, anotherguy, false ) | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Element_functions}} | {{Element_functions|server}} |
Latest revision as of 22:32, 6 September 2024
This function can change an element's visibility.
This function only works with the following elements.
Visibility settings of lower elements in the element tree override higher ones - if visibility for root is set to false and for a player is set to true, it will be visible to the player.
If you want to clear all visibility settings of an element, try clearElementVisibleTo
Setting visibility for one element will also set visibility for all of its children.
Order of setElementVisibleTo calls doesn't matter.
Syntax
bool setElementVisibleTo ( element theElement, element visibleTo, bool visible )
OOP Syntax Help! I don't understand this!
- Method: element:setVisibleTo(...)
- Counterpart: isElementVisibleTo
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 = getPlayerFromName ( "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 ) -- Then make the marker invisible to the whole dimension (root for the first) setElementVisibleTo ( myMarker, root, false ) -- Set marker visibility to true for someguy setElementVisibleTo ( myMarker, someguy, true ) -- The order in which you do the visibility changes does not matter, but ideally trues should be set before falses in order to prevent a momentary flicker. end
The following example shows how to make the marker visible to everyone except anotherguy
-- Find the player called someguy local someguy = getPlayerFromName ( "someguy" ) local anotherguy = getPlayerFromName ( "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 ) attachElements(myMarker, someguy) -- First make sure everyone is able to see the marker, this line is unnecessary in this case as root visibility is set to true by default behaviour setElementVisibleTo ( myMarker, root, true ) -- Then hide it from anotherguy setElementVisibleTo ( myMarker, anotherguy, false ) end
See Also
- addElementDataSubscriber
- clearElementVisibleTo
- cloneElement
- getElementSyncer
- getElementZoneName
- hasElementDataSubscriber
- isElementVisibleTo
- removeElementData
- removeElementDataSubscriber
- setElementSyncer
- setElementVisibleTo
- Shared
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement