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

Solved [TFS 1.2] removeMoney is bugged when more than 100 coins

guiismiti

Well-Known Member
Joined
May 19, 2014
Messages
315
Solutions
3
Reaction score
68
Hello,

As the title says, this function is bugged in TFS 1.2.

If I try to make any operation with an NPC to give it more than 100 coins, it will always do the operation and give me 101 coins in the end.

E. g.:
  • Buying an item that costs 2kk - If I have 200 crystal coins, I will get the item + 101 crystal coins;
  • Depositing money - if I have more than 100 coins, it will add the amount to my balance, remove all stacks of 100 coins and give me 101 coins (or remove all stacks but the last one, and instead of removing the last one, it will give me 1 coin).

It is happening to all coins (gold, platinum and crystal).
I'm looking for the code - am I gonna need to change hard code for that?


This is in game.cpp
Code:
bool Game::removeMoney(Cylinder* cylinder, uint64_t money, uint32_t flags /*= 0*/)
{
    if (cylinder == nullptr) {
        return false;
    }

    if (money == 0) {
        return true;
    }

    std::vector<Container*> containers;

    std::multimap<uint64_t, Item*> moneyMap;
    uint64_t moneyCount = 0;

    for (size_t i = cylinder->getFirstIndex(), j = cylinder->getLastIndex(); i < j; ++i) {
        Thing* thing = cylinder->getThing(i);
        if (!thing) {
            continue;
        }

        Item* item = thing->getItem();
        if (!item) {
            continue;
        }

        Container* container = item->getContainer();
        if (container) {
            containers.push_back(container);
        } else {
            int32_t worth = item->getWorth();
            if (worth != 0) {
                moneyCount += worth;
                moneyMap.emplace(worth, item);
            }
        }
    }

    size_t i = 0;
    while (i < containers.size()) {
        Container* container = containers[i++];
        for (Item* item : container->getItemList()) {
            Container* tmpContainer = item->getContainer();
            if (tmpContainer) {
                containers.push_back(tmpContainer);
            } else {
                int32_t worth = item->getWorth();
                if (worth != 0) {
                    moneyCount += worth;
                    moneyMap.emplace(worth, item);
                }
            }
        }
    }

    if (moneyCount < money) {
        return false;
    }

    for (const auto& moneyEntry : moneyMap) {
        Item* item = moneyEntry.second;
        if (moneyEntry.first >= money) {
            uint32_t worth = moneyEntry.first / item->getItemCount();
            uint32_t removeCount = (money / worth) + 1;

            addMoney(cylinder, (worth * removeCount) - money, flags);
            internalRemoveItem(item, removeCount);
            return true;
        }

        internalRemoveItem(item);
        money -= moneyEntry.first;
    }
    return false;
}
 
Last edited:
Its a tfs 1.2 issue i believe, 1.1 does not have this bug(i'm just saying that for people that uses 1.1 and may be worried).
 
Back
Top