• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore 2 Gold Max Work-Around

slp13at420

Mad Scientist
How to Bypass the gold cap. TrinityCore2 with Boost
thanks to all those who posted the fix as the core changes [MENTION=10]AlexeWarr[/MENTION], [MENTION=428]darksoke[/MENTION] and more , this is just another update to the work-a-round for players gold cap. this is just a more in-depth work-around with help from [MENTION=6]Rochet2[/MENTION].

go to \src\server\game\Entities\Player and open player.cpp.
search for this block around line 22744 :
Code:
bool Player::ModifyMoney(int32 amount, bool sendError /*= true*/)
{
    if (!amount)
        return true;

     sScriptMgr->OnPlayerMoneyChanged(this, amount);

    if (amount < 0)
        SetMoney (GetMoney() > uint32(-amount) ? GetMoney() + amount : 0);
    else
    {
        if (GetMoney() < MAX_MONEY_AMOUNT - static_cast<uint32>(amount))
            SetMoney(GetMoney() + amount);
        else
        {
            [COLOR="#FF0000"]sScriptMgr->OnPlayerMoneyLimit(this, amount);

            if (sendError)

                SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL 
           return false;[/COLOR]
        }
    }

    return true;
}

go to 'if (sendError)'

and remove these 3 consecutive lines:
Code:
            [COLOR="#FF0000"]sScriptMgr->OnPlayerMoneyLimit(this, amount);

            if (sendError)

                SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL 
           return false;[/COLOR]

and add these lines within the `{}` brackets:
Code:
            static const uint32 item_ID = ITEM_SQL_ID; // the id of your item worth 50k gold buy/sell
            const ItemTemplate* currency = sObjectMgr->GetItemTemplate(item_ID);

                    if(!currency)
                        {
                            sScriptMgr->OnPlayerMoneyLimit(this, amount);

                                if (sendError)
                                    SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
                                return false;
                        }

                    uint16 Pamount = (GetMoney() / 500000000); // int16 since the answer shouldnt be large or somethings wrong
                    uint16 Namount = (amount / 500000000);
                    uint16 Icount = Pamount + Namount;
                    uint64 Ptotal = GetMoney() + amount;

                    if(!AddItem(item_ID,  Icount))
                        return false;

                    SetMoney(Ptotal - (Icount * 500000000));
                    ChatHandler(GetSession()).PSendSysMessage("|cFFFFCC00You have reached the gold limit and have been compensated with %u Gold Bar's|r!", Icount);
                    return true;


the block should look like this now:
Code:
bool Player::ModifyMoney(int32 amount, bool sendError /*= true*/)
{
    if (!amount)
        return true;

     sScriptMgr->OnPlayerMoneyChanged(this, amount);

    if (amount < 0)
        SetMoney (GetMoney() > uint32(-amount) ? GetMoney() + amount : 0);
    else
    {
        if (GetMoney() < MAX_MONEY_AMOUNT - static_cast<uint32>(amount))
            SetMoney(GetMoney() + amount);
        else
        {
            static const uint32 item_ID = ITEM_SQL_ID; // the id of your item worth 50k gold buy/sell
            const ItemTemplate* currency = sObjectMgr->GetItemTemplate(item_ID);

                    if(!currency)
                        {
                            sScriptMgr->OnPlayerMoneyLimit(this, amount);

                                if (sendError)
                                    SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
                                return false;
                        }

                    uint16 Pamount = (GetMoney() / 500000000); // int16 since the answer shouldnt be large or somethings wrong
                    uint16 Namount = (amount / 500000000);
                    uint16 Icount = Pamount + Namount;
                    uint64 Ptotal = GetMoney() + amount;

                    if(!AddItem(item_ID,  Icount))
                        return false;

                    SetMoney(Ptotal - (Icount * 500000000));
                    ChatHandler(GetSession()).PSendSysMessage("|cFFFFCC00You have reached the gold limit and have been compensated with %u Gold Bar's|r!", Icount);
                    return true;
        }
    }

    return true;
}

edit item_ID to the sql id of an item you chose with a buy/sell value of 50k gold (500000000)
basically when a player loots or receives gold that max's there amount, this will remove 200k gold and give 4 items worth 50k gold each allowing the gold/silver/copper currently attempting to add to be added.
this award for amounts over 50k gold for players current gold count and reward for players amounts over 50k gold of current loot.
should work as a good catch-22

A full version of this exists in the donor section
 
Last edited:

slp13at420

Mad Scientist
then TC missed it .
I never edited that line.
just add 5 lines and remove 2 line.
lol k nvrmnd thnx lol I updated
 
Last edited:

ToxicDev

Banned
then TC missed it .
I never edited that line.
just add 3 lines and remove 1 line.

This is fine because they are not executing more than 1 line of code within there if statement more then 1 will require brackets otherwise the second or third line and so on will be executed out side of the if statement.
Code:
[COLOR="#00FF00"]if (blah)
    lol();[/COLOR]

[COLOR="#FF0000"]if (blah)
    lol();
    lawl();[/COLOR]

[COLOR="#00FF00"]if (blah)
{
    lol();
    lawl();
}
[/COLOR]

Trinity Core's code was correct. It was your mistake none the less nice job i guess :p
 
Last edited:

slp13at420

Mad Scientist
I honestly didn't know that but I did test as I edited it lol and didn't have an issue but good to know for future Thanx :D
and updated
 
Last edited:

Rochet2

Moderator / Eluna Dev
Notice that you wrap the code inside if (sendError), which only fires when the code was supposed to send an error message to the player when adding gold.
This means that it wont fire always when the player goes over the limit.. which probably was not intended? I suggest sending the message to player if error is true.
Also the code returns false, when it should return true as the gold WAS added.
Additionally the code does not take into account if large sums are transferred. Such as player being ~at max gold amount and then receives ~max gold amount. (handling over 2000000000 copper amounts of money)
Doing that will go over max gold limit.

I was first looking that the math would overflow, but it doesnt as its done with uint32 it seems and it can fit the int32 overflow.
(namely GetMoney() + amount, while max money that GetMoney should return is max int32 and amount is int32. However GetMoney() can possibly return uint32 range thus possibly causing problems if player is already at over max)

Oh yeah, almost forgot. What about if the player has no bagspace?
You should probably then either send a msg that you need more bag space or then code it to mail the items. Personally I would choose the error.
 
Last edited:

slp13at420

Mad Scientist
also you might want to leave some credits arround , you used my code even the item id ;)

actually I only used 1 line
Code:
GetSession()->SendNotification("|cFFFFCC00You have reached gold limit you have been rewarded with 4 Gold Bars|r!");

and item id 62006 is from Guild Warz , the `Guild Coin` .
https://github.com/BlackWolfsDen/Eluna-Grumboz-Guild-Warz/blob/TC2-335a/sql/Guild_Coin.sql
actually this is closer to [MENTION=10]AlexeWarr[/MENTION]'s fix since that it compensates for the amount above the 200k transaction. where yours set there gold to (0) after the transaction so they will lose 147483647 copper :
Code:
			AddItem(60156, 4);
			SetMoney(0);

but the end product for this will be almost identical for anyone I guess ;P
 
Last edited:

slp13at420

Mad Scientist
Notice that you wrap the code inside if (sendError), which only fires when the code was supposed to send an error message to the player when adding gold.
This means that it wont fire always when the player goes over the limit.. which probably was not intended? I suggest sending the message to player if error is true.
Also the code returns false, when it should return true as the gold WAS added.
I have just been going off past threads , mainly @ak47sigh's. I was just going off what I saw in the player.cpp script so I assumed when its done to return a false but fixed tnx :D

Additionally the code does not take into account if large sums are transferred. Such as player being ~at max gold amount and then receives ~max gold amount. (handling over 2000000000 copper amounts of money)
Doing that will go over max gold limit.
maybe a looping check if(amount > 200K)then give 4 of item and check again,if(amount <200k)then continue.

I was first looking that the math would overflow, but it doesnt as its done with uint32 it seems and it can fit the int32 overflow.
(namely GetMoney() + amount, while max money that GetMoney should return is max int32 and amount is int32. However GetMoney() can possibly return uint32 range thus possibly causing problems if player is already at over max)
maybe?
Code:
AddItem(item_ID, math.floor(GetMoney() / 50,000,00,00)+math.floor(amount / 50,000,00,00)
just a shot in the dark to check each side if at 200k+

I did cause it to jump my chars gold to 400K when I had my math screwed up rofl.

Oh yeah, almost forgot. What about if the player has no bagspace?
You should probably then either send a msg that you need more bag space or then code it to mail the items. Personally I would choose the error.

i'm still a super nooooob at C++ so
my personal work around for that would be to use an item that stores to the players currency tab like the 'magic gold' I use for my VIP system. its stored to the players currency tab:

c5lH60D.png

but then it would be sellable only to a custom vender.
so I would need to find an example of that inventory check to implement it.
 
Last edited:

slp13at420

Mad Scientist
ok I don't know much of C++ so I did what I think your talking about with some lua ...

Code:
bool Player::ModifyMoney(int32 amount, bool sendError /*= true*/)
{
    if (!amount)
        return true;

    sScriptMgr->OnPlayerMoneyChanged(this, amount);

    if (amount < 0)
        SetMoney (GetMoney() > uint32(-amount) ? GetMoney() + amount : 0);
    else
    {
        if (GetMoney() < MAX_MONEY_AMOUNT - static_cast<uint32>(amount))
            SetMoney(GetMoney() + amount);
        else
        {
            sScriptMgr->OnPlayerMoneyLimit(this, amount);

            if (sendError)
                {
                    local Pamount = (GetMoney() / 500000000)
                    local Namount = (amount / 500000000)
 
                        if(AddItem(62006, 1)then
                            {
                                AddItem(62006, (Pamount + Namount)); // (item_id, count) item_id of custom currency worth 50k gold, how many.
                                SetMoney((GetMoney() - (500000000 * Pamount)) + (amount - (500000000 * Namount)));
                                GetSession()->SendNotification("|cFFFFCC00You have reached gold limit you have been rewarded with "..Pamount+Namount.." Gold Bars|r!");
                                return true;
                            }
                        else
                            {
                                SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
                                return false;                       
                            }
                }
        }
    }
 return true;
}
am I roughly in the ball park ?? lol
 
Last edited:

darksoke

OnTop500
yep :) and also you can leave some credits to Alexewarr or something like that , because he if the one who created the first version of this mod , also nice one with the custom currency , i started to hate all those gold bars :|
 

slp13at420

Mad Scientist
yep :) and also you can leave some credits to Alexewarr or something like that , because he if the one who created the first version of this mod , also nice one with the custom currency , i started to hate all those gold bars :|

:facepalm: yep dunno why I was thinking ak47sigh lol
so cudo'z to those who posted before and cudo'z to those who add to the lineage of the gold cap work-around in the future :D
 

slp13at420

Mad Scientist
ok [MENTION=6]Rochet2[/MENTION] I think I figured out a catch-22 :
if a players current inventory of gold is at or over limit , it will blindly just reward for amounts of 50k gold tested with 2147483646 copper in inventory.
if a players current loot value is at or over limit it will blindly just reward tested with 100X rates lol

Code:
            if (sendError)
                {
		            AddItem(62006, (GetMoney() / 500000000) + (amount / 500000000)); // (item_id, count) item_id of custom currency worth 50k gold, how many.
		            SetMoney((GetMoney() - (500000000 * (GetMoney() / 500000000))) + (amount - (500000000 * (amount / 500000000))));
                    GetSession()->SendNotification("|cFFFFCC00You have reached gold limit you have been rewarded Gold Bars|r!");
                return false;
                }

I don't know how to add a check for if there is room in players inventory . also would like to know how to add the amount to the announcement and change it to just a broadcast message.
 

Rochet2

Moderator / Eluna Dev
I ended up with same kind of system, but I was not happy with the flooring etc.
So i decided to use uint64

Untested and unsure of the type conversions.

Code:
bool Player::ModifyMoney(int32 amount, bool sendError /*= true*/)
{
    if (!amount)
        return true;

    sScriptMgr->OnPlayerMoneyChanged(this, amount);

    if (amount < 0)
        SetMoney (GetMoney() > uint32(-amount) ? GetMoney() + amount : 0);
    else
    {
        if (GetMoney() < MAX_MONEY_AMOUNT - static_cast<uint32>(amount))
            SetMoney(GetMoney() + amount);
        else
        {
[COLOR="#FF8C00"]            // item_id of custom currency.
            static const uint32 item_ID = 123123;

            // get currency item data, if doesnt exist fall back to original limit code
            const ItemTemplate* currency = sObjectMgr->GetItemTemplate(item_ID);
            if (!currency)
            {
                sScriptMgr->OnPlayerMoneyLimit(this, amount);

                if (sendError)
                    SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
                return false;
            }

            // calculate item amount and leftover cash
            uint64 total = GetMoney() + amount;
            uint32 itemcount = static_cast<uint32>(floor(total / static_cast<double>(currency->SellPrice)));
            uint32 leftover = static_cast<uint32>(total - itemcount*currency->SellPrice);

            // add items, if couldnt add return false, AddItem sends an error msg in itself
            if (!AddItem(item_ID, itemcount))
                return false;

            // set the leftover cash
            SetMoney(leftover);[/COLOR]
        }
    }

    return true;
}
 
Last edited:

slp13at420

Mad Scientist
Tnx Guyz :D
here is what I have now :

Code:
            if (sendError)
                {
                    static const uint32 item_ID = 62006; // can this be done thru the config file?
                    uint16 Pamount = (GetMoney() / 500000000); // int16 since the answer shouldnt be large or somethings wrong
                    uint16 Namount = (amount / 500000000);
                    uint16 Icount = Pamount + Namount;
                    uint64 Ptotal = GetMoney() + amount;

                    if(!AddItem(item_ID,  Icount))
                        return false;

                    SetMoney(Ptotal - (Icount * 500000000));
                    GetSession()->SendNotification("|cFFFFCC00You have reached the gold limit and have been compensated with %u Guild Coin's|r!", Icount);
                    return true;
                }
and wooooohoooooooooooo it works.while having 2147483646 copper in inv. I loot 1677721472 copper.
I then receive 7 items worth 50k gold each and i'm left with 325205118 copper.

:challengeaccepted:


now that I cant just put "4 guild coins' any more how can I use the value in the notification so the statement is dynamic and in the chat box rather than center screen?

ok I figured out how to add the value :D
 
Last edited:

Rochet2

Moderator / Eluna Dev
Try ChatHandler(GetSession()).PSendSysMessage("My message, the number: %u More text", 123);

I still dont think its a good idea to have the thing inside the if error btw.
 

slp13at420

Mad Scientist
I still dont think its a good idea to have the thing inside the if error btw.
I see what you mean. you have it wrote to check if the item exists and if not then do gold limit error . a good catch 22 :D

ok updated the 1st post and thanks everyone :p
 
Last edited:

darksoke

OnTop500
Tnx Guyz :D
here is what I have now :

Code:
            if (sendError)
                {
                    static const uint32 item_ID = 62006; // can this be done thru the config file?
                    uint16 Pamount = (GetMoney() / 500000000); // int16 since the answer shouldnt be large or somethings wrong
                    uint16 Namount = (amount / 500000000);
                    uint16 Icount = Pamount + Namount;
                    uint64 Ptotal = GetMoney() + amount;

                    if(!AddItem(item_ID,  Icount))
                        return false;

                    SetMoney(Ptotal - (Icount * 500000000));
                    GetSession()->SendNotification("|cFFFFCC00You have reached the gold limit and have been compensated with %u Guild Coin's|r!", Icount);
                    return true;
                }
and wooooohoooooooooooo it works.while having 2147483646 copper in inv. I loot 1677721472 copper.
I then receive 7 items worth 50k gold each and i'm left with 325205118 copper.

:challengeaccepted:


now that I cant just put "4 guild coins' any more how can I use the value in the notification so the statement is dynamic and in the chat box rather than center screen?

ok I figured out how to add the value :D

ofc it is possible

// In World.cpp add the following after "m_int_configs[CONFIG_BIRTHDAY_TIME] = sConfigMgr->GetIntDefault("BirthdayTime", 1222964635);"
Code:
m_bool_configs[CONFIG_MAX_GOLD_TO_TOKEN_ENABLE] = sConfigMgr->GetBoolDefault("GoldToken.Enable", false); // Disabled by default
m_int_configs[CONFIG_MAX_GOLD_TO_TOKEN_TOKEN_ID] = sConfigMgr->GetIntDefault("GoldToken.ItemID", 29434); // By default badge of justice

// In World.h add the following after "CONFIG_INSTANCES_RESET_ANNOUNCE,"
Code:
CONFIG_MAX_GOLD_TO_TOKEN_ENABLE,

// In World.h add the following after "CONFIG_BIRTHDAY_TIME,"
Code:
CONFIG_MAX_GOLD_TO_TOKEN_TOKEN_ID,

// In Player.cpp replace "bool Player::ModifyMoney(int32 amount, bool sendError /*= true*/)" with
Code:
bool Player::ModifyMoney(int32 amount, bool sendError /*= true*/)
{
	if (!amount)
		return true;

	sScriptMgr->OnPlayerMoneyChanged(this, amount);

	static const uint32 item_ID = sWorld->getIntConfig(CONFIG_MAX_GOLD_TO_TOKEN_TOKEN_ID); // can this be done thru the config file?
	uint16 Player_gold_amount = (GetMoney() / 200000000); // int16 since the answer shouldnt be large or somethings wrong
	uint16 Looted_gold_amount = (amount / 200000000);
	uint16 Token_count = Player_gold_amount + Looted_gold_amount;
	uint64 Gold_Left = GetMoney() + amount;

	if (amount < 0)
		SetMoney(GetMoney() > uint32(-amount) ? GetMoney() + amount : 0);
	else
	{
		if (sendError)
		{
			if (sWorld->getBoolConfig(CONFIG_MAX_GOLD_TO_TOKEN_ENABLE)){
				SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
			}
			else{
				if (!AddItem(item_ID, Token_count))
					return false;
				SetMoney(Gold_Left - (Token_count * 200000000));
				ChatHandler(GetSession()).PSendSysMessage("|cffE80000[Gold Exchange]|r |cffffffffYou have reached gold cap and been rewarded with|r |cff0074e8%u|r |cffffffffYour Tokens Name|r", Token_count);
			}
			return true;
		}
	}
	return true;
}

// In worldserver.conf

Code:
###################################################################################################
# MAX GOLD TO TOKEN CONFIG
#
#	GoldToken.Enable
#	Description: Enable / Disable gold conversion into tokens when player reach gold cap
#	Default: 	0 - Disabled
#				1 - Enabled
#

GoldToken.Enable = 1

#
#	GoldToken.ItemID
#	Description: Set the item id of the token you want to exchange
#	Default: 	29434 - Badge of Justice
#

GoldToken.ItemID = 29434

#
###################################################################################################

I did not tested the code but i'm 70% sure it work

UPDATE: Tested the script but there are few things you'll have to figure out yourself how to give the token all you need to rewrite is the Player.cpp part
 
Last edited:
Top