Jump to content

How add delay to a command


SkymHaru_

Recommended Posts

Help, I have tried to place a delay for the commands, but it does not help me at all, could you help me? :(

I don't speak English, that's why the code is in another language.

Server:

function ablanca(source)
    if isElementWithinMarker(source, cablanca) then
        if getElementData(source, "slicencia") == true then
            if getPlayerMoney(source) >= 2000 then
                takePlayerMoney(source, 2000)
                giveWeapon(source, 4, 1, true)
                    outputChatBox("Has comprado un #EE850Ecuchillo #FFFFFFpor $2000.", source, 255, 255, 255, true)
                else
                    outputChatBox("No tienes dinero suficiente", source, 255, 255, 255, true)
                
            end
        end
    end
end
addCommandHandler("ablanca", ablanca)

 

Edited by SkymHaru_
Link to comment

Add the player to a table index and remove it inside setTimer, then you will have check if the player element is in the table at the beginning of your function.

Another way is to store getTickCount() in player's index, then calculate the elapsed time with getTickCount() - stored tickCount of player's index.

Link to comment
local Time = 1 --Minutes

local CoolDown = {}

function ablanca(source)
	if isElementWithinMarker(source, cablanca) then
        if getElementData(source, "slicencia") == true then
            if getPlayerMoney(source) >= 2000 then
                takePlayerMoney(source, 2000)
                giveWeapon(source, 4, 1, true)
                outputChatBox("Has comprado un #EE850Ecuchillo #FFFFFFpor $2000.", source, 255, 255, 255, true)
				CoolDown[source] = true
				setTimer( function()
					CoolDown[source] = nil
				end, Time*1000, 1)
            else
                outputChatBox("No tienes dinero suficiente", source, 255, 255, 255, true)
            end
        end
    end
end
addCommandHandler("ablanca", ablanca)

 

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