Jump to content

Yang Gold Bug Negative


Metin2 Dev

Recommended Posts

  • Bot

Find the function:

void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast)

Find the case:

POINT_GOLD

And put this:

		case POINT_GOLD:
			{
				unsigned int nTotalMoney = GetGold() + amount;
				if (nTotalMoney > GOLD_MAX) {
					return;
				}else if (nTotalMoney < 0) {
					return;
				}else{
					SetGold(GetGold() + amount);
					val = GetGold();
				}
			}
			break;

Your YANGS never been negatives!

  • Love 1

english_banner.gif

Link to comment
Share on other sites

7 hours ago, M2BobFixed said:

 


		case POINT_GOLD:
			{
				unsigned int nTotalMoney = GetGold() + amount;
				if (nTotalMoney > GOLD_MAX) {
					return;
				}else if (nTotalMoney < 0) {
					return;
				}else{
					SetGold(GetGold() + amount);
					val = GetGold();
				}
			}
			break;

 

I don't understand why you have this style, but ok.

	case POINT_GOLD:
	{
		unsigned int nTotalMoney = GetGold() + amount;
		if (nTotalMoney < 0 || nTotalMoney > GOLD_MAX)
			return;

		SetGold(GetGold() + amount);
		val = GetGold();
	}
	break;

 

Link to comment
Share on other sites

1 hour ago, Abel(Tiger) said:

unsigned int nTotalMoney

if(nTotalMoney < 0) 

Really ? nTotalMoney never can be negative.

You should think better and read again.

PS: I speak about this situation and code from this topic, ymir did a check "GOLD_MAX <= nTotalMoney" .

_________________________________________________________________

Please enter an integer amount of gold: -500000

  • GetGold: 25000
  • amount: -500000
  • nTotalMoney: -475000

Succes set gold to: -475000

#include <iostream>
#include <algorithm>
using namespace std;

typedef int INT;
typedef unsigned int UINT;

typedef struct character_point
{
	uint64_t gold = 25000;
} CHARACTER_POINT;
CHARACTER_POINT m_points;

INT GetGold()
{
    return m_points.gold;   
}

void SetGold(INT gold)
{
    m_points.gold = gold;
    printf("Succes set gold to: %d", gold);
}

void PointChange(INT iAmount)
{
    UINT nTotalMoney = GetGold() + iAmount;
    printf(" GetGold: %d\n amount: %d\n nTotalMoney: %d\n", GetGold(), iAmount, nTotalMoney);
    SetGold(GetGold() + iAmount);
}

int main()
{
    INT val;
    cout << "Please enter an integer amount of gold: ";
    cin >> val;
    PointChange(val);
}

 

Link to comment
Share on other sites

  • Honorable Member

int x, y;

x= abs(-11);

y = abs(11);

x==y

17 minutes ago, Tasho said:

You should think better and read again.

0D73aab.jpg


#include <iostream>
#include <algorithm>
using namespace std;

typedef int INT;
typedef unsigned int UINT;

INT GetGold()
{
    return 25000;   
}

void PointChange(INT iAmount)
{
    UINT nTotalMoney = GetGold() + iAmount;
    printf("GetGold: %d\n", GetGold());
    printf("amount: %d\n", iAmount);
    printf("nTotalMoney: %d", nTotalMoney);
}

int main()
{
    INT val;
    cout << "Please enter an integer amount of gold: ";
    cin >> val;
    PointChange(val);
}

 

I love getline(cin, val) 

Edited by Metin2 Dev
Core X - External 2 Internal

 

Link to comment
Share on other sites

  • Active+ Member

screenshot_124.png

http://cpp.sh/2qr6b

screenshot_125.png

Are you sure total money will be -475000 ?

In your code is no condition and your print of nTotalMoney is wrong , a unsigned variable should be printed with %u.

Ofc if you print a unsigned variable with signed type it will make automaticaly conversion. (Like you put (int) before variable). http://cpp.sh/9gvt6

So Mali61if you really want to use that condition try like that: (or use @xP3NG3Rx code , is better)

		case POINT_GOLD:
			{
				unsigned int nTotalMoney = GetGold() + amount;
				if (nTotalMoney > GOLD_MAX) {
					return;
				}else if ((int)nTotalMoney < 0) {
					return;
				}else{
					SetGold(GetGold() + amount);
					val = GetGold();
				}
			}

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • 1 year later...

Sorry for update but i need a fix to overflow yangs, and there is nosense to open another topic.

Can I know in which way this will fix the overflow yangs issue?

On 10/15/2017 at 1:14 PM, xP3NG3Rx said:

		case POINT_GOLD:
			{
				UINT newGold = MINMAX(0, GetGold() + amount, g_llMaxGold);//!!!MaxGold
				SetGold(newGold);
				val = GetGold();
			}
			break;

 

 

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.