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

Int overflow bug!

Status
Not open for further replies.

Mokerhamer

Retired Global Mod
Senator
Joined
Aug 6, 2007
Messages
1,767
Reaction score
36
Hi guys,

i made an Golden nugget support. But we are having some problems with the Int overflow (If an npc should give you loads of money it will give 100gn,164cc,164,plat,164 gold) And korn told me it's an int bug.

Altought my team mate dosen't has the time to fix it i'm asking some help on otland :)

here is the code that i made we are using 0.2.4!

Hi,

(testen on Source 2.1+)

This is an very very very simple code but some people might use it. Thise code allows to acsept Golden nuggets/or pai with golden nuggets on your server.

Let's start!

Const.h

AFTER
Code:
	ITEM_COINS_CRYSTAL	= 2160,
ADD
Code:
    ITEM_GOLD_NUGGET	= 2157,




Item.cpp
AFTER
Code:
		case ITEM_COINS_CRYSTAL:
			return getItemCount() * 10000;
			break;
ADD
Code:
case ITEM_GOLD_NUGGET:
			return getItemCount() * 1000000;
			break;




Game.cpp
BEFORE
Code:
	int32_t crys = money / 10000;
	money -= crys * 10000;
ADD
Code:
    int32_t nugget = money / 1000000;
	money -= nugget * 1000000;


BEFORE

Code:
	if(crys != 0)
	{
		do
		{
			Item* remaindItem = Item::CreateItem(ITEM_COINS_CRYSTAL, std::min(100, crys));

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

			crys -= std::min(100, crys);
		}
		while(crys > 0);
	}

ADD
Code:
	if(nugget != 0)
	{
		do
		{
			Item* remaindItem = Item::CreateItem(ITEM_GOLD_NUGGET, std::min(100, nugget));

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

			nugget -= std::min(100, nugget);
		}
		while(nugget > 0);
	}

I hope you will find it usefull.
How to make sutch codes? You NEED to have a brain to know how to copy/paste and edit them!

//Mokerhamer
 
I get this error

C:\Users\Gebruiker\Desktop\source\game.cpp In member function `void Game::addMoney(Cylinder*, int32_t, uint32_t)':
1774 C:\Users\Gebruiker\Desktop\source\game.cpp no matching function for call to `min(int, uint32_t&)'
C:\Users\Gebruiker\Desktop\source\Makefile.win [Build Error] [obj//game.o] Error 1

Anywais the function is big, could u take a look in the source code?
i use 0.2.4

Oke i have managed to compile it (changed more stuff)
Everything is fune until i hut the sell button then everything freezes. I even tryt with the Debug version but still no luk!

I have fixed the Int overflow Thanks!
 
Last edited:
Status
Not open for further replies.
Back
Top