Jump to content

Automatic Gates with more than one person


XxCozzaxX

Recommended Posts

Okay, so here's my code:

privategatesphere = createColSphere ( 1394, -2438, 14, 12 ) 
privateGate = createObject(16773, 1393.1313476563, -2438.46875, 16.553903579712, 16, 0, 270) 
  
function openprivateGate() 
    if (getPlayerFromName("crwblyth" or "XxHEWESxX")) then 
            moveObject(privateGate, 7000, 1390.3840332031, -2438.361328125, 20.691507339478) 
            end 
end 
  
function closeprivateGate() 
    if (getPlayerFromName("crwblyth" or "XxHEWESxX")) then 
            moveObject(privateGate, 7000, 1393.1313476563, -2438.46875, 16.553903579712) 
            end 
end 
addEventHandler ( "onColShapeHit", privategatesphere, openprivateGate ) 
addEventHandler ( "onColShapeLeave", privategatesphere, closeprivateGate ) 

This opens a gate when the colshape is hit and closes it when it is left

But what happens when one person enters as the other leaves?

There is a clash here, any ideas how I could code it so it would work properly?

Regards,

Cozza

Link to comment

Try:

privategatesphere = createColSphere ( 1394, -2438, 14, 12 ) 
privateGate = createObject(16773, 1393.1313476563, -2438.46875, 16.553903579712, 16, 0, 270) 
local isGateMoving = false 
  
function openprivateGate() 
    if (getPlayerFromName("crwblyth" or "XxHEWESxX")) then 
            if isGateMoving then return end 
            moveObject(privateGate, 7000, 1390.3840332031, -2438.361328125, 20.691507339478) 
            isGateMoving = true 
            setTimer(function() isGateMoving = false end,7000,1) 
            end 
end 
  
function closeprivateGate() 
    if (getPlayerFromName("crwblyth" or "XxHEWESxX")) then 
            if isGateMoving then return end 
            moveObject(privateGate, 7000, 1393.1313476563, -2438.46875, 16.553903579712) 
            isGateMoving = true 
            setTimer(function() isGateMoving = false end,7000,1) 
            end 
end 
addEventHandler ( "onColShapeHit", privategatesphere, openprivateGate ) 
addEventHandler ( "onColShapeLeave", privategatesphere, closeprivateGate ) 

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