IsElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Undo revision 50124 by Marcin778 (talk))
 
Line 1: Line 1:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
__NOTOC__
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{Server client function}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
This function checks if a value is an [[element]] or not.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{Note|This function is not reliable as element ids are eventually recycled. Always make sure you nil variables containing an element after calling [[destroyElement]] or handle [[onElementDestroy]] for players and elements that might be destroyed by another resource}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==Syntax==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">bool isElement ( var theValue )</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
===Required Arguments===
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
* '''theValue''': The value that we want to check.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
===Returns===
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
Returns ''true'' if the passed value is an element, ''false'' otherwise.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==Example==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<section name="Server" class="server" show="true">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
This serverside function kills a player when it's passed his name or his element.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
function killPlayer2 ( argument )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- if the argument is an element, and also a player,
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
if isElement( argument ) and getElementType( argument ) == "player" then
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- kill him
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
killPed ( argument )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- if it isn't an element, but a string, it could be a name
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
elseif type ( argument ) == "string" then
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- retrieve the player with that name
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
local playerElement = getPlayerFromName( argument )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- if a player with such a name exists,
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
if playerElement then
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
-- kill him
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
killPed ( playerElement )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</section>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==See Also==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{Element functions}}

Latest revision as of 18:38, 1 January 2017

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

[[{{{image}}}|link=|]] Note: This function is not reliable as element ids are eventually recycled. Always make sure you nil variables containing an element after calling destroyElement or handle onElementDestroy for players and elements that might be destroyed by another resource

Syntax

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
		killPed ( 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 = getPlayerFromName( argument )
		-- if a player with such a name exists,
		if playerElement then
			-- kill him
			killPed ( playerElement )
		end
	end
end

See Also