Jump to content

Problems with making gates.


Portside

Recommended Posts

Hi! I'm very new to the MTA scripting, but I can make different small things, edit and stuff like that. But I can make gates too! Problem is, I can do the command anywhere on the map and the gate will still open. Can someone make a gate template for me on how to open the gate within a certain distance of the object? Thanks in advance! :D

Link to comment

gate = createObject(980, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0) -- objID, X, Y, Z, Rotation X, Y, Z 
      
    function gateOpen() 
    moveObject( gate, 2000, 2188.8193359375, -2272.720703125, 28.495878219604, 0, 0, 130 ) --moves the gate to the open position. time, X, Y, Z, Rotation X, Y, Z 
    end 
    addCommandHandler("go1", gateOpen)--Command /go1 to open gate 
      
    function gateClose() 
    moveObject( gate, 2000, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0 ) --returns the gate to it's starting position. X, Y, Z, Rotation X, Y, Z 
    end 
    addCommandHandler("gc1", gateClose)--Command /gc1 to close gate 

That's what I've made. It's for a friend, but he asked me to have it within a certain radius.

Link to comment
  • Administrators
gate = createObject(980, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0) -- objID, X, Y, Z, Rotation X, Y, Z 
      
    function gateOpen() 
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, 2188.8193359375, -2272.720703125, 28.495878219604, 0, 0, 130 ) --moves the gate to the open position. time, X, Y, Z, Rotation X, Y, Z 
    end 
end 
    addCommandHandler("go1", gateOpen)--Command /go1 to open gate 
      
    function gateClose() 
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, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0 ) --returns the gate to it's starting position. X, Y, Z, Rotation X, Y, Z 
    end 
end 
    addCommandHandler("gc1", gateClose)--Command /gc1 to close gate 

Or you can use colShapes.

Link to comment

Server Side:

gate = createObject(980, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0) -- 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, 2188.8193359375, -2272.720703125, 28.495878219604, 0, 0, 130) --moves the gate to the open position. time, X, Y, Z, Rotation X, Y, Z 
    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, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0 ) --returns the gate to it's starting position. X, Y, Z, Rotation X, Y, Z 
    end 
end 
addCommandHandler("gc1", gateClose)--Command /gc1 to close gate 

Link to comment
  • Administrators
gate = createObject(980, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0) -- objID, X, Y, Z, Rotation X, Y, Z 
      
function gateOpen(me,cmd) 
    local x, y, z = getElementPosition(me) 
    local x1, y1, z1 = getElementPosition(gate) 
    if getDistanceBetweenPoints3D(x, y, z, x1, y1, z1) <= 10 then 
        moveObject(gate, 2000, 2188.8193359375, -2272.720703125, 28.495878219604, 0, 0, 130) --moves the gate to the open position. time, X, Y, Z, Rotation X, Y, Z 
    end 
end 
addCommandHandler("go1", gateOpen)--Command /go1 to open gate 
      
function gateClose(me,cmd) 
    local x, y, z = getElementPosition(me) 
    local x1, y1, z1 = getElementPosition(gate) 
    if getDistanceBetweenPoints3D(x, y, z, x1, y1, z1) <= 10 then 
        moveObject(gate, 2000, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0 ) --returns the gate to it's starting position. X, Y, Z, Rotation X, Y, Z 
    end 
end 
addCommandHandler("gc1", gateClose)--Command /gc1 to close gate 

Link to comment

What CiBeR post is just like what i posted already.

Server Side:
gate = createObject(980, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0) -- 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, 2188.8193359375, -2272.720703125, 28.495878219604, 0, 0, 130) --moves the gate to the open position. time, X, Y, Z, Rotation X, Y, Z 
    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, 2187.626953125, -2273.4443359375, 13.546875, 0, 0, 0 ) --returns the gate to it's starting position. X, Y, Z, Rotation X, Y, Z 
    end 
end 
addCommandHandler("gc1", gateClose)--Command /gc1 to close gate 

The code should work fine, however you will not be able to close the gate after you open it because it will go up and the distance will be more than 10 and therefore to close it you have to fly to it. :mrgreen:

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...