SetElementData: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 18: | Line 18: | ||
Returns ''true'' if the data was set succesfully, ''false'' otherwise. | Returns ''true'' if the data was set succesfully, ''false'' otherwise. | ||
<section name="Server" class="server" show="false"> | |||
==Example== | ==Example== | ||
This example | This example allows for a player to add a custom tag onto their nickname, and also revert it back to normal if they wish | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | function addPlayerCustomTag ( player, command, newTag ) | ||
--Lets check that the newTag param has been entered... | |||
if ( newTag ) then | |||
--Grab their current playername for saving. | |||
local sPlayerNickname = getClientName(player) | |||
--Create their new nickname with their tag | |||
local sNewPlayerNickname = newTag .. " " .. sPlayerNickname | |||
--Lets first load the element data, see if its there allready | |||
--The reason for this is that if a player were to do /addtag twice | |||
--it would have saved their last tag as their orignal nickname | |||
--without this check | |||
local sOldNick = getElementData( player, "tempdata.orignalnick" ) | |||
if ( sOldNick == false ) then | |||
--Save their orignal nickname in their element data | |||
setElementData ( player, "tempdata.orignalnick", sPlayerNickname ) | |||
end | |||
--Set their new nickname globally | |||
setClientName ( player, sNewPlayerNickname ) | |||
--Tell them its done | |||
outputChatBox ( "Your new nickname has been set, to put it back to its orignal state you can use /deltag", player ) | |||
else | |||
--The newTag param was not entered, give a error message | |||
outputChatBox ( "/addtag - Incorrect syntax, Correct: /addtag <newtag>", player ) | |||
end | |||
end | end | ||
addCommandHandler ( "addtag", addPlayerCustomTag ) | |||
-- | function removePlayerCustomTag ( player, command ) | ||
--We first need to check that they have allready used /addtag, lets do that now | |||
local sOldNick = getElementData( player, "tempdata.orignalnick" ) | |||
if ( sOldNick ) then | |||
--Great, they have a tag added, lets reset them | |||
--First we will want to reset the element data back to its default (that being false) | |||
setElementData ( player, "tempdata.orignalnick", false ) | |||
--Now set the client name back | |||
setClientName ( player, sOldNick ) | |||
--Notify them | |||
outputChatBox ( "Your old nickname has been set", player ) | |||
end | |||
end | end | ||
addCommandHandler ( "deltag", removePlayerCustomTag ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{Element_functions}} | {{Element_functions}} |
Revision as of 10:21, 12 August 2007
This function stores data attached to an element. This data can be any primitive LUA type or MTA element (but not a text item or display).
Element data is a useful way to store data attached to players.
Syntax
bool setElementData ( element theElement, string key, var value )
Required Arguments
- theElement: The element you wish to attach the data to
- key: The key you wish to store the data under
- value: The value you wish to store
Returns
Returns true if the data was set succesfully, false otherwise.
Click to expand [+]
ServerSee Also
- 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