Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: Lua  |  size: 2.97 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- Beginning, gate isn't moving.
  2. isGateOpen = false
  3. isGateMoving = false
  4. gate = {}
  5. gateName = ""
  6.  
  7. -- Table of gates. Add more gates here if you want (model of gate)
  8. gates = {
  9. ["gateOne"] = createObject ( 971, 2480.3999023438, -1722, 16.1, 0, 0, 358 ),
  10. ["gateTwo"] = createObject ( 971, 2482.5634765625,-1688.87890625,13.513326644897, 0, 0, 358 )
  11. }
  12.  
  13. -- Table of gateTriggers (colShapes)
  14. gateTriggers = {
  15. ["gateOne"] = createColRectangle( 2476.541015625,-1724.421875, 12, 10 ),
  16. ["gateTwo"] = createColRectangle( 2480.6064453125,-1691.10351562, 12, 10 )
  17. }
  18.  
  19. -- This function OPENS the gate.
  20. function openGateFunc(source)
  21. if isElementWithinColShape(source,gateTriggers.gateOne)then     -- If the player is within the colRectangle that fits gateOne then:
  22.         gate = gates.gateOne    -- Lets the server know gate we are using.
  23.         gateName = "Gate One"   -- Lets the server know what the name of the gate we are using.
  24. elseif isElementWithinColShape(source,gateTriggers.gateTwo)then
  25.         gate = gates.gateTwo    -- Same as above
  26.         gateName = "Gate Two"   -- Same as above
  27. end
  28. if(isGateMoving == false)then   -- If the gate is NOT ALREADY MOVING then do:
  29. local x,y,z = getElementPosition(gate)  -- Get the x,y,z Position of the gate we are using.
  30.                 if(isGateOpen == false)then     -- If the gate IS NOT ALREADY OPEN then do:
  31.                         triggerClientEvent(source,"playGateSound",getRootElement())     -- Plays a "beep" sound, clientside.
  32.                         moveObject( gate, 3500, x + 8, y, z ) -- Moves the gate + 8 units on the X axis, to open the gate.
  33.                         isGateOpen = true       -- Lets the server know that the gate is open.
  34.                         isGateMoving = true     -- Lets the server know that the gate is moving.
  35.                         setTimer(triggerEvent,3500,1,"isGateMovingEvent",getRootElement()) -- After the gate has stopped moving, after 3.5secs, this event will trigger and change, "isGateMoving" to false.
  36.                         setTimer(triggerEvent,8000,1,"closeGate",getRootElement(),gate,gateName) -- 8 Seconds after the gate has opened, it will close on its own.
  37.                         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.
  38.                 end
  39.         end
  40. return
  41. end
  42. addEventHandler("onColShapeHit",gateTriggers.gateOne,openGateFunc)
  43. addEventHandler("onColShapeHit",gateTriggers.gateTwo,openGateFunc)
  44. addEvent("openGate",true)
  45. addEventHandler("openGate",getRootElement(),openGateFunc)
  46.  
  47.  
  48. function closeGateFunc(gate,gateName)
  49. local x,y,z = getElementPosition(gate)
  50.         if(isGateMoving == false)then
  51.                 if(isGateOpen == true)then
  52.                         moveObject( gate, 3500, x - 8, y, z )
  53.                         isGateOpen = false
  54.                         isGateMoving = true
  55.                         setTimer(triggerEvent,3500,1,"isGateMovingEvent",getRootElement())
  56.                         outputChatBox("Closing Gate: "..gateName,source)
  57.                 end
  58.         end
  59. return
  60. end
  61. addEvent("closeGate",true)
  62. addEventHandler("closeGate",getRootElement(),closeGateFunc)
  63.  
  64. function isGateMovingFunc()
  65. isGateMoving = false
  66. gate = {}
  67. end
  68. addEvent("isGateMovingEvent",true)
  69. addEventHandler("isGateMovingEvent",getRootElement(),isGateMovingFunc)