GetElementsWithinColShape: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(23 intermediate revisions by 13 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
This function is used to retreive a list of all elements in a colshape, of the specified type.
__NOTOC__
 
This function is used to retrieve a list of all elements in a colshape, of the specified type.
{{Note|
* For legacy reasons, a colshape created on the client does not collide with elements already existing at that location until they first move.
* This function doesn't verify whether elements are in the same dimension and interior, additional checks could be implemented manually if they are needed.
}}
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table getElementsWithinColShape ( colshape shape, [ string type ] )  
table getElementsWithinColShape ( colshape theShape [, string elemType = nil ] )  
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP| |[[colshape]]:getElementsWithin|elementsWithin|}}
===Required Arguments===  
===Required Arguments===  
*'''shape:''' The colshape you want to get the elements from.
*'''theShape:''' The colshape you want to get the elements from.


===Optional Arguments===  
===Optional Arguments===  
*'''type:''' The type of element you want a list of. This can be any element type, the common ones being:
*'''elemType:''' The type of element you want a list of. This can be any element type, the common ones being:
**'''"player":''' A player connected to the server
**'''"player":''' A player connected to the server
**'''"vehicle":''': A vehicle
**'''"ped":''' A ped
**'''"vehicle":''' A vehicle
**'''"object":''' An object
**'''"object":''' An object
**'''"pickup":''' A pickup
**'''"pickup":''' A pickup
**'''"blip":''' A blip
**'''"marker":''' A marker
**'''"marker":''' A marker
**'''"spawnpoint":''' A spawnpoint
<!--**'''"spawnpoint":''' A spawnpoint
**'''"remoteclient":''' A remote client connected to the server
**'''"remoteclient":''' A remote client connected to the server
**'''"console":''' The server Console
**'''"console":''' The server Console-->


===Returns===
===Returns===
Returns a ''table'' containing all the elements inside the colshape, of the specified type. Returns an empty ''table'' if there are no elements inside. Returns ''false'' if the colshape is invalid.
Returns a [[table]] containing all the elements inside the colshape, of the specified type. Returns an empty [[table]] if there are no elements inside. Returns ''false'' if the colshape is invalid.


==Example==  
==Example==  
This example retrieves a table of the players in the colshape and prints their name to the chat.
This example retrieves a [[table]] of players inside a colshape and prints their name to the chat.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local colshape = createColSphere ( 1, 2, 3, 4 )
local newColShape = createColSphere (1, 2, 3, 4) -- create our new colshape
local players = getElementsWithinColShape ( colshape, "player" ) -- get all the players inside the sphere
local players = getElementsWithinColShape (newColShape, "player") -- get all the players inside the sphere
for theKey,thePlayer in players do -- use a generic for loop to step through each player
 
  outputChatBox ( getClientName ( thePlayer ) .. " is in our new sphere" ) -- print their name to the chat
for _, thePlayer in ipairs (players) do -- use a generic for loop to step through each player
    outputChatBox (getPlayerName (thePlayer).." is in our new sphere") -- print their name to the chat
end
end
</syntaxhighlight>
</syntaxhighlight>
==Changelog==
{{ChangelogHeader}}
{{ChangelogItem|1.5.5-3.12286|Added elementsWithin OOP variable}}


==See Also==
==See Also==
{{Element_functions}}
{{Element_functions}}
[[hu:getElementsWithinColShape]]

Latest revision as of 17:10, 20 September 2021

This function is used to retrieve a list of all elements in a colshape, of the specified type.

[[{{{image}}}|link=|]] Note:
  • For legacy reasons, a colshape created on the client does not collide with elements already existing at that location until they first move.
  • This function doesn't verify whether elements are in the same dimension and interior, additional checks could be implemented manually if they are needed.

Syntax

table getElementsWithinColShape ( colshape theShape [, string elemType = nil ] ) 

OOP Syntax Help! I don't understand this!

Method: colshape:getElementsWithin(...)
Variable: .elementsWithin


Required Arguments

  • theShape: The colshape you want to get the elements from.

Optional Arguments

  • elemType: The type of element you want a list of. This can be any element type, the common ones being:
    • "player": A player connected to the server
    • "ped": A ped
    • "vehicle": A vehicle
    • "object": An object
    • "pickup": A pickup
    • "marker": A marker

Returns

Returns a table containing all the elements inside the colshape, of the specified type. Returns an empty table if there are no elements inside. Returns false if the colshape is invalid.

Example

This example retrieves a table of players inside a colshape and prints their name to the chat.

local newColShape = createColSphere (1, 2, 3, 4) -- create our new colshape
local players = getElementsWithinColShape (newColShape, "player") -- get all the players inside the sphere

for _, thePlayer in ipairs (players) do -- use a generic for loop to step through each player
    outputChatBox (getPlayerName (thePlayer).." is in our new sphere") -- print their name to the chat
end

Changelog

Version Description
1.5.5-3.12286 Added elementsWithin OOP variable

See Also