SetGarageOpen: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server client function}} This function opens or closes the specified garage door in the world. ==Syntax== <syntaxhighlight lang="lua"> void setGarageOpen ( int garageID, bool open ) </code...)
 
No edit summary
Line 19: Line 19:
This example opens a garage door when a player enters a collision shape near it:
This example opens a garage door when a player enters a collision shape near it:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
GARAGE_ID = 25
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
function (resource)
function (resource)
local colCube = createColCuve(1337, 194, 28, 6, 10, 4)
addEventHandler("onColShapeHit", colCube, onGarageCubeHit)
addEventHandler("onColShapeLeave", colCube, onGarageCubeLeave)
end
function onGarageCubeHit(hitElement, matchingDimension)
if (getElementType(hitElement) == "player") then
if (not isGarageOpen(GARAGE_ID)) then
setGarageOpen(GARAGE_ID, true)
end
end
end


function onGarageCubeLeave(leaveElement, matchingDimension)
if (getElementType(leaveElement) == "player") then
if (isGarageOpen(GARAGE_ID)) then
setGarageOpen(GARAGE_ID, false)
end
end
end
end
)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 08:33, 18 September 2008

This function opens or closes the specified garage door in the world.

Syntax

void setGarageOpen ( int garageID, bool open )

Required Arguments

  • garageID: The ID that represents the garage door being opened or closed.
  • isOpen: A boolean indicating whether or not to open the door.

Returns

This function does not return anything.

Example

Click to collapse [-]
Server

This example opens a garage door when a player enters a collision shape near it:

GARAGE_ID = 25

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
function (resource)
	local colCube = createColCuve(1337, 194, 28, 6, 10, 4)
	addEventHandler("onColShapeHit", colCube, onGarageCubeHit)
	addEventHandler("onColShapeLeave", colCube, onGarageCubeLeave)
end

function onGarageCubeHit(hitElement, matchingDimension)
	if (getElementType(hitElement) == "player") then
		if (not isGarageOpen(GARAGE_ID)) then
			setGarageOpen(GARAGE_ID, true)
		end
	end
end

function onGarageCubeLeave(leaveElement, matchingDimension)
	if (getElementType(leaveElement) == "player") then
		if (isGarageOpen(GARAGE_ID)) then
			setGarageOpen(GARAGE_ID, false)
		end
	end
end

See Also

Template:World shape functions