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

getMoney/addMoney/removeMoney issue with max value

bepokemon

Member
Joined
May 16, 2011
Messages
28
Reaction score
6
Hello guys, can anyone help me with editing max money a player can have? I believe its currently capped at 2 billion (maybe cause its uint32), I tried changing to uint64 but failed to compile. :(
Here's my game.cpp ~
C++:
uint32_t Game::getMoney(const Cylinder* cylinder)
{
    if(!cylinder)
        return 0;

    std::list<Container*> listContainer;
    Container* tmpContainer = NULL;

    Thing* thing = NULL;
    Item* item = NULL;

    uint32_t moneyCount = 0;
    for(int32_t i = cylinder->__getFirstIndex(); i < cylinder->__getLastIndex(); ++i)
    {
        if(!(thing = cylinder->__getThing(i)))
            continue;

        if(!(item = thing->getItem()))
            continue;

        if((tmpContainer = item->getContainer()))
            listContainer.push_back(tmpContainer);
        else if(item->getWorth() != 0)
            moneyCount += item->getWorth();
    }

    while(listContainer.size() > 0)
    {
        Container* container = listContainer.front();
        listContainer.pop_front();
        for(ItemList::const_iterator it = container->getItems(); it != container->getEnd(); ++it)
        {
            item = *it;
            if((tmpContainer = item->getContainer()))
                listContainer.push_back(tmpContainer);
            else if(item->getWorth() != 0)
                moneyCount += item->getWorth();
        }
    }

    return moneyCount;
}

bool Game::removeMoney(Cylinder* cylinder, int32_t money, uint32_t flags /*= 0*/)
{
    if(!cylinder)
        return false;

    if(money <= 0)
        return true;

    typedef std::multimap<int32_t, Item*, std::less<int32_t> > MoneyMultiMap;
    MoneyMultiMap moneyMap;

    std::list<Container*> listContainer;
    Container* tmpContainer = NULL;

    Thing* thing = NULL;
    Item* item = NULL;

    int32_t moneyCount = 0;
    for(int32_t i = cylinder->__getFirstIndex(); i < cylinder->__getLastIndex() && money > 0; ++i)
    {
        if(!(thing = cylinder->__getThing(i)))
            continue;

        if(!(item = thing->getItem()))
            continue;

        if((tmpContainer = item->getContainer()))
            listContainer.push_back(tmpContainer);
        else if(item->getWorth() != 0)
        {
            moneyCount += item->getWorth();
            moneyMap.insert(std::make_pair(item->getWorth(), item));
        }
    }

    while(listContainer.size() > 0 && money > 0)
    {
        Container* container = listContainer.front();
        listContainer.pop_front();
        for(int32_t i = 0; i < (int32_t)container->size() && money > 0; i++)
        {
            Item* item = container->getItem(i);
            if((tmpContainer = item->getContainer()))
                listContainer.push_back(tmpContainer);
            else if(item->getWorth() != 0)
            {
                moneyCount += item->getWorth();
                moneyMap.insert(std::make_pair(item->getWorth(), item));
            }
        }
    }

    // Not enough money
    if(moneyCount < money)
        return false;

    for(MoneyMultiMap::iterator mit = moneyMap.begin(); mit != moneyMap.end() && money > 0; ++mit)
    {
        Item* item = mit->second;
        if(!item)
            continue;

        internalRemoveItem(NULL, item);
        if(mit->first > money)
        {
            // Remove a monetary value from an item
            int32_t remaind = item->getWorth() - money;
            addMoney(cylinder, remaind, flags);
            money = 0;
        }
        else
            money -= mit->first;

        mit->second = NULL;
    }

    moneyMap.clear();
    return money == 0;
}

void Game::addMoney(Cylinder* cylinder, int32_t money, uint32_t flags /*= 0*/)
{
    IntegerMap moneyMap = Item::items.getMoneyMap();
    int32_t tmp = 0;
    for(IntegerMap::reverse_iterator it = moneyMap.rbegin(); it != moneyMap.rend(); ++it)
    {
        tmp = money / it->first;
        money -= tmp * it->first;
        if(tmp != 0)
        {
            do
            {
                Item* remaindItem = Item::CreateItem(it->second, std::min(100, tmp));
                if(internalAddItem(NULL, cylinder, remaindItem, INDEX_WHEREEVER, flags) != RET_NOERROR)
                    internalAddItem(NULL, cylinder->getTile(), remaindItem, INDEX_WHEREEVER, FLAG_NOLIMIT);

                tmp -= std::min(100, tmp);
            }
            while(tmp > 0);
        }
    }
}
 
I do have 5 coins. TFS0.3.6.
XML:
<item id="12416" article="a" name="cent" plural="cents">
        <attribute key="description" value="One hundred of these can be converted in a dollar." />
        <attribute key="duration" value="5" />
        <attribute key="worth" value="1" />
    </item>
<item id="2148" article="a" name="dollar note" plural="dollar notes">
        <attribute key="weight" value="0" />
        <attribute key="worth" value="100" />
        <attribute key="description" value="One hundred of these can be converted in a hundred dollar note." />
    </item>
<item id="2152" article="a" name="hundred dollar note" plural="hundred dollar notes">
        <attribute key="weight" value="0" />
        <attribute key="worth" value="10000" />
        <attribute key="description" value="One hundred of these can be converted in a ten thound dollar note." />
    </item>
<item id="2160" article="a" name="ten thousand dollar note" plural="ten thousand dollar notes">
        <attribute key="weight" value="0" />
        <attribute key="worth" value="1000000" />
        <attribute key="description" value="Valuable money!" />
    </item>
    <item id="2161" article="a" name="one million dollar note" plural="million dollar notes">
        <attribute key="weight" value="0" />
        <attribute key="worth" value="100000000" />
        <attribute key="description" value="I mean... That's a lot of money!" />
    </item>
When I have 20 or more milion dollar notes (aprox 2000000000 worth), things get a lil glitchy.
 
what the script u will for npc or houses or ?? i already edit sources for houses and edit npc for this coins and actions all for tfs 0.4 so i can help u
 
Back
Top