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

TFS 1.X+ npc accept new coins

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
278
Solutions
1
Reaction score
50
Location
Paraná,Brazil
Someone could help me with some solution to this problem of mine, I found an npc here on the forum that I can buy the items through other items without using the 'gold coin', but in the image is showing the gold coin, I would have to change it to the new currency appear?

1599680164880.png1599680265909.png

 
Someone could help me with some solution to this problem of mine, I found an npc here on the forum that I can buy the items through other items without using the 'gold coin', but in the image is showing the gold coin, I would have to change it to the new currency appear?

View attachment 49636View attachment 49637

@darkmu inside your data/lib/core you will find player.lua here you will find

LUA:
local type_crystal = ItemType(ITEM_CRYSTAL_COIN)
    local crystalCoins = math.floor(amount / 10000)
    if crystalCoins > 0 then
        amount = amount - (crystalCoins * 10000)
        while crystalCoins > 0 do
            local count = math.min(100, crystalCoins)
            totalWeight = totalWeight + type_crystal:getWeight(count)
            crystalCoins = crystalCoins - count
            inventorySlots = inventorySlots + 1
        end
    end

Here you must create your own function exactly the same as its written here, but change crystal for your own currency name.
Also you should create the global ITEM_CRYSTAL_COIN inside data/actions/scripts/other/changegold.lua so you tell on which place it must be changed, so lets say it should be the highest currency available you will do it like this:

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 = ITEM_NEWCURRENCY_COIN}
    [ITEM_NEWCURRENCY_COIN] = {changeBack = ITEM_CRYSTAL_COIN}
}

But there is many more :(
in your bank.lua inside your npc scripts you must also add an extra elseif statement for removing and adding the coin.
Beside this you will also need to specify in your source code ITEM_NEWCURRENCY_COIN to the itemid of the new currency. Which you can find in const.h, make edits to game.cpp inside the void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/) function, item.cpp in the uint32_t Item::getWorth() const function, inside luascript you must add a new enum registerEnum(ITEM_NEWCURRENCY_COIN), then finally you must update player.cpp inside the bool Player::updateSaleShopList(const Item* item) function.

I hope you gained enough information to obtain your goal. This is the proper way of doing it.
The not proper way would be replacing ITEM_NEWCURRENCY_COIN for the itemid, but that will not work properly.

Sincerely,
Ralumbi
 
Back
Top