RemoveElementData: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (fix oop syntax)
(Improve example.)
Line 19: Line 19:
This will create an element data for know if a player has spawned.
This will create an element data for know if a player has spawned.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function spawn()
function onPlayerSpawn()
     setElementData(source,"spawned",true)
     setElementData(source, "playerSpawned", true)
end
end
addEventHandler ( "onPlayerSpawn", getRootElement(), spawn )
addEventHandler("onPlayerSpawn", root, onPlayerSpawn)
function wasted()
 
     removeElementData(source,"spawned")
function onPlayerWasted()
     removeElementData(source, "playerSpawned")
end
end
addEventHandler ( "onPlayerWasted", getRootElement(), wasted )</syntaxhighlight>
addEventHandler("onPlayerWasted", root, onPlayerWasted)
</syntaxhighlight>


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

Revision as of 10:24, 3 June 2023

This function removes the element data with the given key for that element. The element data removal is synced with all the clients.

Syntax

bool removeElementData ( element theElement, string key ) 

OOP Syntax Help! I don't understand this!

Method: element:removeData(...)


Required Arguments

  • theElement: The element you wish to remove the data from.
  • key: The key string you wish to remove.

Returns

Returns true if the data was removed succesfully, false if the given key does not exist in the element or the element is invalid.

Example

This will create an element data for know if a player has spawned.

function onPlayerSpawn()
    setElementData(source, "playerSpawned", true)
end
addEventHandler("onPlayerSpawn", root, onPlayerSpawn)

function onPlayerWasted()
    removeElementData(source, "playerSpawned")
end
addEventHandler("onPlayerWasted", root, onPlayerWasted)

See Also