GetElementRadius: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Added OOP syntax introduced in r6987 and improved the page)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__
__NOTOC__
This function gets the radius from a element. Depending on the shape of the element this may be an accurate or very inaccurate way to detect if the player is near or within the element.  
This function gets the radius of an [[element]]. Normally, sphere or circle-shaped elements tend to return a more accurate and expected radius than others with another shapes.
 
<!-- This could really do with saying what elements it affects, and what you'd expect to get back from them -->
[[Category:Incomplete]] <!-- Do not remove unless you finish the documentation. -->


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float getElementRadius ( element theElement )
float getElementRadius ( element theElement )
</syntaxhighlight>  
</syntaxhighlight>
{{New feature/item|3.0141|1.4.0|6987|{{OOP||[[element]]:getRadius|radius}}}}


===Required Arguments===  
===Required Arguments===  
*'''theElement:''' The element.
*'''theElement:''' The element to get the radius of. It can be any entity type, such as:
** '''[[player|Players]]'''.
** '''[[ped|Peds]]'''.
** '''[[vehicle|Vehicles]]'''.
** '''[[object|Objects]]'''.


===Returns===
===Returns===
Returns ''float'' as radius, ''false'' otherwise.
Returns a ''float'' containing the radius if the element is valid, ''false'' otherwise.


==Example==  
==Example==  
This example shows how to get the radius of a player
This example shows how to get and output the radius of every player who types the ''/getmyradius'' command (which will always be ''1'').
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function myCommandHandler(command)
local function outputLocalPlayerRadius()
local myradius = getElementRadius ( getLocalPlayer() )
    outputChatBox("Your radius is " .. getElementRadius(localPlayer))
if (myradius) then
outputChatBox("Radius of my player is: " .. myradius)
else
outputChatBox("Error")
end
end
end
 
addCommandHandler("getmyradius", outputLocalPlayerRadius)
addCommandHandler("getmyradius", myCommandHandler)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Client element functions}}
{{Client element functions}}

Latest revision as of 13:53, 31 December 2014

This function gets the radius of an element. Normally, sphere or circle-shaped elements tend to return a more accurate and expected radius than others with another shapes.

Syntax

float getElementRadius ( element theElement )

OOP Syntax Help! I don't understand this!

Method: element:getRadius(...)
Variable: .radius

Required Arguments

Returns

Returns a float containing the radius if the element is valid, false otherwise.

Example

This example shows how to get and output the radius of every player who types the /getmyradius command (which will always be 1).

local function outputLocalPlayerRadius()
    outputChatBox("Your radius is " .. getElementRadius(localPlayer))
end
addCommandHandler("getmyradius", outputLocalPlayerRadius)

See Also