IsGarageOpen: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server client function}} This function checks whether or not a specific garage door is open. ==Syntax== <syntaxhighlight lang="lua"> bool isGarageOpen ( int garageID ) </syntaxhighlight> ===Require...)
 
 
(9 intermediate revisions by 6 users not shown)
Line 9: Line 9:


===Required Arguments===  
===Required Arguments===  
*'''garageID:''' The ID that represents the garage door that is being checked.
*'''garageID:''' The [[Garage|garage ID]] that represents the garage door that is being checked.


===Returns===
===Returns===
Returns true if the garage is open, false if it is closed.
Returns ''true'' if the garage is open, ''false'' if it is closed or an invalid garage ID was given.


==Example==  
==Example==  
Line 21: Line 21:


-- create a collision shape and attach event handlers to it when the resource starts
-- create a collision shape and attach event handlers to it when the resource starts
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
addEventHandler("onResourceStart", getResourceRootElement(),
function (resource)
function (resource)
local garageCube = createColCuve(1337, 194, 28, 6, 10, 4)
local garageCube = createColCuboid(1337, 194, 28, 6, 10, 4)
addEventHandler("onColShapeHit", garageCube, onGarageCubeHit)
addEventHandler("onColShapeHit", garageCube, onGarageCubeHit)
addEventHandler("onColShapeLeave", garageCube, onGarageCubeLeave)
addEventHandler("onColShapeLeave", garageCube, onGarageCubeLeave)
end
end)


-- open the door when someone enters the garage's collision shape
-- open the door when someone enters the garage's collision shape
Line 54: Line 54:
==See Also==
==See Also==
{{World functions}}
{{World functions}}
[[Category:Needs_More_Examples]]
 
[[ru:isGarageOpen]]

Latest revision as of 16:45, 11 February 2015

This function checks whether or not a specific garage door is open.

Syntax

bool isGarageOpen ( int garageID )

Required Arguments

  • garageID: The garage ID that represents the garage door that is being checked.

Returns

Returns true if the garage is open, false if it is closed or an invalid garage ID was given.

Example

Click to collapse [-]
Server

This example opens a garage door when a player enters a collision shape near it, and closes it when they leave:

GARAGE_ID = 25

-- create a collision shape and attach event handlers to it when the resource starts
addEventHandler("onResourceStart", getResourceRootElement(),
function (resource)
	local garageCube = createColCuboid(1337, 194, 28, 6, 10, 4)
	addEventHandler("onColShapeHit", garageCube, onGarageCubeHit)
	addEventHandler("onColShapeLeave", garageCube, onGarageCubeLeave)
end)

-- open the door when someone enters the garage's collision shape
function onGarageCubeHit(hitElement, matchingDimension)
	if (getElementType(hitElement) == "player") then
		-- check to make sure the door is closed
		if (not isGarageOpen(GARAGE_ID)) then
			-- open the door
			setGarageOpen(GARAGE_ID, true)
		end
	end
end

-- close the door when someone leaves the garage's collision shape
function onGarageCubeLeave(leaveElement, matchingDimension)
	if (getElementType(leaveElement) == "player") then
		-- check to make sure the door is open
		if (isGarageOpen(GARAGE_ID)) then
			-- close the door
			setGarageOpen(GARAGE_ID, false)
		end
	end
end

See Also