• 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+ coin accept

God Aries

New Member
Joined
Jun 24, 2018
Messages
44
Reaction score
4
Good morning community, I am having a problem with a new currency that I add by installing a changegold script that 100 crystal coin becomes a gold ingot and everything works well, the only thing is that the npcs do not detect the gold ingot as a currency, it should detect and for of course give me the change of what I have left over

I need to solve this for tfs 1.3, I use otx.

I hope and can help me, thanks
 
Solution
const.h

Change this lines:
Code:
    ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
To this lines: As you see there is "2151" its server gold ingot ID, change it for you server gold ingot ID or what you want.
Code:
    ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
    ITEM_GOLD_INGOT = 2151,

game.cpp

After this line:
Code:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }
Add this line:
Code:
    uint32_t goldIngot = money / 1000000;
    money -= goldIngot * 1000000;
    while (goldIngot > 0) {
        const uint16_t count = std::min<uint32_t>(100...
Good morning community, I am having a problem with a new currency that I add by installing a changegold script that 100 crystal coin becomes a gold ingot and everything works well, the only thing is that the npcs do not detect the gold ingot as a currency, it should detect and for of course give me the change of what I have left over

I need to solve this for tfs 1.3, I use otx.

I hope and can help me, thanks
Its not defined as money.
in item.cpp, luascript.cpp, player.cpp, game.cpp, const.h y ou must add lines to define new currency, just copy previous. and change need things.
 
Its not defined as money.
in item.cpp, luascript.cpp, player.cpp, game.cpp, const.h y ou must add lines to define new currency, just copy previous. and change need things.
yes, I just saw it in another post that you line but in tfs 1.2 although they are similar, the problem is that it is not compiled, I will have to see tutorials
 
const.h

Change this lines:
Code:
    ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
To this lines: As you see there is "2151" its server gold ingot ID, change it for you server gold ingot ID or what you want.
Code:
    ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
    ITEM_GOLD_INGOT = 2151,

game.cpp

After this line:
Code:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }
Add this line:
Code:
    uint32_t goldIngot = money / 1000000;
    money -= goldIngot * 1000000;
    while (goldIngot > 0) {
        const uint16_t count = std::min<uint32_t>(100, goldIngot);

        Item* remaindItem = Item::CreateItem(ITEM_GOLD_INGOT, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        goldIngot -= count;
    }

item.cpp

Change this:
Code:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        default:
            return 0;
    }
}

To this:

Code:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        case ITEM_GOLD_INGOT:
            return count * 1000000;

        default:
            return 0;
    }
}

luascript.cpp

After this:

Code:
    registerEnum(ITEM_CRYSTAL_COIN)

Add this:

Code:
    registerEnum(ITEM_GOLD_INGOT)

player.cpp

Change this:
Code:
bool Player::updateSaleShopList(const Item* item)
{
    uint16_t itemId = item->getID();
    if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN) {
        auto it = std::find_if(shopItemList.begin(), shopItemList.end(), [itemId](const ShopInfo& shopInfo) { return shopInfo.itemId == itemId && shopInfo.sellPrice != 0; });
        if (it == shopItemList.end()) {
            const Container* container = item->getContainer();
            if (!container) {
                return false;
            }

            const auto& items = container->getItemList();
            return std::any_of(items.begin(), items.end(), [this](const Item* containerItem) {
                return updateSaleShopList(containerItem);
            });
        }
    }

    if (client) {
        client->sendSaleItemList(shopItemList);
    }
    return true;
}

To this:

Code:
bool Player::updateSaleShopList(const Item* item)
{
    uint16_t itemId = item->getID();
    if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_GOLD_INGOT) {
        auto it = std::find_if(shopItemList.begin(), shopItemList.end(), [itemId](const ShopInfo& shopInfo) { return shopInfo.itemId == itemId && shopInfo.sellPrice != 0; });
        if (it == shopItemList.end()) {
            const Container* container = item->getContainer();
            if (!container) {
                return false;
            }

            const auto& items = container->getItemList();
            return std::any_of(items.begin(), items.end(), [this](const Item* containerItem) {
                return updateSaleShopList(containerItem);
            });
        }
    }

    if (client) {
        client->sendSaleItemList(shopItemList);
    }
    return true;
}

Now u have next stage of currency :)
 
Solution
Good morning community, I am having a problem with a new currency that I add by installing a changegold script that 100 crystal coin becomes a gold ingot and everything works well, the only thing is that the npcs do not detect the gold ingot as a currency, it should detect and for of course give me the change of what I have left over

I need to solve this for tfs 1.3, I use otx.

I hope and can help me, thanks
If this help and work mark is as solved. This will help each other who get the same issue and easy find solve :)
 
Sorry for the delay in writing, I had other difficulties on my server and I did not have time to edit sources but I already edited them and it works perfect, thank you very much for the guide, you are very kind, God bless you <3
 
Sorry for the delay in writing, I had other difficulties on my server and I did not have time to edit sources but I already edited them and it works perfect, thank you very much for the guide, you are very kind, God bless you <3
you still haven't marked his answer as best answer tho 😁
 
const.h

Change this lines:
Code:
    ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
To this lines: As you see there is "2151" its server gold ingot ID, change it for you server gold ingot ID or what you want.
Code:
    ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
    ITEM_GOLD_INGOT = 2151,

game.cpp

After this line:
Code:
void Game::addMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (money == 0) {
        return;
    }
Add this line:
Code:
    uint32_t goldIngot = money / 1000000;
    money -= goldIngot * 1000000;
    while (goldIngot > 0) {
        const uint16_t count = std::min<uint32_t>(100, goldIngot);

        Item* remaindItem = Item::CreateItem(ITEM_GOLD_INGOT, count);

        ReturnValue ret = internalAddItem(cylinder, remaindItem, INDEX_WHEREEVER, flags);
        if (ret != RETURNVALUE_NOERROR) {
            internalAddItem(cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);
        }

        goldIngot -= count;
    }

item.cpp

Change this:
Code:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        default:
            return 0;
    }
}

To this:

Code:
uint32_t Item::getWorth() const
{
    switch (id) {
        case ITEM_GOLD_COIN:
            return count;

        case ITEM_PLATINUM_COIN:
            return count * 100;

        case ITEM_CRYSTAL_COIN:
            return count * 10000;

        case ITEM_GOLD_INGOT:
            return count * 1000000;

        default:
            return 0;
    }
}

luascript.cpp

After this:

Code:
    registerEnum(ITEM_CRYSTAL_COIN)

Add this:

Code:
    registerEnum(ITEM_GOLD_INGOT)

player.cpp

Change this:
Code:
bool Player::updateSaleShopList(const Item* item)
{
    uint16_t itemId = item->getID();
    if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN) {
        auto it = std::find_if(shopItemList.begin(), shopItemList.end(), [itemId](const ShopInfo& shopInfo) { return shopInfo.itemId == itemId && shopInfo.sellPrice != 0; });
        if (it == shopItemList.end()) {
            const Container* container = item->getContainer();
            if (!container) {
                return false;
            }

            const auto& items = container->getItemList();
            return std::any_of(items.begin(), items.end(), [this](const Item* containerItem) {
                return updateSaleShopList(containerItem);
            });
        }
    }

    if (client) {
        client->sendSaleItemList(shopItemList);
    }
    return true;
}

To this:

Code:
bool Player::updateSaleShopList(const Item* item)
{
    uint16_t itemId = item->getID();
    if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_GOLD_INGOT) {
        auto it = std::find_if(shopItemList.begin(), shopItemList.end(), [itemId](const ShopInfo& shopInfo) { return shopInfo.itemId == itemId && shopInfo.sellPrice != 0; });
        if (it == shopItemList.end()) {
            const Container* container = item->getContainer();
            if (!container) {
                return false;
            }

            const auto& items = container->getItemList();
            return std::any_of(items.begin(), items.end(), [this](const Item* containerItem) {
                return updateSaleShopList(containerItem);
            });
        }
    }

    if (client) {
        client->sendSaleItemList(shopItemList);
    }
    return true;
}

Now u have next stage of currency :)

Can anyone apply for this Repo "GitHub - opentibiabr/canary: Canary Server 13.x for OpenTibia community. (https://github.com/opentibiabr/canary)" and would like to share some cool tutorial?
 
Back
Top