Lua A little item system.

Udun

Well-Known Member
Joined
Jan 5, 2012
Messages
181
Solutions
1
Reaction score
52
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

royalpala

Active Member
Joined
Dec 31, 2019
Messages
76
Solutions
1
Reaction score
44
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:

oen432

Legendary OT User
Joined
Oct 3, 2014
Messages
1,326
Solutions
43
Reaction score
1,429
Location
Poland
GitHub
Oen44
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
Top