#I'm not english.
Hello,
On this tutorial we will learn how to fix GetGold command.
The bug make your penya goes to 0 by exceeding of int max value
Ok, let's go.
First you have to open FuncTextCmd.cpp (Interface folder)
Search (CTRL+F): BOOL TextCmd_GetGold( CScanner& scanner )
You should have the following code:
Well, now we must check if nGold > 2147483646 (Max int size - 1):
First, create a variable call for example maxIntValue and assign it to 2147483646
Ok, well the variable is create. Now we must make a condition who check if nGold > MaxIntValue.
Ok, right. The next part is optional. We must check if maxIntValue >= gold user + nGold.
That's simply check if user gold + nGold (input) is inferior than maxIntValue
Pastebin final link with correct indentation:
Should work, bye
Hello,
On this tutorial we will learn how to fix GetGold command.
The bug make your penya goes to 0 by exceeding of int max value
Ok, let's go.
First you have to open FuncTextCmd.cpp (Interface folder)
Search (CTRL+F): BOOL TextCmd_GetGold( CScanner& scanner )
You should have the following code:
PHP:
BOOL TextCmd_GetGold( CScanner& scanner )
{
#ifdef __WORLDSERVER
CUser* pUser = (CUser*)scanner.dwValue;
int nGold = scanner.GetNumber();
pUser->AddGold( nGold );
#endif // __WORLDSERVER
return TRUE;
}
Well, now we must check if nGold > 2147483646 (Max int size - 1):
First, create a variable call for example maxIntValue and assign it to 2147483646
PHP:
BOOL TextCmd_GetGold( CScanner& scanner )
{
#ifdef __WORLDSERVER
CUser* pUser = (CUser*)scanner.dwValue;
int maxIntValue = 2147483646; // max int value - 1
int nGold = scanner.GetNumber();
pUser->AddGold( nGold );
#endif // __WORLDSERVER
return TRUE;
}
Ok, well the variable is create. Now we must make a condition who check if nGold > MaxIntValue.
PHP:
BOOL TextCmd_GetGold( CScanner& scanner )
{
#ifdef __WORLDSERVER
CUser* pUser = (CUser*)scanner.dwValue;
int maxIntValue = 2147483646; // max int value - 1
int nGold = scanner.GetNumber();
if(nGold > MaxIntValue)
{
pUser->AddText("Oversized !");
}
else
{
int nGold = scanner.GetNumber();
pUser->AddGold( nGold );
#endif // __WORLDSERVER
}
return TRUE;
}
Ok, right. The next part is optional. We must check if maxIntValue >= gold user + nGold.
That's simply check if user gold + nGold (input) is inferior than maxIntValue
PHP:
BOOL TextCmd_GetGold( CScanner& scanner )
{
#ifdef __WORLDSERVER
CUser* pUser = (CUser*)scanner.dwValue;
int maxIntValue = 2147483646; // max int value - 1
int userGold = pUser->GetGold(); // Get user gold
int nGold = scanner.GetNumber();
if(nGold > MaxIntValue)
{
pUser->AddText("Oversized !");
}
else
{
if(maxIntValue >= (userGold + nGold))
{
pUser->AddGold( nGold );
}
else
{
pUser->AddGold(maxIntValue);
}
}
return TRUE;
}
Pastebin final link with correct indentation:
You must be registered to see links
Should work, bye
Last edited: