• 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 A little item system.

Udun

Well-Known Member
Joined
Jan 5, 2012
Messages
192
Solutions
1
Reaction score
67
Hello guys, I wanted to know if someone could help me with this idea to crearte-craft items for TFS 1.2
I think probably is a very easy script to do but I'm a real noob in terms of programming.

The idea is the next:

I "use-click" one item id XXXX above another item id ZZZZ and then the two items are deleted and a new one with id YYYYY is created

the idea is that you can convine 2 different items to create a new one, and be able to use them without any order, so if a use first the id XXXX and megre to the ZZZZ or if I use the ZZZZ first on the XXXX the result should be the same.

it is possible?

thanks in advance
 
Solution
Lua:
local config = {
    {a = 1111, b = 2222, result = 3333},
    {a = 4444, b = 5555, result = 6666}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target or not target:isItem() then
        return false
    end
    for i = 1, #config do
        local craft = config[i]
        if craft.a == item:getId() and craft.b == target:getId() or craft.a == target:getId() and craft.b == item:getId() then
            item:remove(1)
            target:remove(1)
            player:addItem(craft.result)
            break
        end
    end
    return true
end
this is for TFS 0.4, you may use something similar to this


Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(item.itemid == XXXX and itemEx.itemid == YYYY) then
        doTransformItem(itemEx.uid, ZZZZ)
        doRemoveItem(item.uid, 1)

edit: the end result of this fucntion is to combine items XXXX and YYYY to create item ZZZZ
 
Last edited:
Lua:
local config = {
    {a = 1111, b = 2222, result = 3333},
    {a = 4444, b = 5555, result = 6666}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target or not target:isItem() then
        return false
    end
    for i = 1, #config do
        local craft = config[i]
        if craft.a == item:getId() and craft.b == target:getId() or craft.a == target:getId() and craft.b == item:getId() then
            item:remove(1)
            target:remove(1)
            player:addItem(craft.result)
            break
        end
    end
    return true
end
 
Solution
Back
Top