Your lucky I got some exams tomorrow, this presents a perfect opportunity to procrastinate!
Try this ... you add the objectID, ZYX, time to open, move to XYZ in the gates table, I've already added your own two gates in it. So basically to open the first gate you do /open 1, and for the second /open 2, etc.
Same with /close.
I'd recommend adding a colcircle around the gate tho since it's a bit unrealistic to open a gate in SF while riding in LS , or just check the distance between GetDistanceBetweenPoints3D using the gate position as one point and the players position as the other.
Oh, and I haven't tested it, but I suppose I'd work
-- First thing is to create a table to hold all the coordinates for the gates.
-- In the gates table there tables that contain the info for one gate
-- { objectID, CoordX, CoordY, CoordZ, Time to move gate in ms, moveToCoordZ, moveToCoordY, moveToCoordZ )
local gates = {
{ 969, 209.0489654541, 1875.4265136719, 12.140625, 3000, 200.65399169922, 1875.3364257813, 12.140625 },
{ 3109, 226.6572265625, 1858.30859375, 14.64695930481, 3000, 226.6572265625, 1858.30859375, 11.64695930481 }
}
local gate = { } -- this is where we store the gate elements.
addEventHandler ( "onResourceStart", getResourceRootElement(),
function ( )
for i, tbl in ipairs ( gates ) do -- when the resource start we loop over the gates table
gate[i] = createObject ( tbl[1], tbl[2], tbl[3], tbl[4] ) -- we create objects, the numbers 1-4 are the location of the objectID and the XYZ coords. ( see above )
end
end
)
addCommandHandler ( "open",
function ( source, command, gate )
if tonumber ( gate ) then -- if its not a number we cant use it.
local i = tonumber ( gate )
if gate[i] then -- if that gate exists we open it up
moveObject ( gate[i], gates[i][5], gates[i][6], gates[i][7], gates[i][8] ) -- we open it to the XYZ coords in x amount of seconds, 5 - 8 in the table.
else
outputChatBox ( "Gate not found", source )
end
else
outputChatBox ( "Syntax is /" .. command .. " , with gate being a number.", source )
end
end
)
addCommandHandler ( "close",
function ( source, command, gate )
if tonumber ( gate ) then
local i = tonumber ( gate )
if gate[i] then
moveObject ( gate[i], gates[i][5], gates[i][2], gates[i][3], gates[i][4] ) -- same as above, but since we're closing it (going back to begin position) we use the 2-4 XYZ.
else
outputChatBox ( "Gate not found", source )
end
else
outputChatBox ( "Syntax is /" .. command .. " , with gate being a number.", source )
end
end
)