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

Use item on chest

mattehj

Member
Joined
Oct 8, 2009
Messages
83
Reaction score
16
I'm trying to make like rl tibia, so you can use crystal sword on chest to get goolem wrench.
as it working now, It removes the chest on fail/succeed.
I want the chest to stay. so only the crystal sword (7449) only get removed

Lua:
------------
-- Alternative to no-magic style.
-- Description here
----

---- string of mending id "7449"-----
local ITEMS = {
    [21385] = {
         {"golem wrench", 10.10} -----
    }
}

local stringOfMending = Action()

---- onUse [opt]
-- @param cid Player ID
-- @param item Item ID
-- @param fromPosition Current Position
-- @param[opt] itemEx Item change
-- @param[opt] toPosition Nem position
function stringOfMending.onUse(cid, item, fromPosition, itemEx, toPosition)
    local cadena = ITEMS[itemEx.itemid]
    if cadena == nil then
        return false
    end

    local iEx = Item(itemEx.uid)
    local random, chance = math.random() * 100, 0

    for i = 1, #cadena do
        chance = chance + cadena[i][2]
        if random <= chance then
            iEx:transform(cadena[i][1])
            iEx:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
            Item(item.uid):remove(1)
            return true
        end
    end

    iEx:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    Item(item.uid):remove(1)
    iEx:remove()
    doCreatureSay(cid, "10% chance, the item was broken.", TALKTYPE_ORANGE_1)
    return true
end

stringOfMending:id(7449)
stringOfMending:register()
Post automatically merged:

@Sarah Wesker You are like number 1 in this, You got a clue?
 
Last edited:
Solution
It worked until it was succed, Then the chest transformed to a golden wrench, :/
Lua:
-- Alternative to no-magic style.
-- Description here
----

---- string of mending id "7449"-----
local ITEMS = {
    [21385] = {
         {"golem wrench", 10.10} -----
    }
}

local stringOfMending = Action()

function stringOfMending.onUse(player, item, fromPos, target, toPos, isHotkey)
    local found = ITEMS[target:getId()]
    if not found then
        return true
    end

    local random, chance = math.random(0, 100), 0
    for _, info in pairs(found) do
        chance = chance + info[2]
        if random <= chance then
            player:addItem(info[1],1)
            target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)...
Try this:
Lua:
------------
-- Alternative to no-magic style.
-- Description here
----

---- string of mending id "7449"-----
local ITEMS = {
    [21385] = {
         {"golem wrench", 10.10} -----
    }
}

local stringOfMending = Action()

function stringOfMending.onUse(player, item, fromPos, target, toPos, isHotkey)
    local found = ITEMS[target:getId()]
    if not found then
        return true
    end

    local random, chance = math.random(0, 100), 0
    for _, info in pairs(found) do
        chance = chance + info[2]
        if random <= chance then
            target:transform(info[1])
            target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
            item:remove(1)
            return true
        end
    end

    item:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    item:remove(1)
    player:say("10% chance, the item was broken.", TALKTYPE_ORANGE_1)
    return true
end

stringOfMending:id(7449)
stringOfMending:register()
 
Try this:
Lua:
------------
-- Alternative to no-magic style.
-- Description here
----

---- string of mending id "7449"-----
local ITEMS = {
    [21385] = {
         {"golem wrench", 10.10} -----
    }
}

local stringOfMending = Action()

function stringOfMending.onUse(player, item, fromPos, target, toPos, isHotkey)
    local found = ITEMS[target:getId()]
    if not found then
        return true
    end

    local random, chance = math.random(0, 100), 0
    for _, info in pairs(found) do
        chance = chance + info[2]
        if random <= chance then
            target:transform(info[1])
            target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
            item:remove(1)
            return true
        end
    end

    item:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    item:remove(1)
    player:say("10% chance, the item was broken.", TALKTYPE_ORANGE_1)
    return true
end

stringOfMending:id(7449)
stringOfMending:register()
It worked until it was succed, Then the chest transformed to a golden wrench, :/
 
It worked until it was succed, Then the chest transformed to a golden wrench, :/
Lua:
-- Alternative to no-magic style.
-- Description here
----

---- string of mending id "7449"-----
local ITEMS = {
    [21385] = {
         {"golem wrench", 10.10} -----
    }
}

local stringOfMending = Action()

function stringOfMending.onUse(player, item, fromPos, target, toPos, isHotkey)
    local found = ITEMS[target:getId()]
    if not found then
        return true
    end

    local random, chance = math.random(0, 100), 0
    for _, info in pairs(found) do
        chance = chance + info[2]
        if random <= chance then
            player:addItem(info[1],1)
            target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
            item:remove(1)
            return true
        end
    end

    item:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
    item:remove(1)
    player:say("10% chance, the item was broken.", TALKTYPE_ORANGE_1)
    return true
end

stringOfMending:id(7449)
stringOfMending:register()
 
Solution
Back
Top