Jump to content

[Scripting Gates] - [Timer Setting]


Portside

Recommended Posts

I just can't get my head around it at all! Is there anyway that I can use one command for this gate. For example, using the command /go to open the gate, can a timer be set on the script so it will close after so many seconds?

Here's what I have:

    gate = createObject(980, 1579, 713.599609375, 12.5, 0, 0, 90) -- objID, X, Y, Z, Rotation X, Y, Z 
          
    function gateOpen(source) 
        local x, y, z = getElementPosition(source) 
        local x1, y1, z1 = getElementPosition(gate) 
        if getDistanceBetweenPoints3D(x, y, z, x1, y1, z1) <= 10 then 
            moveObject(gate, 2000, 1579, 713.599609375, 7, 0, 0, 0) --moves the gate to the open position. time, X, Y, Z, Rotation X, Y, Z 
    outputChatBox("Montana's Gate Is Now Open!", thePlayer, 0, 255, 0) 
        end 
    end 
    addCommandHandler("go1", gateOpen)--Command /go1 to open gate 
          
    function gateClose(source) 
        local x, y, z = getElementPosition(source) 
        local x1, y1, z1 = getElementPosition(gate) 
        if getDistanceBetweenPoints3D(x, y, z, x1, y1, z1) <= 10 then 
            moveObject(gate, 2000, 1579, 713.599609375, 12.5 , 0, 0, 0 ) --returns the gate to its starting position. X, Y, Z, Rotation X, Y, Z 
    outputChatBox("Montana's Gate Is Now Closed!", thePlayer, 255, 0, 0) 
        end 
    end 
    addCommandHandler("gc1", gateClose)--Command /gc1 to close gate 

Thanks in advance!

Link to comment
  • MTA Team

This will close the gate after 5 seconds:

  
   gate = createObject(980, 1579, 713.599609375, 12.5, 0, 0, 90) -- objID, X, Y, Z, Rotation X, Y, Z 
          
    function gateOpen(source) 
        local x, y, z = getElementPosition(source) 
        local x1, y1, z1 = getElementPosition(gate) 
        if getDistanceBetweenPoints3D(x, y, z, x1, y1, z1) <= 10 then 
            moveObject(gate, 2000, 1579, 713.599609375, 7, 0, 0, 0) --moves the gate to the open position. time, X, Y, Z, Rotation X, Y, Z 
    outputChatBox("Montana's Gate Is Now Open!", thePlayer, 0, 255, 0) 
    setTimer(moveObject,5000,1,gate, 2000, 1579, 713.599609375, 12.5 , 0, 0, 0) 
        end 
    end 
    addCommandHandler("go1", gateOpen)--Command /go1 to open gate 

Link to comment
  • MTA Team
  
  
   gate = createObject(980, 1579, 713.599609375, 12.5, 0, 0, 90) -- objID, X, Y, Z, Rotation X, Y, Z 
          
    function gateOpen(source) 
source = source 
        local x, y, z = getElementPosition(source) 
        local x1, y1, z1 = getElementPosition(gate) 
        if getDistanceBetweenPoints3D(x, y, z, x1, y1, z1) <= 10 then 
            moveObject(gate, 2000, 1579, 713.599609375, 7, 0, 0, 0) --moves the gate to the open position. time, X, Y, Z, Rotation X, Y, Z 
    outputChatBox("Montana's Gate Is Now Open!", source, 0, 255, 0) 
    setTimer(function () 
outputChatBox("Montana's Gate Is Now Closing!", source, 0, 255, 0) 
moveObject(gate, 2000, 1579, 713.599609375, 12.5 , 0, 0, 0)end,5000,1) 
        end 
    end 
    addCommandHandler("go1", gateOpen)--Command /go1 to open gate 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...