CreateElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Cleanup, added Template:Needs Checking: createElement doesn't check for hardcoded types, syntax should be obsoleted)
Line 1: Line 1:
{{Needs Checking|createElement doesn't actually restrict element types. You can create any abstract element with a hardcoded type - I'm not really sure if this is a bug or a feature.<br>Also, the ID element should be optional and go after the type. --[[User:Jbeta|jbeta]] 12:26, 25 September 2007 (CDT)}}
__NOTOC__
__NOTOC__
{{Server client function}}
{{Server client function}}
This function is used to create dummy elements in the element table, but do not have a counterpart within the San Andreas world. A common use for this function is for creating custom elements, such as a Flag or a Base.
This function is used to create a new dummy element in the [[element tree]] which do not necessarily represent an entity within the San Andreas world. A common use for this function is for creating custom elements, such as a Flag or a Base.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element createElement ( string id, string type )
element createElement ( string elementID, string elementType )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''id:''' The ID of the element being created.
*'''elementID:''' The ID of the element being created.
*'''type:''' The type of element being created. This value will be returned if getElementType is used on it.
*'''elementType:''' The type of element being created.


===Returns===
===Returns===
Returns the element if it was successfully created. Returns ''false'' if the arguments are wrong or if the type is not allowed. Unallowed types include hard-coded MTA elements (such as "vehicle") and the type "dummy".
Returns the element if it was successfully created. Returns ''false'' if the arguments are wrong.


==Example==
==Example==
This example creates a "flag" element, named "blue", which will be at the root of the element tree.
This example creates a "flag" element, named "blue", which will be at the resource's dynamic map.


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 22: Line 23:
</syntaxhighlight>
</syntaxhighlight>


This will have the same effect as having this in .map:
Except for it being placed in a different map root, that line will have the same effect as having this in a .map file:
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<flag id="blue" />
<flag id="blue" />
Line 28: Line 29:


==See Also==  
==See Also==  
{{element functions}}
{{Element functions}}

Revision as of 17:26, 25 September 2007

Dialog-information.png This article needs checking.

Reason(s): createElement doesn't actually restrict element types. You can create any abstract element with a hardcoded type - I'm not really sure if this is a bug or a feature.
Also, the ID element should be optional and go after the type. --jbeta 12:26, 25 September 2007 (CDT)

This function is used to create a new dummy element in the element tree which do not necessarily represent an entity within the San Andreas world. A common use for this function is for creating custom elements, such as a Flag or a Base.

Syntax

element createElement ( string elementID, string elementType )

Required Arguments

  • elementID: The ID of the element being created.
  • elementType: The type of element being created.

Returns

Returns the element if it was successfully created. Returns false if the arguments are wrong.

Example

This example creates a "flag" element, named "blue", which will be at the resource's dynamic map.

blueTeamFlag = createElement( "blue", "flag" )

Except for it being placed in a different map root, that line will have the same effect as having this in a .map file:

<flag id="blue" />

See Also