CreateRadarArea: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Fixed syntax)
 
(24 intermediate revisions by 18 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server client function}}
This function can be used to create custom radar areas on the radar.
This function can be used to create custom radar areas on the radar.
==Syntax==
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
radararea createRadarArea ( float startPosX, float startPosY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255, element visibleTo = root ] )
</syntaxhighlight>
</section>


==Syntax==  
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
radararea createRadarArea ( float x, float y, float sizex, float sizey, int r, int g, int b, int a, [ visibleTo=getRootElement () ] )            
radararea createRadarArea ( float startPosX, float startPosY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255 ] )
</syntaxhighlight>  
</syntaxhighlight>  
</section>
[[File:Mta-screen 2020-04-27 16-28-13.png|thumb|Radar Area on map]] [[File:Mta-screen 2020-04-27 16-28-38.png|thumb|Radar Area on minimap]]
{{OOP||[[radararea|RadarArea]]}}


===Required Arguments===  
===Required Arguments===  
*'''x:''' A float representing the origin 'x' position of the radar area
*'''startPosX:''' A float representing the origin 'x' position of the radar area.
*'''y:''' A float representing the origin 'y' position of the radar area
*'''startPosY:''' A float representing the origin 'y' position of the radar area.
*'''sizex:''' A float representing the width of the radar area, going in an east direction
*'''sizeX:''' A float representing the width of the radar area.
*'''sizey:''' A float representing the height of the radar area, going in a south direction
*'''sizeY:''' A float representing the height of the radar area.
 
===Optional Arguments===
{{OptionalArg}}


*'''r:''' An integer representing the amount of red in the color.  Maximum value is 255
*'''r:''' An integer representing the amount of red in the color.  Maximum value is 255
Line 17: Line 31:
*'''b:''' An integer representing the amount of blue in the color.  Maximum value is 255
*'''b:''' An integer representing the amount of blue in the color.  Maximum value is 255
*'''a:''' An integer representing the amount of alpha in the color.  This allows setting the transparency of the radar area.  255 is opaque and 0 is transparent.
*'''a:''' An integer representing the amount of alpha in the color.  This allows setting the transparency of the radar area.  255 is opaque and 0 is transparent.
*'''visibleTo:''' An [[element]] that you wish to restrict the [[visibility]] of the radar area to. (Server function only)


Note: The origin position specified by the ''x'' and ''y'' arguments is the bottom left (or south west) corner of the area.
==Example==
<section name="Server" class="server" show="true">
This example creates a radar area for the King of the hill script, and a colsquare. When the player enters the radar area it flashes, and stops flashing when a player leaves it.
<syntaxhighlight lang="lua">
-- create our hill area for our gamemode
local hillArea = createColRectangle ( -2171.0678710938, 678.17950439453, 15, 15 )
local hillRadar = createRadarArea ( -2183.5678710938, 705.67950439453, 40, -40, 0, 255, 0, 175 )


===Optional Arguments===
-- add hill_Enter as a handler for when a player enters the hill area
{{OptionalArg}}
function hill_Enter ( thePlayer, matchingDimension )
*'''visibleto:''' An element or elements that you wish to restrict the visibility of the radar area to.
        -- announce to everyone that the player entered the hill
        if (getElementType(thePlayer) == "player") then
                outputChatBox( getPlayerName(thePlayer) .. " entered the zone!", root, 255, 255, 109 )
                setRadarAreaFlashing ( hillRadar, true )
        end
end
addEventHandler ( "onColShapeHit", hillArea, hill_Enter )


==Example==
-- add hill_Enter as a handler for when a player leaves the hill area
This example creates a radar area when a player spawns, only visible to himself.
function hill_Exit ( thePlayer, matchingDimension )
<syntaxhighlight lang="lua">
        -- check if the player is not dead
addEventHandler ( "onPlayerSpawn", root, "playerSpawn" ) --add an event handler for onPlayerSpawn
        if (getElementType(thePlayer) == "player") then
function playerSpawn () --when a player spawns
                if isPedDead ( thePlayer ) ~= true then
    createRadarArea ( 0, 0, 5, 5, 0, 255, 0, 150, source ) --create a green radar area at 0, 0 which is only visible to the player
                        -- if he was alive, announce to everyone that the player has left the hill
                        outputChatBox ( getPlayerName(thePlayer) .. " left the zone!", root, 255, 255, 109 )
                        setRadarAreaFlashing ( hillRadar, false )
                end
        end
end
end
addEventHandler ( "onColShapeLeave", hillArea, hill_Exit )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Radar area_functions}}
{{Radar area_functions}}

Latest revision as of 08:18, 17 July 2024

This function can be used to create custom radar areas on the radar.

Syntax

Click to collapse [-]
Server
radararea createRadarArea ( float startPosX, float startPosY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255, element visibleTo = root ] )
Click to collapse [-]
Client
radararea createRadarArea ( float startPosX, float startPosY, float sizeX, float sizeY, [ int r = 255, int g = 0, int b = 0, int a = 255 ] )
Radar Area on map
Radar Area on minimap

OOP Syntax Help! I don't understand this!

Method: RadarArea(...)


Required Arguments

  • startPosX: A float representing the origin 'x' position of the radar area.
  • startPosY: A float representing the origin 'y' position of the radar area.
  • sizeX: A float representing the width of the radar area.
  • sizeY: A float representing the height of the radar area.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • r: An integer representing the amount of red in the color. Maximum value is 255
  • g: An integer representing the amount of green in the color. Maximum value is 255
  • b: An integer representing the amount of blue in the color. Maximum value is 255
  • a: An integer representing the amount of alpha in the color. This allows setting the transparency of the radar area. 255 is opaque and 0 is transparent.
  • visibleTo: An element that you wish to restrict the visibility of the radar area to. (Server function only)

Example

Click to collapse [-]
Server

This example creates a radar area for the King of the hill script, and a colsquare. When the player enters the radar area it flashes, and stops flashing when a player leaves it.

-- create our hill area for our gamemode
local hillArea = createColRectangle ( -2171.0678710938, 678.17950439453, 15, 15 )
local hillRadar = createRadarArea ( -2183.5678710938, 705.67950439453, 40, -40, 0, 255, 0, 175 )

-- add hill_Enter as a handler for when a player enters the hill area
function hill_Enter ( thePlayer, matchingDimension )
        -- announce to everyone that the player entered the hill
        if (getElementType(thePlayer) == "player") then
                outputChatBox( getPlayerName(thePlayer) .. " entered the zone!", root, 255, 255, 109 )
                setRadarAreaFlashing ( hillRadar, true )
        end
end
addEventHandler ( "onColShapeHit", hillArea, hill_Enter )

-- add hill_Enter as a handler for when a player leaves the hill area
function hill_Exit ( thePlayer, matchingDimension )
        -- check if the player is not dead
        if (getElementType(thePlayer) == "player") then
                if isPedDead ( thePlayer ) ~= true then
                        -- if he was alive, announce to everyone that the player has left the hill
                        outputChatBox ( getPlayerName(thePlayer) .. " left the zone!", root, 255, 255, 109 )
                        setRadarAreaFlashing ( hillRadar, false )
                end
        end
end
addEventHandler ( "onColShapeLeave", hillArea, hill_Exit )

See Also