AddColPolygonPoint: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (1-based index)
(Remove obsolete Requirements section)
 
(4 intermediate revisions by 2 users not shown)
Line 21: Line 21:
Returns ''true'' if the polygon was changed, ''false'' if invalid arguments were passed.
Returns ''true'' if the polygon was changed, ''false'' if invalid arguments were passed.


==Example==
===Example===
<section name="Server" class="server" show="true">
This examples adds a point to an existing polygon shape by a command.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
TODO
local shape = createColPolygon(2, 2, 5, 5, 6, 6, 8, 8) -- Somewhere in the map
function addPointToPolygon(plr, cmd, fX, fY, index)
    if (not fX or not fY) then
        outputChatBox("Correct syntax: /addpoint <fX fY>", plr, 255, 25, 25)
        return false
    end
    if (not index or index == 0) then
        addColPolygonPoint(shape, fX, fY)
    else
        addColPolygonPoint(shape, fX, fY, index)
    end
    outputChatBox("Point added", plr, 0, 255, 0)
end
addCommandHandler("addpoint", addPointToPolygon)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Collision_shape_functions}}
{{Collision_shape_functions}}

Latest revision as of 17:20, 7 November 2024

This function is used to add a new point to an existing colshape polygon.

Syntax

bool addColPolygonPoint ( colshape shape, float fX, float fY [, int index = 0 ] )  

OOP Syntax Help! I don't understand this!

Method: colshape:addPoint(...)
Counterpart: removeColPolygonPoint


Required Arguments

  • shape: The colshape polygon you wish add a point to.
  • fX: The X position of the new bound point.
  • fY: The Y position of the new bound point.

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.

  • index: The index where the new point will be inserted in the polygon. The points are indexed in order, with 1 being the first bound point. Passing 0 will insert the point as the last one in the polygon.

Returns

Returns true if the polygon was changed, false if invalid arguments were passed.

Example

Click to collapse [-]
Server

This examples adds a point to an existing polygon shape by a command.

local shape = createColPolygon(2, 2, 5, 5, 6, 6, 8, 8) -- Somewhere in the map
function addPointToPolygon(plr, cmd, fX, fY, index)
    if (not fX or not fY) then
        outputChatBox("Correct syntax: /addpoint <fX fY>", plr, 255, 25, 25)
        return false
    end
    if (not index or index == 0) then
        addColPolygonPoint(shape, fX, fY)
    else
        addColPolygonPoint(shape, fX, fY, index)
    end
    outputChatBox("Point added", plr, 0, 255, 0)
end
addCommandHandler("addpoint", addPointToPolygon)

See Also