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

[Money Exchange] Crystal coin to bar of gold.

Ovnyx

Member
Joined
Jul 25, 2017
Messages
163
Solutions
2
Reaction score
7
Hi guys im trying to creat a script to exchange 100 crystal coins for 1 bar of gold, im using tfs 1.0, and i im working on data/actions/scripts/others/changelog.lua

and i got this:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
    if item.itemid == ITEM_GOLD_COIN and item.type == ITEMCOUNT_MAX then
        Item(item.uid):remove()
        Player(cid):addItem(ITEM_PLATINUM_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type == ITEMCOUNT_MAX then
        Item(item.uid):remove()
        Player(cid):addItem(ITEM_CRYSTAL_COIN, 1)
    elseif item.itemid == ITEM_PLATINUM_COIN and item.type < ITEMCOUNT_MAX then
        Item(item.uid):transform(item.itemid, item.type - 1)
        Player(cid):addItem(ITEM_GOLD_COIN, ITEMCOUNT_MAX)
    elseif item.itemid == ITEM_CRYSTAL_COIN then
        Item(item.uid):transform(item.itemid, item.type - 1)
        Player(cid):addItem(ITEM_PLATINUM_COIN, ITEMCOUNT_MAX)
    else
        return false
    end

    return true
end

what i want to know is where are this coins variables declared, because i searched them in the global.lua, but they are not there, i understand how this function works but i need to add the bar of gold variable to asociate it with his id.

hope someone can help me, and thanks in advice.

PD: i searched in forum and scripts for this doesnt work, i guess becuase they are for another TFS Version

Ok i make it work by declaring the variables in the script, now it is working thanks!!
 
Last edited by a moderator:
Solution
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, changeTo = x}
    [x] = {changeBack = ITEM_CRYSTAL_COIN}
}

function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local coin = config[item.itemid]
    if not coin then
        return false
    end

    if coin.changeTo and item.type == 100 then
        item:remove()
        player:addItem(coin.changeTo, 1)
    elseif coin.changeBack then
        item:transform(item.itemid, item.type - 1)
        player:addItem(coin.changeBack, 100)
    else
        return false
    end
    return true
end
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, changeTo = x}
    [x] = {changeBack = ITEM_CRYSTAL_COIN}
}

function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local coin = config[item.itemid]
    if not coin then
        return false
    end

    if coin.changeTo and item.type == 100 then
        item:remove()
        player:addItem(coin.changeTo, 1)
    elseif coin.changeBack then
        item:transform(item.itemid, item.type - 1)
        player:addItem(coin.changeBack, 100)
    else
        return false
    end
    return true
end
 
Last edited by a moderator:
Solution
Code:
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, changeTo = x}
    [x] = {changeBack = ITEM_CRYSTAL_COIN}
}

function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local coin = config[item.itemid]
    if not coin then
        return false
    end

    if coin.changeTo and item.type == 100 then
        item:remove()
        player:addItem(coin.changeTo, 1)
    elseif coin.changeBack then
        item:transform(item.itemid, item.type - 1)
        player:addItem(coin.changeBack, 100)
    else
        return false
    end
    return true
end


wow thanks for aswering, im new on this, but this code looks better than the one i used, i will use it, thank you a lot
 
Back
Top