Jump to content

/close or /open command


MelloD

Recommended Posts

hello

I want something with addeventhandlercommand or addeventcommand

example:

I state in area-51 (Admin Base by me)

I want so that a gate opens

and I want a command that I am so busy at t, then / and then the name of the command and if I do it then the gate opens

Who will help me

sorry for my bad english i am from Netherlands

Link to comment

I've got a script and it works but if I want to do the same but I'll put a 1 behind so I got this in the first: openMyGate and this in the 2: 1 openMyGate1 then he opens not with the first command but he opened it with two commands are really

Help me please

function createTheGate ()
  myGate = createObject ( 969, 209.0489654541, 1875.4265136719, 12.140625 )
end
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), createTheGate )
 
function openMyGate ( )
moveObject ( myGate, 3000, 200.65399169922, 1875.3364257813, 12.140625 )
end
addCommandHandler("open",openMyGate)
 
function movingMyGateBack ()
moveObject ( myGate, 3000, 209.0489654541, 1875.4265136719 + 0, 12.140625 )
end
addCommandHandler("close",movingMyGateBack)
 
function createTheGate1 ()
  myGate = createObject ( 3109, 226.6572265625, 1858.30859375, 14.64695930481 )
end
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource () ), createTheGate1 )
 
 
function openMyGate1 ()
moveObject ( myGate, 3000, 226.6572265625, 1858.30859375, 11.64695930481 )
end
addCommandHandler("deur",openMyGate1)
 
function movingMyGateBack1 ()
moveObject ( myGate, 3000, 226.6572265625, 1858.30859375, 14.64695930481 )
end
addCommandHandler("deur1",movingMyGateBack1)

what am I doing wrong

Link to comment

Your lucky I got some exams tomorrow, this presents a perfect opportunity to procrastinate! :D

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 :P, 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
)

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