SetElementData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[[Category:Incomplete]]
__NOTOC__
This function stores data attached to an element. This data can be any lua type.


__NOTOC__
Element data is a useful way to store data attached to players. It is also the way to add a column to the scoreboard, using [[addScoreboardColumn]].
This fake function is for use with blah & blah and does blahblahblabhalbhl


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setElementData ( element element, string name, var data )  
bool setElementData ( element theElement, string key, var value )  
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''argumentName:''' description
*'''theElement:''' The element you wish to attach the data to
 
*'''key:''' The key you wish to store the data under
===Optional Arguments===
*'''value:''' The value you wish to store
{{OptionalArg}}
*'''argumentName2:''' descriptiona
*'''argumentName3:''' description


===Returns===
===Returns===
Returns ''true'' if blah, ''false'' otherwise.
Returns ''true'' if the data was set succesfully, ''false'' otherwise.


==Example==  
==Example==  
This example does...
This example does...
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
-- Make our 'joinTime' function be called when a player joins
blabhalbalhb --abababa
addEventHandler ( "onPlayerJoin", getRootElement(), "joinTime" )
--This line does this...
function joinTime ( )
mooo
    setElementData ( source, "joinTime", os.date() ) -- Store the current time in the player's data with the key 'joinTime'
end
 
-- Add a console command join_time, that takes an optional parameter of a player's name
addCommandHandler ( "join_time", "showJoinTime" )
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...
            outputChatBox ( getClientName ( thePlayer ) .. " joined " .. getElementData ( thePlayer, "joinTime" ), 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
        outputChatBox ( "You joined " .. getElementData ( source, "joinTime" ), source )
        outputChatBox ( "Use 'join_time <player name>' to see other people's join time" )
    end
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{FunctionArea_Functions}}
{{Element_functions}}

Revision as of 16:25, 8 September 2006

This function stores data attached to an element. This data can be any lua type.

Element data is a useful way to store data attached to players. It is also the way to add a column to the scoreboard, using addScoreboardColumn.

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

This example does...

-- Make our 'joinTime' function be called when a player joins
addEventHandler ( "onPlayerJoin", getRootElement(), "joinTime" )
function joinTime ( )
    setElementData ( source, "joinTime", os.date() ) -- Store the current time in the player's data with the key 'joinTime'
end

-- Add a console command join_time, that takes an optional parameter of a player's name
addCommandHandler ( "join_time", "showJoinTime" )
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...
            outputChatBox ( getClientName ( thePlayer ) .. " joined " .. getElementData ( thePlayer, "joinTime" ), 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
        outputChatBox ( "You joined " .. getElementData ( source, "joinTime" ), source )
        outputChatBox ( "Use 'join_time <player name>' to see other people's join time" )
    end
end

See Also