marty000123 Posted February 18, 2017 Share Posted February 18, 2017 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
pa3ck Posted February 18, 2017 Share Posted February 18, 2017 local lastUsed = getTickCount() addCommandHandler("toll", function(p, cmd ) if ( lastUsed + 10000 > getTickCount() ) then outputChatBox("Cannot use this command", p ) else -- code lastUsed = getTickCount() end end) Link to comment
Angelo. Posted February 18, 2017 Share Posted February 18, 2017 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
marty000123 Posted February 18, 2017 Author Share Posted February 18, 2017 Thanks guys! Link to comment
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