SetElementData: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
This example allows for a player to add a custom tag onto their nickname, and also revert it back to normal if they wish | 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 ( | function addPlayerCustomTag ( thePlayer, command, newTag ) | ||
-- | --Let's make sure the newTag param has been entered... | ||
if ( newTag ) then | if ( newTag ) then | ||
--Grab their current playername for saving. | --Grab their current playername for saving. | ||
local sPlayerNickname = getClientName( | local sPlayerNickname = getClientName ( thePlayer ) | ||
--Create their new nickname with their tag | --Create their new nickname with their tag | ||
local sNewPlayerNickname = newTag .. " " .. sPlayerNickname | local sNewPlayerNickname = newTag .. " " .. sPlayerNickname | ||
-- | --Let's first load the element data, see if it's there already | ||
--The reason for this is that if a player were to do /addtag twice | --The reason for this is that if a player were to do /addtag twice, | ||
-- | --the tag would be prepended a second time | ||
local sOldNick = getElementData( thePlayer, "tempdata.originalnick" ) | |||
local sOldNick = getElementData( | |||
if ( sOldNick == false ) then | if ( sOldNick == false ) then | ||
--Save their orignal nickname in their element data | --Save their orignal nickname in their element data | ||
setElementData ( | setElementData ( thePlayer, "tempdata.originalnick", sPlayerNickname ) | ||
end | end | ||
--Set their new nickname globally | --Set their new nickname globally | ||
setClientName ( | setClientName ( thePlayer, sNewPlayerNickname ) | ||
--Tell them | --Tell them it's done | ||
outputChatBox ( "Your new nickname has been set, to put it back to its | outputChatBox ( "Your new nickname has been set, to put it back to its original state you can use /deltag", thePlayer ) | ||
else | else | ||
--The newTag param was not entered, give | --The newTag param was not entered, give an error message | ||
outputChatBox ( "/addtag - Incorrect syntax, Correct: /addtag <newtag>", | outputChatBox ( "/addtag - Incorrect syntax, Correct: /addtag <newtag>", thePlayer ) | ||
end | end | ||
end | end | ||
addCommandHandler ( "addtag", addPlayerCustomTag ) | addCommandHandler ( "addtag", addPlayerCustomTag ) | ||
function removePlayerCustomTag ( | function removePlayerCustomTag ( thePlayer, command ) | ||
--We first need to check that they have | --We first need to check that they have already used /addtag, let's do that now | ||
local sOldNick = getElementData( | local sOldNick = getElementData( thePlayer, "tempdata.originalnick" ) | ||
if ( sOldNick ) then | if ( sOldNick ) then | ||
--Great, they have a tag added, | --Great, they have a tag added, let's reset them | ||
--First we will want to reset the element data back to its default (that being false) | --First we will want to reset the element data back to its default (that being false) | ||
setElementData ( | setElementData ( thePlayer, "tempdata.originalnick", false ) | ||
--Now set the client name back | --Now set the client name back | ||
setClientName ( | setClientName ( thePlayer, sOldNick ) | ||
--Notify them | --Notify them | ||
outputChatBox ( "Your old nickname has been set", | outputChatBox ( "Your old nickname has been set", thePlayer ) | ||
end | end | ||
end | end |
Revision as of 12:32, 16 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.
Example
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