• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Cooldown on a lever

liqeen

Active Member
Joined
Nov 26, 2014
Messages
150
Solutions
1
Reaction score
30
Location
Poland
Hello, how could I add a cooldown for this script, for example 5secs.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.uid == 1263 then
        local chance = math.random(0,3)
         if chance < 1 then
        Game.createMonster('Demon', Position(1810, 2404, 13))
       elseif chance < 2 then
                Game.createMonster('Fire Devil', Position(1809, 2402, 13))
       elseif chance < 3 then
                Game.createMonster('Orshabaal', Position(1809, 2402, 13))
            end
            end
return true
end
I was trying with addEvent but can't do that.
 
Solution
well thats weird, try this

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.uid == 1263 then
        if getGlobalStorageValue(1234) > os.time() then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Wait a few.')
            return true
        end
        local chance = math.random(0, 3)
        if chance < 1 then
            Game.createMonster('Demon', Position(1810, 2404, 13))
        elseif chance < 2 then
            Game.createMonster('Fire Devil', Position(1809, 2402, 13))
        elseif chance < 3 then
            Game.createMonster('Orshabaal', Position(1809, 2402, 13))
        end
        setGlobalStorageValue(1234, os.time() + 5)
    end
    return true
end
try this

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local cTime = os.time()
    if item.uid == 1263 and Game.getStorageValue(1234) > cTime then
        local chance = math.random(0, 3)
        if chance < 1 then
            Game.createMonster('Demon', Position(1810, 2404, 13))
        elseif chance < 2 then
            Game.createMonster('Fire Devil', Position(1809, 2402, 13))
        elseif chance < 3 then
            Game.createMonster('Orshabaal', Position(1809, 2402, 13))
        end
        Game.setStorageValue(1234, os.time() + 300)
    end
    return true
end
 
try this

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local cTime = os.time()
    if item.uid == 1263 and Game.getStorageValue(1234) > cTime then
        local chance = math.random(0, 3)
        if chance < 1 then
            Game.createMonster('Demon', Position(1810, 2404, 13))
        elseif chance < 2 then
            Game.createMonster('Fire Devil', Position(1809, 2402, 13))
        elseif chance < 3 then
            Game.createMonster('Orshabaal', Position(1809, 2402, 13))
        end
        Game.setStorageValue(1234, os.time() + 300)
    end
    return true
end
Nothing happens after clicking the spot, also no errors in console.
 
well thats weird, try this

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.uid == 1263 then
        if getGlobalStorageValue(1234) > os.time() then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Wait a few.')
            return true
        end
        local chance = math.random(0, 3)
        if chance < 1 then
            Game.createMonster('Demon', Position(1810, 2404, 13))
        elseif chance < 2 then
            Game.createMonster('Fire Devil', Position(1809, 2402, 13))
        elseif chance < 3 then
            Game.createMonster('Orshabaal', Position(1809, 2402, 13))
        end
        setGlobalStorageValue(1234, os.time() + 5)
    end
    return true
end
 
Solution
Nothing happens after clicking the spot, also no errors in console.
It doesn't make sense for you to do a math.random from 0 - 3 if you never actually check for 3. Also it might be necessary to force create the monster on the tile, it's hard to say for sure without seeing where you're trying to spawn it.

Try this out:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local cTime = os.time()
    if item.uid == 1263 and Game.getStorageValue(1234) > cTime then
        local chance = math.random(3)
        if chance == 1 then
            Game.createMonster('Demon', Position(1810, 2404, 13), false, true)
        elseif chance == 2 then
            Game.createMonster('Fire Devil', Position(1809, 2402, 13), false, true)
        elseif chance == 3 then
            Game.createMonster('Orshabaal', Position(1809, 2402, 13), false, true)
        end
        Game.setStorageValue(1234, os.time() + 300)
    end
    return true
end
 
Back
Top