-- Beginning, gate isn't moving.
isGateOpen = false
isGateMoving = false
gate = {}
gateName = ""
-- Table of gates. Add more gates here if you want (model of gate)
gates = {
["gateOne"] = createObject ( 971, 2480.3999023438, -1722, 16.1, 0, 0, 358 ),
["gateTwo"] = createObject ( 971, 2482.5634765625,-1688.87890625,13.513326644897, 0, 0, 358 )
}
-- Table of gateTriggers (colShapes)
gateTriggers = {
["gateOne"] = createColRectangle( 2476.541015625,-1724.421875, 12, 10 ),
["gateTwo"] = createColRectangle( 2480.6064453125,-1691.10351562, 12, 10 )
}
-- This function OPENS the gate.
function openGateFunc(source)
if isElementWithinColShape(source,gateTriggers.gateOne)then -- If the player is within the colRectangle that fits gateOne then:
gate = gates.gateOne -- Lets the server know gate we are using.
gateName = "Gate One" -- Lets the server know what the name of the gate we are using.
elseif isElementWithinColShape(source,gateTriggers.gateTwo)then
gate = gates.gateTwo -- Same as above
gateName = "Gate Two" -- Same as above
end
if(isGateMoving == false)then -- If the gate is NOT ALREADY MOVING then do:
local x,y,z = getElementPosition(gate) -- Get the x,y,z Position of the gate we are using.
if(isGateOpen == false)then -- If the gate IS NOT ALREADY OPEN then do:
triggerClientEvent(source,"playGateSound",getRootElement()) -- Plays a "beep" sound, clientside.
moveObject( gate, 3500, x + 8, y, z ) -- Moves the gate + 8 units on the X axis, to open the gate.
isGateOpen = true -- Lets the server know that the gate is open.
isGateMoving = true -- Lets the server know that the gate is moving.
setTimer(triggerEvent,3500,1,"isGateMovingEvent",getRootElement()) -- After the gate has stopped moving, after 3.5secs, this event will trigger and change, "isGateMoving" to false.
setTimer(triggerEvent,8000,1,"closeGate",getRootElement(),gate,gateName) -- 8 Seconds after the gate has opened, it will close on its own.
outputChatBox("Opening Gate: "..gateName,source) -- Tells the client that the gate he is using is opening. This line can be removed if you dont like it.
end
end
return
end
addEventHandler("onColShapeHit",gateTriggers.gateOne,openGateFunc)
addEventHandler("onColShapeHit",gateTriggers.gateTwo,openGateFunc)
addEvent("openGate",true)
addEventHandler("openGate",getRootElement(),openGateFunc)
function closeGateFunc(gate,gateName)
local x,y,z = getElementPosition(gate)
if(isGateMoving == false)then
if(isGateOpen == true)then
moveObject( gate, 3500, x - 8, y, z )
isGateOpen = false
isGateMoving = true
setTimer(triggerEvent,3500,1,"isGateMovingEvent",getRootElement())
outputChatBox("Closing Gate: "..gateName,source)
end
end
return
end
addEvent("closeGate",true)
addEventHandler("closeGate",getRootElement(),closeGateFunc)
function isGateMovingFunc()
isGateMoving = false
gate = {}
end
addEvent("isGateMovingEvent",true)
addEventHandler("isGateMovingEvent",getRootElement(),isGateMovingFunc)