IsElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
Line 20: Line 20:
if isElement( argument ) and getElementType( argument ) == "player" then
if isElement( argument ) and getElementType( argument ) == "player" then
-- kill him
-- kill him
killPlayer ( argument )
killPed ( argument )


-- if it isn't an element, but a string, it could be a name
-- if it isn't an element, but a string, it could be a name
Line 29: Line 29:
if playerElement then
if playerElement then
-- kill him
-- kill him
killPlayer ( playerElement )
killPed ( playerElement )
end
end
end
end

Revision as of 20:50, 21 September 2011

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

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

See Also