createColRectangle
Client-side
Server-side
Shared
This function creates a collision rectangle. This is a shape that has a position and a width and a depth and infinite height. See Rectangle for a definition of a rectangle. XY marks on the south west corner of the colshape.
Note
Attaching a rectangle colshape to another element may give unexpected results as the origin is not at the rectangle centre. Try using a collision circle for attaching instead.
Tip
To visualize a colshape when writing scripts, use the client console command showcol.
OOP Syntax Help! I don't understand this!
- Method:ColShape.Rectangle(...)
Syntax
colshape|false createColRectangle ( float fX, float fY, float fWidth, float fDepth )Required Arguments
- fX: The X position of the collision rectangle's west side.
- fY: The Y position of the collision rectangle's south side.
- fWidth: The collision rectangle's width.
- fDepth: The collision rectangle's depth.
Returns
- colshape|false: col-rectangle
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!") endend
function setZone(playerSource, commandName, fX, fY, fWidth, fDepth) local fX, fY, fWidth, fDepth = tonumber(fX), tonumber(fY), tonumber(fWidth), tonumber(fDepth) if (not fX) or (not fY) or (not fWidth) or (not fDepth) then outputChatBox("Syntax: /"..commandName.." [X] [Y] [Width] [Depth]", playerSource) else if (theZone) then destroyElement(theZone) end local tempCol = createColRectangle(fX, fY, fWidth, fDepth) addEventHandler("onColShapeHit", tempCol, shapeHit) outputChatBox("Zone has "..(theZone ~= nil and "moved" or "created").."!", playerSource) theZone = tempCol endendaddCommandHandler("set_zone", setZone, false, false)See Also
Colshape Functions
- addColPolygonPoint
- createColCircle
- createColCuboid
- createColPolygon
- createColRectangle
- createColSphere
- createColTube
- getColPolygonHeight
- getColPolygonPointPosition
- getColPolygonPoints
- getColShapeRadius
- getColShapeSize
- getColShapeType
- isInsideColShape
- removeColPolygonPoint
- setColPolygonHeight
- setColPolygonPointPosition
- setColShapeRadius
- setColShapeSize
