GetElementData: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
Line 7: | Line 7: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theElement:''' This is the element with data you want to | *'''theElement:''' This is the element with data you want to retrieve. | ||
*'''key:''' The name of the element data entry you want to retrieve. | *'''key:''' The name of the element data entry you want to retrieve. | ||
Line 24: | Line 24: | ||
function showJoinTime ( source, commandName, playerName ) | function showJoinTime ( source, commandName, playerName ) | ||
if ( playerName ) then -- see if a player was specified | |||
thePlayer = getPlayerFromNick ( playerName ) -- get the player element for the specified player | |||
if ( thePlayer ) then -- if one was found... | |||
local timeOnline = (getTickCount() - getElementData ( thePlayer, "joinTime" )) / 1000 -- calculates the time since join | local timeOnline = (getTickCount() - getElementData ( thePlayer, "joinTime" )) / 1000 -- calculates the time since join | ||
outputChatBox ( getClientName ( thePlayer ).." joined "..timeOnline.." seconds ago", source ) -- output the player's join time | |||
else | |||
outputChatBox ( "Couldn't find '" .. playerName .. "'", source ) -- display an error | |||
end | |||
else | |||
-- display when the player who used the function joined and inform how to see other people's join time | |||
local timeOnline = (getTickCount() - getElementData ( source, "joinTime" )) / 1000 -- calculate the time since join | local timeOnline = (getTickCount() - getElementData ( source, "joinTime" )) / 1000 -- calculate the time since join | ||
outputChatBox ( "You joined " ..timeOnline.." seconds ago", source ) | |||
outputChatBox ( "Use 'join_time <player name>' to see other people's join time", source ) | |||
end | |||
end | end | ||
-- Add a console command joinTime, that takes an optional parameter of a player's name | -- Add a console command joinTime, that takes an optional parameter of a player's name |
Revision as of 14:56, 15 August 2007
Elements can contain data values. These are accessable via names, and their value can be retrieved using getElementData and set using setElementData. These values are also loaded from the attributes in the XML map files, and as such can provide a powerful way to store and retrieve data in XML for each element.
Syntax
var getElementData ( element theElement, string key )
Required Arguments
- theElement: This is the element with data you want to retrieve.
- key: The name of the element data entry you want to retrieve.
Returns
This function returns a variable containing the requested element data, or false if the element data does not exist, or the element itself does not exist. Usually this is a string but it doesn't have to be.
Example
This example stores the tick count when a player joins and then allows players to see how long they are connected using a console function 'joinTime'.
Click to collapse [-]
Serverfunction joinTime ( ) setElementData ( source, "joinTime", getTickCount() ) -- Store the current tick count in the player's data with the key 'joinTime' end -- Make our 'joinTime' function be called when a player joins addEventHandler ( "onPlayerJoin", getRootElement(), joinTime ) function showJoinTime ( source, commandName, playerName ) if ( playerName ) then -- see if a player was specified thePlayer = getPlayerFromNick ( playerName ) -- get the player element for the specified player if ( thePlayer ) then -- if one was found... local timeOnline = (getTickCount() - getElementData ( thePlayer, "joinTime" )) / 1000 -- calculates the time since join outputChatBox ( getClientName ( thePlayer ).." joined "..timeOnline.." seconds ago", source ) -- output the player's join time else outputChatBox ( "Couldn't find '" .. playerName .. "'", source ) -- display an error end else -- display when the player who used the function joined and inform how to see other people's join time local timeOnline = (getTickCount() - getElementData ( source, "joinTime" )) / 1000 -- calculate the time since join outputChatBox ( "You joined " ..timeOnline.." seconds ago", source ) outputChatBox ( "Use 'join_time <player name>' to see other people's join time", source ) end end -- Add a console command joinTime, that takes an optional parameter of a player's name addCommandHandler ( "joinTime", showJoinTime )
See 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