IsElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Added template, sections, minor changes)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server client function}}
This function checks if a value is an [[element]] or not.
This function checks if a value is an [[element]] or not.


==Syntax==
==Syntax==
<section name="Server and client" class="both" show="true">
<syntaxhighlight lang="lua">bool isElement ( var theValue )</syntaxhighlight>
<syntaxhighlight lang="lua">bool isElement ( var theValue )</syntaxhighlight>


Line 10: Line 12:
===Returns===
===Returns===
Returns ''true'' if the passed value is an element, ''false'' otherwise.
Returns ''true'' if the passed value is an element, ''false'' otherwise.
</section>


==Example==
==Example==
This function kills a player when it's passed the player element, or his name.
<section name="Server" class="server" show="true">
This serverside function kills a player when it's passed his name or his element.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function killPlayer2 ( argument )
function killPlayer2 ( argument )
Line 32: Line 36:
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Revision as of 22:08, 12 August 2007

This function checks if a value is an element or not.

Syntax

Click to collapse [-]
Server and client
bool isElement ( var theValue )

Required Arguments

  • theValue: The value that we want to check.

Returns

Returns true if the passed value is an element, false otherwise.

Example

Click to collapse [-]
Server

This serverside function kills a player when it's passed his name or his element.

function killPlayer2 ( argument )
	-- if the argument is an element, and also a player,
	if isElement( argument ) and getElementType( argument ) == "player" then
		-- kill him
		killPlayer ( argument )

	-- if it isn't an element, but a string, it could be a name
	elseif type ( argument ) == "string" then
		-- retrieve the player with that name
		local playerElement = getPlayerFromNick( argument )
		-- if a player with such a name exists,
		if playerElement then
			-- kill him
			killPlayer ( playerElement )
		end
	end
end

See Also