• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua (TFS 0.4) Using X item on X item transforms it (TFS 0.4)

marek12

Available for sprite works
Joined
Apr 8, 2020
Messages
398
Solutions
4
Reaction score
395
Hi, I am looking for a script that will transform items.
I have custom sprites and custom items.

Example:

Using item XXXX with 100 charges, on stack of 100 items YYYY(stackable) which, transforms YYYY to ZZZZ and removing charges on XXXX.
In other words: Using protection amulet on arrows, to transform arrows to bolts and remove charges from amulet.

anyone would be so kind to do this for me?
I am learning but this is a bit too hard for me tho
 
Last edited:
Solution
This works (tested):
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local charges = getItemAttribute(item.uid, "charges")
    if itemEx.itemid == 2160 then
        if charges > itemEx.type then
            doItemSetAttribute(item.uid, "charges", charges - itemEx.type)
            doTransformItem(itemEx.uid, 2158)
        elseif charges < itemEx.type then
            doTransformItem(itemEx.uid, 2158, charges)
            doRemoveItem(item.uid, 1)
        else
            doTransformItem(itemEx.uid, 2158)
            doRemoveItem(item.uid, 1)
        end
            doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
        return false
    end
    return true...
Idk, maybe something like this:
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local charges = getItemAttribute(item.uid, "charges")
    if itemEx.itemid == 2160 and itemEx.type == 100 then
        doTransformItem(itemEx.uid, 2161)
        doItemSetAttribute(item.uid, "charges", charges -1)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
        return false
    end

    if charges == 0 then
        doPlayerRemoveItem(cid, item.uid, 1)
    end
    return true
end
 
it works but not completely.
now it only workwhen I got stack with exactly 100 items.
how to make it work to also work on for example 76 items in stack?
 
LUA:
itemEx.type
Is responsible for charges.
I don't understand what you mean, so that's the only way I can help you.
yeah. I actually done it a second ago. but it's not removing charges properly
Post automatically merged:

it's now transforming the item as I wanted. but when I use it on 50 item stack it only removes 1 charge, instead of 50
Post automatically merged:

oh. it also not removing the item when it got 0 charges ;s
 
Test this:
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local charges = getItemAttribute(item.uid, "charges")
    if itemEx.itemid == 2160 then
        if charges > itemEx.type then
            doTransformItem(itemEx.uid, 2161)
            doItemSetAttribute(item.uid, "charges", charges - itemEx.type)
        elseif charges < itemEx.type then
            doTransformItem(itemEx.uid, 2161, charges)
            doPlayerRemoveItem(cid, item.uid, 1)
        else
            doTransformItem(itemEx.uid, 2161)
            doPlayerRemoveItem(cid, item.uid, 1)
        end
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
        return false
    end
    return true
end
 
Test this:
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local charges = getItemAttribute(item.uid, "charges")
    if itemEx.itemid == 2160 then
        if charges > itemEx.type then
            doTransformItem(itemEx.uid, 2161)
            doItemSetAttribute(item.uid, "charges", charges - itemEx.type)
        elseif charges < itemEx.type then
            doTransformItem(itemEx.uid, 2161, charges)
            doPlayerRemoveItem(cid, item.uid, 1)
        else
            doTransformItem(itemEx.uid, 2161)
            doPlayerRemoveItem(cid, item.uid, 1)
        end
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
        return false
    end
    return true
end
nope. not removing charges at all
Post automatically merged:

sorry. removing charges but stays infinite when on 1 charge left
 
This works (tested):
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local charges = getItemAttribute(item.uid, "charges")
    if itemEx.itemid == 2160 then
        if charges > itemEx.type then
            doItemSetAttribute(item.uid, "charges", charges - itemEx.type)
            doTransformItem(itemEx.uid, 2158)
        elseif charges < itemEx.type then
            doTransformItem(itemEx.uid, 2158, charges)
            doRemoveItem(item.uid, 1)
        else
            doTransformItem(itemEx.uid, 2158)
            doRemoveItem(item.uid, 1)
        end
            doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
        return false
    end
    return true
end
 
Solution
This works (tested):
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local charges = getItemAttribute(item.uid, "charges")
    if itemEx.itemid == 2160 then
        if charges > itemEx.type then
            doItemSetAttribute(item.uid, "charges", charges - itemEx.type)
            doTransformItem(itemEx.uid, 2158)
        elseif charges < itemEx.type then
            doTransformItem(itemEx.uid, 2158, charges)
            doRemoveItem(item.uid, 1)
        else
            doTransformItem(itemEx.uid, 2158)
            doRemoveItem(item.uid, 1)
        end
            doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
        return false
    end
    return true
end
there is a small issue, but I think I am able to fix it myself.
anyways, thank you very much! Totally helped me. Appreciate that :)
 
Idk, maybe something like this:
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local charges = getItemAttribute(item.uid, "charges")
    if itemEx.itemid == 2160 and itemEx.type == 100 then
        doTransformItem(itemEx.uid, 2161)
        doItemSetAttribute(item.uid, "charges", charges -1)
        doSendMagicEffect(toPosition, CONST_ME_POFF)
    else
        doPlayerSendCancel(cid,"Sorry, not possible.")
        return false
    end

    if charges == 0 then
        doPlayerRemoveItem(cid, item.uid, 1)
    end
    return true
end
Would you have an equal but for tfs 1.3, and that with the same item it can transform others, for example with a demonic essence it can transform from a demon armor to an mpa and also transform a magic sword into a falcon sword?
 
Would you have an equal but for tfs 1.3, and that with the same item it can transform others, for example with a demonic essence it can transform from a demon armor to an mpa and also transform a magic sword into a falcon sword?
yeah there are a plenty of scripts that you can use as example:
 
Back
Top