createColCircle | Multi Theft Auto: Wiki Skip to content

createColCircle

Client-side
Server-side
Shared

This function creates a collision circle. This is a shape that has a position and a radius and infinite height. Events will be triggered when a element enters or leaves it.

Tip

To visualize a colshape when writing scripts, use the client console command showcol.

OOP Syntax Help! I don't understand this!

Syntax

colshape|false createColCircle ( float fX, float fY, float radius )
Required Arguments
  • fX: The collision circle's center point's X axis position.
  • fY: The collision circle's center point's Y axis position.
  • radius: The radius of the collision circle. Can not be smaller than 0.1.

Returns

  • colshape|false: col-circle

Returns a colshape element if successful, false if invalid arguments were passed to the function.

Code Examples

server

This example displays a chat message when a player enters the colshape and allows the colshape to be created using a console command set_zone.

local theZone
local function shapeHit(hitElement, matchingDimensions)
if (hitElement and getElementType(hitElement) == 'player' and matchingDimensions) then
outputChatBox(getPlayerName(thePlayer).. " is in the zone!")
end
end
function setZone(playerSource, commandName, fX, fY, fRadius)
local fX, fY, fRadius = tonumber(fX), tonumber(fY), tonumber(fRadius)
if (not fX) or (not fY) or (not fRadius) then
outputChatBox("Syntax: /"..commandName.." [X] [Y] [Radius]", playerSource)
else
if (theZone) then
destroyElement(theZone)
end
local tempCol = createColCircle(fX, fY, fRadius)
addEventHandler("onColShapeHit", tempCol, shapeHit)
outputChatBox("Zone has "..(theZone ~= nil and "moved" or "created").."!", playerSource)
theZone = tempCol
end
end
addCommandHandler("set_zone", setZone, false, false)