SetGarageOpen: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Undo revision 22008 by Dzakub (Talk))
mNo edit summary
 
(8 intermediate revisions by 5 users not shown)
Line 2: Line 2:
{{Server client function}}
{{Server client function}}
This function opens or closes the specified garage door in the world.
This function opens or closes the specified garage door in the world.
 
{{Note|setGarageOpen does not work with ID 32 (Pay 'n' Spray near Royal Casino). This garage has been disabled by Rockstar Games due to floor collision issues (see TheJizzy's video "BETA Leftovers and Glitches" at 12:12 timestamp). You can remove the door by using [[removeWorldModel]] and recreating it for later with [[moveObject]].}}
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 22: Line 22:


-- 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 = createColCube(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)
Line 55: Line 55:
==See Also==
==See Also==
{{World functions}}
{{World functions}}
[[ru:setGarageOpen]]

Latest revision as of 14:08, 7 December 2021

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

[[{{{image}}}|link=|]] Note: setGarageOpen does not work with ID 32 (Pay 'n' Spray near Royal Casino). This garage has been disabled by Rockstar Games due to floor collision issues (see TheJizzy's video "BETA Leftovers and Glitches" at 12:12 timestamp). You can remove the door by using removeWorldModel and recreating it for later with moveObject.

Syntax

bool setGarageOpen ( int garageID, bool open )

Required Arguments

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

Returns

Returns true if successful, false if 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