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

C++ Problem with new coin

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
504
Solutions
16
Reaction score
98
I have two editeds coins in my server
bar of gold and vampire coin. one bar of gold = 1000000 and vampire = 100000000
if i deposit 50x100 bar of gold all good
Naji: Would you really like to deposit 5000000000 gold?
but if i deposit 50 vampire
Naji: Would you really like to deposit 705032704 gold?

change in source
luascript.cpp
C++:
registerEnum(ITEM_VAMPIRE_COIN)
item.cpp
C++:
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_BAR_OF_GOLD:
            return count * 1000000;   
           
        case ITEM_VAMPIRE_COIN:
            return count * 100000000;
           
        default:
            return 0;
    }
}
const.h
C++:
ITEM_BAR_OF_GOLD = 15515,
ITEM_VAMPIRE_COIN = 9020,
game.cpp
C++:
    uint32_t tgold = money / 100000000;
    money -= tgold * 100000000;
    while (tgold > 0) {
        const uint16_t count = std::min<uint32_t>(100, tgold);

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

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

        tgold -= count;
    }
   
    uint32_t barofgold = money / 1000000;
    money -= barofgold * 1000000;
    while (barofgold > 0) {
        const uint16_t count = std::min<uint32_t>(100, barofgold);

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

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

        barofgold -= count;
    }
player.cpp
C++:
    if (itemId != ITEM_GOLD_COIN && itemId != ITEM_PLATINUM_COIN && itemId != ITEM_CRYSTAL_COIN && itemId != ITEM_BAR_OF_GOLD && itemId != ITEM_VAMPIRE_COIN) {
 
Solution
Integer overflow - Wikipedia
increase your integer sizes to hold uint64_t or else the number will keep overflowing
100,000,000 * 50 = 5 billion
uint32_t holds 4,294,967,295
5,000,000,000 is the amount of money needed, 4,294,967,295 is the limit
once 4,294,967,295 is surpasssed, it starts counting from 0 again
5,000,000,000 - 4,294,967,295 = 705,032,704
Result too large for uint32_t causing some crazy shit to happen?

(I don't know much about c++ at all)
if the problem is uint32_t why bar of gold its work ?
i already changed it to uint64_t , but no effect
50 bar of gold * 100 = 5000000000
50 vampires = 5000000000
 
? do you even read my post? Your code can only hold 4,2 billion. which is 4,2xx,xxx,xxx

50 million is, 50,xxx,xxx
Yes i read your post, but i just dont understand why bar of gold work
if i deposit 50 million in item bar of gold is function.
how i can solve it ?
 
Yes i read your post, but i just dont understand why bar of gold work
if i deposit 50 million in item bar of gold is function.
how i can solve it ?
holy shit you cant read. max value is 4,2 billion not 42 million or 4,2 million.


only way to solve it is to raise the limit to uint_64t or something dont ask me how to do it
 
Integer overflow - Wikipedia
increase your integer sizes to hold uint64_t or else the number will keep overflowing
100,000,000 * 50 = 5 billion
uint32_t holds 4,294,967,295
5,000,000,000 is the amount of money needed, 4,294,967,295 is the limit
once 4,294,967,295 is surpasssed, it starts counting from 0 again
5,000,000,000 - 4,294,967,295 = 705,032,704
 
Solution
Integer overflow - Wikipedia
increase your integer sizes to hold uint64_t or else the number will keep overflowing
100,000,000 * 50 = 5 billion
uint32_t holds 4,294,967,295
5,000,000,000 is the amount of money needed, 4,294,967,295 is the limit
once 4,294,967,295 is surpasssed, it starts counting from 0 again
5,000,000,000 - 4,294,967,295 = 705,032,704
jajajajajajaja
 
Back
Top