CreateColSphere: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(11 intermediate revisions by 8 users not shown)
Line 1: Line 1:
[[Category:Incomplete]]
[[Category:Need Syntax]]
__NOTOC__  
__NOTOC__  
This function is for blahblah.. not defined yet
{{Server client function}}
 
This function creates a collision sphere. This is a shape that has a position and a radius. See [http://en.wikipedia.org/wiki/Sphere Wikipedia] for a definition of a sphere.
{{VisualizeColshape}}
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
INSERT SYNTAX HERE             
colshape createColSphere ( float fX, float fY, float fZ, float fRadius )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP| |ColShape.Sphere||}}
===Required Arguments===  
===Required Arguments===  
*'''argumentName:''' description
*'''fX:''' The collision sphere's center point's X axis position.
 
*'''fY:''' The collision sphere's center point's Y axis position.
===Optional Arguments===
*'''fZ:''' The collision sphere's center point's Z axis position.
{{OptionalArg}}
*'''fRadius:''' The collision sphere's radius.
*'''argumentName2:''' descriptiona
*'''argumentName3:''' description


===Returns===
===Returns===
Returns ''true'' if blah, ''false'' otherwise.
Returns a [[colshape]] element if successful, ''false'' if invalid arguments were passed to the function.


==Example==  
==Example==  
This example does...
<section name="Server" class="server" show="true">
'''Example 1:''' This example displays a chat message when a player enters the colshape and allows the colshape to be created using a console function ''set_zone''.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
local theZone
blabhalbalhb --abababa
 
--This line does this...
function shapeHit(thePlayer)
mooo
    outputChatBox(getPlayerName(thePlayer).. " is in the zone!")
end
 
function setZone(playerSource, commandName, fX, fY, fZ, fRadius)
    local fX, fY, fZ, fRadius = tonumber(fX), tonumber(fY), tonumber(fZ), tonumber(fRadius)
    if (not fX) or (not fY) or (not fZ) or (not fRadius) then
        outputChatBox("Syntax: /"..commandName.." [X] [Y] [Z] [Radius]", playerSource)
    else
        if (theZone ~= nil) then
            destroyElement(theZone)
        end
        local tempCol = createColSphere(fX, fY, fZ, 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)
</syntaxhighlight>
'''Example 2:''' This example allows creation of claymores, which trigger and explode.
<syntaxhighlight lang="lua">function createClaymore ( x,y,z, creator )
local x,y,z = getElementPosition ( creator )
local claymoreObject = createObject ( 1945, x, y, z - 1, 0, 0, 90 ) --create an object which looks like a claymore
local claymoreCol = createColSphere ( x, y, z, 1 ) --create a col sphere with radius 1
setElementData ( claymoreCol , "type", "claymore" ) --store the type of colshape so it can be retrieved
setElementData ( claymoreCol, "object", claymoreObject ) --store the object of the claymore
setElementData ( claymoreCol, "creatorPlayer", creator ) --store the person who created it
end
 
function claymoreHit ( player, matchingDimension )
if getElementData ( source, "type" ) == "claymore" then --ensure its a claymore
--retrieve the object associated to the claymore, and who created it
local claymoreObject = getElementData ( source, "object" )
local claymoreCreator = getElementData ( source, "creatorPlayer" )
--get the position of the claymore
local x,y,z = getElementPosition ( source )
createExplosion ( x,y,z, 12, claymoreCreator ) --create an explosion, associated to the creator, of a small size at the col's position
--destroy the claymore object, and the col shape so it doesnt trigger again.
destroyElement ( claymoreObject )
destroyElement ( source )
end
end
addEventHandler ( "onColShapeHit", getRootElement(), claymoreHit )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{FunctionArea_Functions}}
{{Collision shape functions}}
 
[[hu:createColSphere]]

Latest revision as of 09:26, 6 November 2023

This function creates a collision sphere. This is a shape that has a position and a radius. See Wikipedia for a definition of a sphere.

[[{{{image}}}|link=|]] Tip: To visualize a colshape when writing scripts, use the client console command showcol

Syntax

colshape createColSphere ( float fX, float fY, float fZ, float fRadius )

OOP Syntax Help! I don't understand this!

Method: ColShape.Sphere(...)


Required Arguments

  • fX: The collision sphere's center point's X axis position.
  • fY: The collision sphere's center point's Y axis position.
  • fZ: The collision sphere's center point's Z axis position.
  • fRadius: The collision sphere's radius.

Returns

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

Example

Click to collapse [-]
Server

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

local theZone

function shapeHit(thePlayer)
    outputChatBox(getPlayerName(thePlayer).. " is in the zone!")
end

function setZone(playerSource, commandName, fX, fY, fZ, fRadius)
    local fX, fY, fZ, fRadius = tonumber(fX), tonumber(fY), tonumber(fZ), tonumber(fRadius)
    if (not fX) or (not fY) or (not fZ) or (not fRadius) then
        outputChatBox("Syntax: /"..commandName.." [X] [Y] [Z] [Radius]", playerSource)
    else
        if (theZone ~= nil) then
            destroyElement(theZone)
        end
        local tempCol = createColSphere(fX, fY, fZ, 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)

Example 2: This example allows creation of claymores, which trigger and explode.

function createClaymore ( x,y,z, creator )
	local x,y,z = getElementPosition ( creator )
	local claymoreObject = createObject ( 1945, x, y, z - 1, 0, 0, 90 ) --create an object which looks like a claymore
	local claymoreCol = createColSphere ( x, y, z, 1 ) --create a col sphere with radius 1
	setElementData ( claymoreCol , "type", "claymore" ) --store the type of colshape so it can be retrieved
	setElementData ( claymoreCol, "object", claymoreObject ) --store the object of the claymore
	setElementData ( claymoreCol, "creatorPlayer", creator ) --store the person who created it
end

function claymoreHit ( player, matchingDimension )
	if getElementData ( source, "type" ) == "claymore" then --ensure its a claymore
		--retrieve the object associated to the claymore, and who created it
		local claymoreObject = getElementData ( source, "object" )
		local claymoreCreator = getElementData ( source, "creatorPlayer" )
		--get the position of the claymore
		local x,y,z = getElementPosition ( source )
		createExplosion ( x,y,z, 12, claymoreCreator ) --create an explosion, associated to the creator, of a small size at the col's position
		--destroy the claymore object, and the col shape so it doesnt trigger again.
		destroyElement ( claymoreObject )
		destroyElement ( source )
	end
end
addEventHandler ( "onColShapeHit", getRootElement(), claymoreHit )

See Also