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

TFS 1.X+ Change Gold

Pedrook

Advanced OT User
Joined
May 24, 2009
Messages
442
Solutions
3
Reaction score
183
Location
Brazil
Hello, I would like help to make some modifications to the change gold, every time you exchange a gold, regardless of the backpack it is it goes to the main backpack, I would like to change in the blue backpack 100 gold coin and it would transform 1 platinum coin into blue backpack, were not for the main backpack.


is this in the conversion or source script itself?


Lua:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[target.itemid]
    
    if not coin then
        return false
    end
    
    local charges = item:getCharges()
        if coin.changeTo and target.type == 100 then
        target:remove()
        player:addItem(coin.changeTo, 1)
        item:transform(item:getId(), charges -1)
    elseif coin.changeBack then
        target:transform(target.itemid, target.type - 1)
        player:addItem(coin.changeBack, 100)
        item:transform(item:getId(), charges -1)
        else
        return false
    end
    if charges == 0 then
    item:remove()
    end
    return true
end
 
You need to get current parent (container that is holding the item) of the gold coin you are using.

Lua:
local parent = item:getParent()
if parent and parent:getType():isContainer() then
    parent:addItem() -- add your changed gold to the parent container
end
 
You need to get current parent (container that is holding the item) of the gold coin you are using.

Lua:
local parent = item:getParent()
if parent and parent:getType():isContainer() then
    parent:addItem() -- add your changed gold to the parent container
end
I do not know if I put it wrong, but it did not.



Lua:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local coin = config[target.itemid]
    
    local parent = item:getParent()
        if parent and parent:getType():isContainer() then
        parent:addItem() -- add your changed gold to the parent container
        end
    
    if not coin then
        return false
    end
    
    local charges = item:getCharges()
        if coin.changeTo and target.type == 100 then
        target:remove()
        player:addItem(coin.changeTo, 1)
        item:transform(item:getId(), charges -1)
    elseif coin.changeBack then
        target:transform(target.itemid, target.type - 1)
        player:addItem(coin.changeBack, 100)
        item:transform(item:getId(), charges -1)
        else
        return false
    end
    if charges == 0 then
    item:remove()
    end
    return true
end
 
Back
Top