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

Solved On use shovel add item

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,735
Solutions
127
Reaction score
2,203
I have this code, im not good at lua...
Every lua master should get the concept.

So can someone help me?

Item ids: 2554 = shovel
Action id: 22543 = tile action id
TFS 1.2

Code:
local config = {
    mud = {22543}
}

    function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if item.itemid == 2554 and isInArray(config.mud, target.actionid) and (math.random(1,40) <= 1) then
            player:addItem(20138, 1)
           doCreatureSay(cid, "You dug up a Leech!", MESSAGE_EVENT_ADVANCE)
        
        return true
     
    elseif(isInArray(config.mud, target.actionid)) and (math.random(7,10) <= 7) then
    player:addItem(2817, 1)
    doCreatureSay(cid, "Again dead snake?! Again? I guess I'll have to dig more!", MESSAGE_EVENT_ADVANCE)
 
    return true
 
    elseif(isInArray(config.mud, target.actionid)) and (math.random(2,10) <= 2)  then
    player:addItem(2145, 1)
    doCreatureSay(cid, "You Found a Small Diamond!", MESSAGE_EVENT_ADVANCE)
 
            return true
    end
            return true
    end
 
Code:
    local config = {
        mud = {22543}
    }
    local this = {
        {add = 20138, amount = 1, minmax = {1, 40}, chance = 1, msg = "You dug up a Leech!"},
        {add = 2817, amount = 1, minmax = {7, 10}, chance = 7, msg = "Again dead snake?! Again? I guess I'll have to dig more!"},
        {add = 2145, amount = 1, minmax = {2, 10}, chance = 2, msg = "You Found a Small Diamond!"}
    }
    function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if item.itemid == 2554 and isInArray(config.mud, target.actionid) then
            for i in ipairs(this) do
                if math.random( unpack( this[i].minmax ) ) <= this[i].chance then
                    player:addItem(this[i].add, this[i].amount)
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, this[i].msg)
                end
            end
        end
        return true
    end
 
Last edited:
Dont work ;x When i use shovel on the spot 22543 then nothing happens.

Then spot is mud floor with action id 22543. Im using shove on it
 
Last edited:
I never understood what this is for:
Code:
for i in ipairs

What is it?
for i in ipairs, the i holds the index of the current iteration of the table, ipairs traverses the table from the top down in the exact sequence it is defined, it will only return indexes which are within the bounds of its size.
 
Code:
    local config = {
        mud = {22543}
    }
    local this = {
        {add = 20138, amount = 1, minmax = {1, 40}, chance = 1, msg = "You dug up a Leech!"},
        {add = 2817, amount = 1, minmax = {7, 10}, chance = 7, msg = "Again dead snake?! Again? I guess I'll have to dig more!"},
        {add = 2145, amount = 1, minmax = {2, 10}, chance = 2, msg = "You Found a Small Diamond!"}
    }
    function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if item.itemid == 2554 and isInArray(config.mud, target.actionid) then
            for i in ipairs(this) do
                if math.random( unpack( this[i].minmax ) ) <= this[i].chance then
                    player:addItem(this[i].add, this[i].amount)
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, this[i].msg)
                end
            end
        end
        return true
    end

Codex i treid to edit your script to use on item and used like 20 arguments for local this = {}

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
            for i in ipairs(this) do
                if math.random( unpack( this[i].minmax ) ) <= this[i].chance then
                    player:addItem(this[i].add, this[i].amount)
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, this[i].msg)
                    item:remove(1)
            end
        end
        return true
    end

and the script is so slow... When i click he dont execute or after 10 secs...
How to fix that?
 

Similar threads

Back
Top