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

[SOLVED] Check to see if bags are full

Status
Not open for further replies.

Reloac

BETA Tester
Hey

I've been working on making items cost a custom currency, so far so good.. it will error if they dont have enough Magic Gold, and it will give them the item if they do and deduct the Magic Gold, but if their inventory is full, and they have the Magic Gold for the item, it takes that and doesn't give them the item, im trying to work out how i can add a check to see if they have space and if not to error and say they dont have any.. but all tries have failed :/

Code:
	if (pProto->mgcost > 0)
	{

		QueryResult result = LoginDatabase.PQuery("SELECT magic_gold FROM magic_gold WHERE id='%u'", GetSession()->GetAccountId());
		if (result)
		{
				Field* fields = result->Fetch();
				uint32 CurrentMagicGold = fields[0].GetUInt32();

				if (pProto->zgcost > CurrentMagicGold)
				{
					ChatHandler(GetSession()).SetSentErrorMessage(true);
					ChatHandler(GetSession()).PSendSysMessage("Not enough Magic Gold! [Item Cost : %u]", pProto->mgcost);
					SendBuyError(BUY_ERR_CANT_FIND_ITEM, creature, item, 0);
					return false;
				}
				else
				{
					CurrentMagicGold -= pProto->mgcost;
					ChatHandler(GetSession()).PSendSysMessage("Deducted %u Magic Gold!", pProto->mgcost);
					LoginDatabase.PExecute("UPDATE magic_gold SET magic_gold='%u' WHERE id='%u'", CurrentMagicGold, GetSession()->GetAccountId());
				}
			}
		}

Any help would be awesome...
 
Last edited:

Tommy

Founder
The function add item is a boolean, so you could do:

Code:
                                    if (player->AddItem(itemId, count))
                                    {
					CurrentMagicGold -= pProto->zgcost;
					ChatHandler(GetSession()).PSendSysMessage("Deducted %u Magic Gold!", pProto->mgcost);
					LoginDatabase.PExecute("UPDATE magic_gold SET magic_gold='%u' WHERE id='%u'", CurrentMagicGold, GetSession()->GetAccountId());
                                    }
                                    // else // bags are full or item doesn't exist
 

Reloac

BETA Tester
Thanks, i don't think it would work though (?) as the items are bought from a vendor and the item has a table added named mgcost, it would check if it is above 0 ect.. its not actually in a script but added to the function to buy items from a vendor.
 

Tommy

Founder
Thanks, i don't think it would work though (?) as the items are bought from a vendor and the item has a table added named mgcost, it would check if it is above 0 ect.. its not actually in a script but added to the function to buy items from a vendor.

I'd recommend putting the magic gold cost code inside of the function "bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot)" located in Player.cpp.

Put the magic cost code above "if (crItem->ExtendedCost)".

Since it would deplete you having to check yourself when you can add it in that function, which will do everything for you. Why not anyway? Since you're using magic gold or whatever as a currency, it might as well be there. :3
 

Reloac

BETA Tester
that would be the location it already is included in but still deducts their magic gold even if they get the item or not :p ^^
 

Tommy

Founder
that would be the location it already is included in but still deducts their magic gold even if they get the item or not :p ^^

I think I gave you the wrong info on where to put the code. Either way, how would I know where you have it since you only gave me the magic gold code? :p

Put your magic gold code below:

Code:
        if (!_StoreOrEquipNewItem(vendorslot, item, count, bag, slot, price, pProto, creature, crItem, true))
            return false;

in the same function, close to the bottom. It's inside of another if statement:

Code:
    if ((bag == NULL_BAG && slot == NULL_SLOT) || IsInventoryPos(bag, slot))
    {
        if (!_StoreOrEquipNewItem(vendorslot, item, count, bag, slot, price, pProto, creature, crItem, true))
            return false;
    }

That checks to see if you can store or equip the newly bought item. I'm not thinking of the logic really, lol.. Kinda not in the mood today I guess..
 

Reloac

BETA Tester
haha thanks, pretty tired at the moment so not thinking, funny enough i did try them.. but they didn't have the desired effect prob because i used them wrong, however.. would it be possible for you to add it where it needs to go because.. being late.. id most prob mess up where they're ment to go.. xD

http://paste.emudevs.com/?paste=74 is my code.
 
Status
Not open for further replies.
Top