Jump to content

help


marty000123

Recommended Posts

Hello

I made a command called /paytoll. The barrier goes up, but someone who quickly does it after the first person bugs the barrier. How do I disable the command after the first usage?

Like, if player A does /paytoll, and 2 seconds later a guy comes and does /paytoll as well, the resource will return false and an outputChatbox("You have to wait 10 seconds!")

Thanks in advance

Link to comment

You could also create a local variable for example 'cooldown' and set it to false. When someone uses the command set cooldown to true then set a timer to reset the cooldown to false after X seconds as well as close the barrier.

local cooldown = false

function tollHandler()
  if cooldown then return end
  openBarrier() -- this is the function that will open the barrier
  cooldown = true
  setTimer(
    function()
      closeBarrier() -- this is the function that will close the barrier
      cooldown = false
    end, 5000, 1) -- 5 seconds cooldown
end
addCommandHandler("paytoll", tollHandtler)

function openBarrier()
  -- code here
end

function closeBarrier()
  -- code here
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...