• 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!

Lua Delete item after a certain time

noshirtstan

New Member
Joined
Aug 2, 2020
Messages
68
Reaction score
2
So hey guys, back again. I would like to have my script start counting down when you use the item, then after 5 min, remove the item. I thought I had the syntax correct, but I can't seem to get it. It either deletes it right away or deletes it on the second click.

Here is what I have so far

Lua:
local mineGone = os.time()

function onUse(player, item, fromPosition, itemEx, toPosition)
    if item.itemid == 26405 and isInArray({50605, 50602, 50603, 50604}, item.actionid) then
        if mineGone == os.time() then
        elseif mineGone < os.time() then
            item:remove(26405)
        end
        if player:getCondition(player, CONDITION_COOLDOWN, 160) then
            player:sendCancelMessage("You are already gathering!")
            return true
        end
        
        if not player:isGatheringJob(item.actionid) then
            player:sendCancelMessage("You must learn "..craftingGatheringJobConfig[item.actionid].skillName.." before using this.")
            return true
        end
        
        if player:isGatheringJob(item.actionid) then
        
            if player:getStorageValue(205000) > os.time() then
                player:sendCancelMessage("You must wait before mining this again!")
                return true
            
            end
            if player:getItemCount(2553) >= 1 then -- check for pick
            mathCheck = math.floor(math.random() * 100) + 1
            if mathCheck >= 50 then
                player:addItem(26410, math.floor(math.random() * 3) + 1)
            elseif mathCheck <= 49 then
                player:addItem(26409, math.floor(math.random() * 3)+ 1)
            end
            else
                player:sendCancelMessage("You need a pick to use this!")
                return true
                end
            end
            player:setStorageValue(205000, os.time() + 5)
            mineGone = os.time() + 300

Any thoughts?
Post automatically merged:

So I thought of a better solution instead lol.

Thank you =)
Post automatically merged:

Admin please delete this post.

Thank you
 
Last edited:
Yeah that makes sense. I decided to set the item to transform on a random basis. I then set the item attribute to decay back to the original form after 5 min.

Main Function:

Lua:
function onUse(player, item, fromPosition, itemEx, toPosition)
    if item.itemid == 26405 and isInArray({50605, 50602, 50603, 50604}, item.actionid) then
        if player:getCondition(player, CONDITION_COOLDOWN, 160) then
            player:sendCancelMessage("You are already gathering!")
            return true
        end
        
        if not player:isGatheringJob(item.actionid) then
            player:sendCancelMessage("You must learn "..craftingGatheringJobConfig[item.actionid].skillName.." before using this.")
            return true
        end
        
        if player:isGatheringJob(item.actionid) then
        
            if player:getStorageValue(205000) > os.time() then
                player:sendCancelMessage("You must wait before mining this again!")
                return true
            
            end
            if player:getItemCount(2553) >= 1 then -- check for pick
            mathCheck = math.floor(math.random() * 100) + 1
            if mathCheck >= 50 then
                player:addItem(26410, math.floor(math.random() * 3) + 1)
            elseif mathCheck <= 49 then
                player:addItem(26409, math.floor(math.random() * 3)+ 1)
            end
            else
                player:sendCancelMessage("You need a pick to use this!")
                return true
                end
            end
            player:setStorageValue(205000, os.time() + 5)
            mathCheck2 = math.floor(math.random() * 100) + 1
            if mathCheck2 >= 35 then
                player:sendTextMessage("You successfully mined the ore!")
                return true
            elseif mathCheck2 <= 34 then
                item:transform(26404)
                player:sendTextMessage("You've exhausted this vein")
            end

Item Adjustment:

Code:
<item id="26404" article="a" name="mined copper vein">
        <attribute key="weight" value="263" />
        <attribute key="decayTo" value="23749" />
        <attribute key="duration" value="300" />
    </item>
Post automatically merged:

@Xikini So i may have spoken too soon.

The item doesn't transform back even with the decay on it lol. It stays at the transformed id.
 
Last edited:
item:decay(decayId)
The item doesn't transform back even with the decay on it lol. It stays at the transformed id.
Lua:
elseif mathCheck2 <= 34 then
    item:transform(26404)
    item:decay() -- allows item to start decaying
 
Solution
Back
Top