IsElementLocal: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added OOP syntax introduced in r6987)
(Improve example.)
Line 18: Line 18:
This clientside function destroys all local radar blips.
This clientside function destroys all local radar blips.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function destroyAllLocalBlips ( )
function destroyAllLocalBlips()
-- get a table containing all blips
-- Get a table containing all blips
local allBlips = getElementsByType( "blip" )
 
-- for each blip in this table,
local allBlips = getElementsByType("blip")
for index, theBlip in ipairs ( allBlips ) do
 
-- check if it's a blip that only exists locally,
-- For each blip in this table
if isElementLocal ( theBlip ) then
 
-- and destroy it in that case
for blipID = 1, #allBlips do
destroyElement ( theBlip )
local blipElement = allBlips[blipID]
 
-- Check if it's a blip that only exists locally
 
if isElementLocal(blipElement) then
 
-- And destroy it in that case
 
destroyElement(blipElement)
end
end
end
end

Revision as of 08:53, 27 October 2021

This function checks whether a clientside element is local to the client (doesn't exist in the server) or not.

Syntax

bool isElementLocal ( element theElement )

OOP Syntax Help! I don't understand this!

Method: element:isLocal(...)
Variable: .localElement

Required Arguments

  • theElement: The element that we want to check.

Returns

Returns true if the passed element is local, false if not or if invalid parameters are passed.

Example

This clientside function destroys all local radar blips.

function destroyAllLocalBlips()
	-- Get a table containing all blips

	local allBlips = getElementsByType("blip")

	-- For each blip in this table

	for blipID = 1, #allBlips do
		local blipElement = allBlips[blipID]

		-- Check if it's a blip that only exists locally

		if isElementLocal(blipElement) then

			-- And destroy it in that case

			destroyElement(blipElement)
		end
	end
end

See Also

Shared