SetGarageOpen: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
Line 17: | Line 17: | ||
==Example== | ==Example== | ||
<section name="Server" class="server" show="true"> | <section name="Server" class="server" show="true"> | ||
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, and closes it when they leave: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
GARAGE_ID = 25 | GARAGE_ID = 25 | ||
-- create a collision shape and attach event handlers to it when the resource starts | |||
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), | addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), | ||
function (resource) | function (resource) | ||
local | local garageCube = createColCuve(1337, 194, 28, 6, 10, 4) | ||
addEventHandler("onColShapeHit", | addEventHandler("onColShapeHit", garageCube, onGarageCubeHit) | ||
addEventHandler("onColShapeLeave", | addEventHandler("onColShapeLeave", garageCube, onGarageCubeLeave) | ||
end | end | ||
-- open the door when someone enters the garage's collision shape | |||
function onGarageCubeHit(hitElement, matchingDimension) | function onGarageCubeHit(hitElement, matchingDimension) | ||
if (getElementType(hitElement) == "player") then | if (getElementType(hitElement) == "player") then | ||
-- check to make sure the door is closed | |||
if (not isGarageOpen(GARAGE_ID)) then | if (not isGarageOpen(GARAGE_ID)) then | ||
-- open the door | |||
setGarageOpen(GARAGE_ID, true) | setGarageOpen(GARAGE_ID, true) | ||
end | end | ||
Line 36: | Line 40: | ||
end | end | ||
-- close the door when someone leaves the garage's collision shape | |||
function onGarageCubeLeave(leaveElement, matchingDimension) | function onGarageCubeLeave(leaveElement, matchingDimension) | ||
if (getElementType(leaveElement) == "player") then | if (getElementType(leaveElement) == "player") then | ||
-- check to make sure the door is open | |||
if (isGarageOpen(GARAGE_ID)) then | if (isGarageOpen(GARAGE_ID)) then | ||
-- close the door | |||
setGarageOpen(GARAGE_ID, false) | setGarageOpen(GARAGE_ID, false) | ||
end | end | ||
Line 47: | Line 54: | ||
==See Also== | ==See Also== | ||
{{World | {{World functions}} | ||
[[Category:Needs_More_Examples]] | [[Category:Needs_More_Examples]] |
Revision as of 08:39, 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 [-]
ServerThis 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(getThisResource()), function (resource) local garageCube = createColCuve(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
- areTrafficLightsLocked
- getAircraftMaxHeight
- getAircraftMaxVelocity
- getCloudsEnabled
- getFarClipDistance
- getFogDistance
- getGameSpeed
- getGravity
- getHeatHaze
- getInteriorSoundsEnabled
- getJetpackMaxHeight
- getMinuteDuration
- getMoonSize
- getOcclusionsEnabled
- getRainLevel
- getSunColor
- getSunSize
- getTime
- getTrafficLightState
- getWeather
- getWindVelocity
- getSkyGradient
- getPlayerBlurLevel
- getZoneName
- isGarageOpen
- removeWorldModel
- resetFarClipDistance
- resetFogDistance
- resetHeatHaze
- resetMoonSize
- resetRainLevel
- resetSkyGradient
- resetSunColor
- resetSunSize
- resetWindVelocity
- restoreAllWorldModels
- restoreWorldModel
- setAircraftMaxHeight
- setAircraftMaxVelocity
- setCloudsEnabled
- setFarClipDistance
- setFogDistance
- setGameSpeed
- setGarageOpen
- setGravity
- setHeatHaze
- setInteriorSoundsEnabled
- setMinuteDuration
- setMoonSize
- setOcclusionsEnabled
- setRainLevel
- setSkyGradient
- setSunColor
- setSunSize
- setTime
- setTrafficLightState
- setTrafficLightsLocked
- setWeather
- setWeatherBlended
- setWindVelocity
- setJetpackMaxHeight
- setPlayerBlurLevel