Portside Posted January 17, 2014 Posted January 17, 2014 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!
Chopper Posted January 17, 2014 Posted January 17, 2014 (edited) Use: GetDistanceBetweenPoints3D Edited April 20, 2014 by Guest
Portside Posted January 17, 2014 Author Posted January 17, 2014 Eh, like I said. I'm pretty new with this scripting thing. Mind telling me exactly and where this is put? And how it's used. Thanks!
Portside Posted January 17, 2014 Author Posted January 17, 2014 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.
MTA Team 0xCiBeR Posted January 17, 2014 MTA Team Posted January 17, 2014 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.
Portside Posted January 18, 2014 Author Posted January 18, 2014 Thanks a lot, really appreciated your help!
MTA Team 0xCiBeR Posted January 18, 2014 MTA Team Posted January 18, 2014 I just put it in like that, right? Yes. Tell me if it works..
TAPL Posted January 18, 2014 Posted January 18, 2014 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
Portside Posted January 19, 2014 Author Posted January 19, 2014 Nah, it's still moving no matter what distance I am from it.
TAPL Posted January 19, 2014 Posted January 19, 2014 Nah, it's still moving no matter what distance I am from it. Impossible, try lower the distance.
Portside Posted January 19, 2014 Author Posted January 19, 2014 Still nada... Just forget about it, I think it just doesn't like me lol
MTA Team 0xCiBeR Posted January 19, 2014 MTA Team Posted January 19, 2014 It should work. As I said in the first post, you can also try with colShapes.
TAPL Posted January 21, 2014 Posted January 21, 2014 It should work. As I said in the first post, you can also try with colShapes. How it will work if you did not define 'source'?
MTA Team 0xCiBeR Posted January 21, 2014 MTA Team Posted January 21, 2014 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
Portside Posted January 21, 2014 Author Posted January 21, 2014 Ciber, do I just put that in as it is?
TAPL Posted January 25, 2014 Posted January 25, 2014 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.
Portside Posted January 25, 2014 Author Posted January 25, 2014 It's working properly now, thanks haha.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now