Jump to content
metin2dev
Metin2International
ReFresh

Feature enhancement

Recommended Posts

Hey guys,

can someone improve the function for stacking items automatically when you buy them from the shop?

Explanation: You buy a one potion from shop and you buy the same potion again. Normally you bought 2 same items which are putted in two slots of inventory next to yourself.

Feature enhancement: This will automatically stack same bought items to one slot of inventory automatically. Like when you pick up some stackable item from the floor.

I will be really glad if someone make this feature for free, because it's useful and I think it's the same function when you pick up stackable items from the floor.

Sincerely,

ReFresh

Share this post


Link to post
Share on other sites

                        if (item2->GetVnum() == item->GetVnum())
                        {
                            int j;

                            for (j = 0; j < ITEM_SOCKET_MAX_NUM; ++j)
                                if (item2->GetSocket(j) != item->GetSocket(j))
                                    break;

                            if (j != ITEM_SOCKET_MAX_NUM)
                                continue;

                            BYTE bCount2 = MIN(200 - item2->GetCount(), bCount);
                            bCount -= bCount2;

                            item2->SetCount(item2->GetCount() + bCount2);
                        }

                    item->SetCount(bCount);

 

 

Think on bool CHARACTER::PickupItem(DWORD dwVID) as you was telling.

Share this post


Link to post
Share on other sites
Acum 1 oră, ReFresh a spus:

@WeedHex Do you know where can I find a buy from shop function? I need to place it here and try it if it work.

shop.cpp - ::Buy

Share this post


Link to post
Share on other sites

Use AutoGiveItem instead of CreateItem & AddToCharacter.

 

Can you post your Buy function from shop.cpp?

Share this post


Link to post
Share on other sites

Here is buy function from shop.cpp:

Spoiler

long long CShop::Buy(LPCHARACTER ch, BYTE pos)
{
	if (pos >= m_itemVector.size())
	{
		sys_log(0, "Shop::Buy : invalid position %d : %s", pos, ch->GetName());
		return SHOP_SUBHEADER_GC_INVALID_POS;
	}
	
	if (IsPCShop() && ch->GetGMLevel() > GM_PLAYER) //BLOCK GM CAN'T BUY FROM PRIVATE SHOPS
	{
		ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Game Master nemuze nakupovat ze soukromeho stanku."));
		return SHOP_SUBHEADER_GC_SOLD_OUT;
	}

	sys_log(0, "Shop::Buy : name %s pos %d", ch->GetName(), pos);

	GuestMapType::iterator it = m_map_guest.find(ch);

	if (it == m_map_guest.end())
		return SHOP_SUBHEADER_GC_END;

	SHOP_ITEM& r_item = m_itemVector[pos];

	if (r_item.price < 0)
	{
		LogManager::instance().HackLog("SHOP_BUY_GOLD_OVERFLOW", ch);
		return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
	}

	LPITEM pkSelectedItem = ITEM_MANAGER::instance().Find(r_item.itemid);

	if (IsPCShop())
	{
		if (!pkSelectedItem)
		{
			sys_log(0, "Shop::Buy : Critical: This user seems to be a hacker : invalid pcshop item : BuyerPID:%d SellerPID:%d",
					ch->GetPlayerID(),
					m_pkPC->GetPlayerID());

			return false;
		}

		if ((pkSelectedItem->GetOwner() != m_pkPC))
		{
			sys_log(0, "Shop::Buy : Critical: This user seems to be a hacker : invalid pcshop item : BuyerPID:%d SellerPID:%d",
					ch->GetPlayerID(),
					m_pkPC->GetPlayerID());

			return false;
		}
	}

	long long dwPrice = r_item.price;

	if (it->second)	// if other empire, price is triple
		dwPrice *= 3;

	if (ch->GetGold() < (long long) dwPrice)
	{
		sys_log(1, "Shop::Buy : Not enough money : %s has %d, price %d", ch->GetName(), ch->GetGold(), dwPrice);
		return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
	}

	LPITEM item;

	if (m_pkPC) // ÇÇľľ°ˇ żîżµÇĎ´Â ĽĄŔş ÇÇľľ°ˇ ˝ÇÁ¦ ľĆŔĚĹŰŔ» °ˇÁö°íŔÖľîľß ÇŃ´Ů.
		item = r_item.pkItem;
	else
		item = ITEM_MANAGER::instance().CreateItem(r_item.vnum, r_item.count);

	if (!item)
		return SHOP_SUBHEADER_GC_SOLD_OUT;

	if (!m_pkPC)
	{
		//START OF NONTRADABLE MARBLE
		/*if (quest::CQuestManager::instance().GetEventFlag("hivalue_item_sell") == 0)
		{
			//ĂŕşąŔÇ ±¸˝˝ && ¸¸łâÇŃö ŔĚşĄĆ® 
			if (item->GetVnum() == 70024 || item->GetVnum() == 70035)
			{
				return SHOP_SUBHEADER_GC_END;
			}
		}*/
		//END OF NONTRADABLE MARBLE
	}

	int iEmptyPos;
	if (item->IsDragonSoul())
	{
		iEmptyPos = ch->GetEmptyDragonSoulInventory(item);
	}
	else
	{
		iEmptyPos = ch->GetEmptyInventory(item->GetSize());
	}

	if (iEmptyPos < 0)
	{
		if (m_pkPC)
		{
			sys_log(1, "Shop::Buy at PC Shop : Inventory full : %s size %d", ch->GetName(), item->GetSize());
			return SHOP_SUBHEADER_GC_INVENTORY_FULL;
		}
		else
		{
			sys_log(1, "Shop::Buy : Inventory full : %s size %d", ch->GetName(), item->GetSize());
			M2_DESTROY_ITEM(item);
			return SHOP_SUBHEADER_GC_INVENTORY_FULL;
		}
	}

	ch->PointChange(POINT_GOLD, -dwPrice, false);

	//ĽĽ±Ý °č»ę
	DWORD dwTax = 0;
	int iVal = 0;

	if (LC_IsYMIR() ||  LC_IsKorea())
	{
		if (0 < (iVal = quest::CQuestManager::instance().GetEventFlag("trade_tax")))
		{
			if (iVal > 100)
				iVal = 100;

			dwTax = dwPrice * iVal / 100;
			dwPrice = dwPrice - dwTax;
		}
		else
		{
			iVal = 3;
			dwTax = dwPrice * iVal / 100;
			dwPrice = dwPrice - dwTax;			
		}
	}
	else
	{
		iVal = quest::CQuestManager::instance().GetEventFlag("personal_shop");

		if (0 < iVal)
		{
			if (iVal > 100)
				iVal = 100;

			dwTax = dwPrice * iVal / 100;
			dwPrice = dwPrice - dwTax;
		}
		else
		{
			iVal = 0;
			dwTax = 0;
		}
	}

	// »óÁˇżˇĽ­ »ě‹š ĽĽ±Ý 5%
	if (!m_pkPC) 
	{
		CMonarch::instance().SendtoDBAddMoney(dwTax, ch->GetEmpire(), ch);
	}

	// ±şÁÖ ˝Ă˝şĹŰ : ĽĽ±Ý ¡Ľö
	if (m_pkPC)
	{
		m_pkPC->SyncQuickslot(QUICKSLOT_TYPE_ITEM, item->GetCell(), 255);

		if (item->GetVnum() == 90008 || item->GetVnum() == 90009) // VCARD
		{
			VCardUse(m_pkPC, ch, item);
			item = NULL;
		}
		else
		{
			char buf[512];

			if (item->GetVnum() >= 80003 && item->GetVnum() <= 80007)
			{
				snprintf(buf, sizeof(buf), "%s FROM: %u TO: %u PRICE: %lld", item->GetName(), ch->GetPlayerID(), m_pkPC->GetPlayerID(), dwPrice);
				LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), SHOP_BUY, buf);
				LogManager::instance().GoldBarLog(m_pkPC->GetPlayerID(), item->GetID(), SHOP_SELL, buf);
			}
			
			item->RemoveFromCharacter();
			if (item->IsDragonSoul())
				item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
			else
				item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
			ITEM_MANAGER::instance().FlushDelayedSave(item);
			

			snprintf(buf, sizeof(buf), "%s %u(%s) %lld %u", item->GetName(), m_pkPC->GetPlayerID(), m_pkPC->GetName(), dwPrice, item->GetCount());
			LogManager::instance().ItemLog(ch, item, "SHOP_BUY", buf);

			snprintf(buf, sizeof(buf), "%s %u(%s) %lld %u", item->GetName(), ch->GetPlayerID(), ch->GetName(), dwPrice, item->GetCount());
			LogManager::instance().ItemLog(m_pkPC, item, "SHOP_SELL", buf);
		}

		r_item.pkItem = NULL;
		BroadcastUpdateItem(pos);

		m_pkPC->PointChange(POINT_GOLD, dwPrice, false);

		if (iVal > 0)
			m_pkPC->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ĆǸűݾ×ŔÇ %d %% °ˇ ĽĽ±ÝŔ¸·Î łŞ°ˇ°ÔµË´Ď´Ů"), iVal);

		CMonarch::instance().SendtoDBAddMoney(dwTax, m_pkPC->GetEmpire(), m_pkPC);
	}
	else
	{
		if (item->IsDragonSoul())
			item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
		else
			item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
		ITEM_MANAGER::instance().FlushDelayedSave(item);
		LogManager::instance().ItemLog(ch, item, "BUY", item->GetName());

		if (item->GetVnum() >= 80003 && item->GetVnum() <= 80007)
		{
			LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), PERSONAL_SHOP_BUY, "");
		}

		DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), -dwPrice);
	}

	if (item)
		sys_log(0, "SHOP: BUY: name %s %s(x %d):%u price %lld", ch->GetName(), item->GetName(), item->GetCount(), item->GetID(), dwPrice);

    ch->Save();

    return (SHOP_SUBHEADER_GC_OK);
}

 

 

Share this post


Link to post
Share on other sites

long long CShop::Buy(LPCHARACTER ch, BYTE pos)
{
    if (pos >= m_itemVector.size())
    {
        sys_log(0, "Shop::Buy : invalid position %d : %s", pos, ch->GetName());
        return SHOP_SUBHEADER_GC_INVALID_POS;
    }
    
    if (IsPCShop() && ch->GetGMLevel() > GM_PLAYER) //BLOCK GM CAN'T BUY FROM PRIVATE SHOPS
    {
        ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Game Master nemuze nakupovat ze soukromeho stanku."));
        return SHOP_SUBHEADER_GC_SOLD_OUT;
    }

    sys_log(0, "Shop::Buy : name %s pos %d", ch->GetName(), pos);

    GuestMapType::iterator it = m_map_guest.find(ch);

    if (it == m_map_guest.end())
        return SHOP_SUBHEADER_GC_END;

    SHOP_ITEM& r_item = m_itemVector[pos];

    if (r_item.price < 0)
    {
        LogManager::instance().HackLog("SHOP_BUY_GOLD_OVERFLOW", ch);
        return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
    }

    LPITEM pkSelectedItem = ITEM_MANAGER::instance().Find(r_item.itemid);

    if (IsPCShop())
    {
        if (!pkSelectedItem)
        {
            sys_log(0, "Shop::Buy : Critical: This user seems to be a hacker : invalid pcshop item : BuyerPID:%d SellerPID:%d",
                    ch->GetPlayerID(),
                    m_pkPC->GetPlayerID());

            return false;
        }

        if ((pkSelectedItem->GetOwner() != m_pkPC))
        {
            sys_log(0, "Shop::Buy : Critical: This user seems to be a hacker : invalid pcshop item : BuyerPID:%d SellerPID:%d",
                    ch->GetPlayerID(),
                    m_pkPC->GetPlayerID());

            return false;
        }
    }

    long long dwPrice = r_item.price;

    if (it->second)    // if other empire, price is triple
        dwPrice *= 3;

    if (ch->GetGold() < (long long) dwPrice)
    {
        sys_log(1, "Shop::Buy : Not enough money : %s has %d, price %d", ch->GetName(), ch->GetGold(), dwPrice);
        return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
    }

    LPITEM item;

    if (m_pkPC) // ÇÇľľ°ˇ żîżµÇĎ´Â ĽĄŔş ÇÇľľ°ˇ ˝ÇÁ¦ ľĆŔĚĹŰŔ» °ˇÁö°íŔÖľîľß ÇŃ´Ů.
        item = r_item.pkItem;
    else
        item = ITEM_MANAGER::instance().CreateItem(r_item.vnum, r_item.count);

    if (!item)
        return SHOP_SUBHEADER_GC_SOLD_OUT;

    if (!m_pkPC)
    {
        //START OF NONTRADABLE MARBLE
        /*if (quest::CQuestManager::instance().GetEventFlag("hivalue_item_sell") == 0)
        {
            //ĂŕşąŔÇ ±¸˝˝ && ¸¸łâÇŃö ŔĚşĄĆ® 
            if (item->GetVnum() == 70024 || item->GetVnum() == 70035)
            {
                return SHOP_SUBHEADER_GC_END;
            }
        }*/
        //END OF NONTRADABLE MARBLE
    }

    int iEmptyPos;
    if (item->IsDragonSoul())
    {
        iEmptyPos = ch->GetEmptyDragonSoulInventory(item);
    }
    else
    {
        iEmptyPos = ch->GetEmptyInventory(item->GetSize());
    }

    if (iEmptyPos < 0)
    {
        if (m_pkPC)
        {
            sys_log(1, "Shop::Buy at PC Shop : Inventory full : %s size %d", ch->GetName(), item->GetSize());
            return SHOP_SUBHEADER_GC_INVENTORY_FULL;
        }
        else
        {
            sys_log(1, "Shop::Buy : Inventory full : %s size %d", ch->GetName(), item->GetSize());
            M2_DESTROY_ITEM(item);
            return SHOP_SUBHEADER_GC_INVENTORY_FULL;
        }
    }

    ch->PointChange(POINT_GOLD, -dwPrice, false);

    //ĽĽ±Ý °č»ę
    DWORD dwTax = 0;
    int iVal = 0;

    if (LC_IsYMIR() ||  LC_IsKorea())
    {
        if (0 < (iVal = quest::CQuestManager::instance().GetEventFlag("trade_tax")))
        {
            if (iVal > 100)
                iVal = 100;

            dwTax = dwPrice * iVal / 100;
            dwPrice = dwPrice - dwTax;
        }
        else
        {
            iVal = 3;
            dwTax = dwPrice * iVal / 100;
            dwPrice = dwPrice - dwTax;            
        }
    }
    else
    {
        iVal = quest::CQuestManager::instance().GetEventFlag("personal_shop");

        if (0 < iVal)
        {
            if (iVal > 100)
                iVal = 100;

            dwTax = dwPrice * iVal / 100;
            dwPrice = dwPrice - dwTax;
        }
        else
        {
            iVal = 0;
            dwTax = 0;
        }
    }

    // »óÁˇżˇĽ­ »ě‹š ĽĽ±Ý 5%
    if (!m_pkPC) 
    {
        CMonarch::instance().SendtoDBAddMoney(dwTax, ch->GetEmpire(), ch);
    }

    // ±şÁÖ ˝Ă˝şĹŰ : ĽĽ±Ý ¡Ľö
    if (m_pkPC)
    {
        m_pkPC->SyncQuickslot(QUICKSLOT_TYPE_ITEM, item->GetCell(), 255);

        if (item->GetVnum() == 90008 || item->GetVnum() == 90009) // VCARD
        {
            VCardUse(m_pkPC, ch, item);
            item = NULL;
        }
        else
        {
            char buf[512];

            if (item->GetVnum() >= 80003 && item->GetVnum() <= 80007)
            {
                snprintf(buf, sizeof(buf), "%s FROM: %u TO: %u PRICE: %lld", item->GetName(), ch->GetPlayerID(), m_pkPC->GetPlayerID(), dwPrice);
                LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), SHOP_BUY, buf);
                LogManager::instance().GoldBarLog(m_pkPC->GetPlayerID(), item->GetID(), SHOP_SELL, buf);
            }
            
            item->RemoveFromCharacter();
            if (item->IsDragonSoul())
                item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
            else
                item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
            ITEM_MANAGER::instance().FlushDelayedSave(item);
            

            snprintf(buf, sizeof(buf), "%s %u(%s) %lld %u", item->GetName(), m_pkPC->GetPlayerID(), m_pkPC->GetName(), dwPrice, item->GetCount());
            LogManager::instance().ItemLog(ch, item, "SHOP_BUY", buf);

            snprintf(buf, sizeof(buf), "%s %u(%s) %lld %u", item->GetName(), ch->GetPlayerID(), ch->GetName(), dwPrice, item->GetCount());
            LogManager::instance().ItemLog(m_pkPC, item, "SHOP_SELL", buf);
        }

        r_item.pkItem = NULL;
        BroadcastUpdateItem(pos);

        m_pkPC->PointChange(POINT_GOLD, dwPrice, false);

        if (iVal > 0)
            m_pkPC->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ĆǸűݾ×ŔÇ %d %% °ˇ ĽĽ±ÝŔ¸·Î łŞ°ˇ°ÔµË´Ď´Ů"), iVal);

        CMonarch::instance().SendtoDBAddMoney(dwTax, m_pkPC->GetEmpire(), m_pkPC);
    }
    else
    {
        /*
        if (item->IsDragonSoul())
            item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
        else
            item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
        */
        item = ch->AutoGiveItem(item->GetVnum(), item->GetCount());
        ITEM_MANAGER::instance().FlushDelayedSave(item);
        LogManager::instance().ItemLog(ch, item, "BUY", item->GetName());

        if (item->GetVnum() >= 80003 && item->GetVnum() <= 80007)
        {
            LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), PERSONAL_SHOP_BUY, "");
        }

        DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), -dwPrice);
    }

    if (item)
        sys_log(0, "SHOP: BUY: name %s %s(x %d):%u price %lld", ch->GetName(), item->GetName(), item->GetCount(), item->GetID(), dwPrice);

    ch->Save();

    return (SHOP_SUBHEADER_GC_OK);
}

try

  • Thanks 1

Share this post


Link to post
Share on other sites

@Endymion nice, it works but it writing in chat which item I bought, like when you pick up some item, it's so annoying can you remove it? I mean: You recieved red potion... etc.

And it works only when you buying items from npc shop not working when I create shop with player.

Share this post


Link to post
Share on other sites
1 hour ago, ReFresh said:

@Endymion nice, it works but it writing in chat which item I bought, like when you pick up some item, it's so annoying can you remove it? I mean: You recieved red potion... etc.

And it works only when you buying items from npc shop not working when I create shop with player.

Add the autogiveitem in the shopex.cpp too.

Share this post


Link to post
Share on other sites

@Legend Any solution for this must exist because one server have it without the: You recieved.. bla bla

And still need do a stacking items when I buy them from private shop.

Share this post


Link to post
Share on other sites
16 minutes ago, ReFresh said:

@Legend Any solution for this must exist because one server have it without the: You recieved.. bla bla

And still need do a stacking items when I buy them from private shop.

shopEx.cpp


You have received blabla:

Spoiler

 

// Search for:

    LogManager::instance().ItemLog(ch, item, "BUY", item->GetName());

 

// Add under:

    ch->ChatPacket(CHAT_TYPE_INFO, "You have bought: %s for %u yang.", item->GetName(), dwPrice);

 

 

Auto Stack (privateshop):

Spoiler

File: shopEx.cpp 

Search:

    if (item->IsDragonSoul())
        item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
    else
        item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));

Replace with this.

 // if (item->IsDragonSoul())
        // item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
    // else
        // item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
    // AutoGiveItem ( Stack )
    item = ch->AutoGiveItem(item->GetVnum(), item->GetCount());
    // End

 

Share this post


Link to post
Share on other sites

@Legend Thanks gonna to try it and can you tell me how can I delete: You recieved bla bla ... when I buy something from normal npc shop? 

Share this post


Link to post
Share on other sites
14 minutes ago, ReFresh said:

@Legend Thanks gonna to try it and can you tell me how can I delete: You recieved bla bla ... when I buy something from normal npc shop? 

// Remove: You have received blabla. text.

Spoiler

 

Replace::

        item = ch->AutoGiveItem(item->GetVnum(), item->GetCount());

With:

        item = ch->AutoGiveItem(item->GetVnum(), item->GetCount(), -1, false);

 

 

  • Like 1

Share this post


Link to post
Share on other sites

@Legend I need to remove text phrase not the item. When I'm buying items from shops I'm getting these phrases because of autogiveitem:

 

Share this post


Link to post
Share on other sites
1 minute ago, ReFresh said:

@Legend I need to remove text phrase not the item. When I'm buying items from shops I'm getting these phrases because of autogiveitem:

phra.jpg.f7773b0b154ccf1aa0c7a623db29e321.jpg

Can you share your ::autogiveitem function?

Share this post


Link to post
Share on other sites

@Legend

Spoiler

void CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip)
{
	if (NULL == item)
	{
		sys_err ("NULL point.");
		return;
	}
	if (item->GetOwner())
	{
		sys_err ("item %d 's owner exists!",item->GetID());
		return;
	}
	
	int cell;
	if (item->IsDragonSoul())
	{
		cell = GetEmptyDragonSoulInventory(item);
	}
	else
	{
		cell = GetEmptyInventory (item->GetSize());
	}

	if (cell != -1)
	{
		if (item->IsDragonSoul())
			item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, cell));
		else
			item->AddToCharacter(this, TItemPos(INVENTORY, cell));

		LogManager::instance().ItemLog(this, item, "SYSTEM", item->GetName());

		if (item->GetType() == ITEM_USE && item->GetSubType() == USE_POTION)
		{
			TQuickslot * pSlot;

			if (GetQuickslot(0, &pSlot) && pSlot->type == QUICKSLOT_TYPE_NONE)
			{
				TQuickslot slot;
				slot.type = QUICKSLOT_TYPE_ITEM;
				slot.pos = cell;
				SetQuickslot(0, slot);
			}
		}
	}
	else
	{
		item->AddToGround (GetMapIndex(), GetXYZ());
		item->StartDestroyEvent();

		if (longOwnerShip)
			item->SetOwnership (this, 300);
		else
			item->SetOwnership (this, 60);
		LogManager::instance().ItemLog(this, item, "SYSTEM_DROP", item->GetName());
	}
}

LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, BYTE bCount, int iRarePct, bool bMsg)
{
	TItemTable * p = ITEM_MANAGER::instance().GetTable(dwItemVnum);

	if (!p)
		return NULL;

	DBManager::instance().SendMoneyLog(MONEY_LOG_DROP, dwItemVnum, bCount);

	if (p->dwFlags & ITEM_FLAG_STACKABLE && p->bType != ITEM_BLEND) 
	{
		for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
		{
			LPITEM item = GetInventoryItem(i);

			if (!item)
				continue;

			if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item))
			{
				if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT))
				{
					if (bCount < p->alValues[1])
						bCount = p->alValues[1];
				}

				BYTE bCount2 = MIN(200 - item->GetCount(), bCount);
				bCount -= bCount2;

				item->SetCount(item->GetCount() + bCount2);

				if (bCount == 0)
				{
					if (bMsg)
						ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ľĆŔĚĹŰ Čąµć: %s"), item->GetName());

					return item;
				}
			}
		}
	}

	LPITEM item = ITEM_MANAGER::instance().CreateItem(dwItemVnum, bCount, 0, true);

	if (!item)
	{
		sys_err("cannot create item by vnum %u (name: %s)", dwItemVnum, GetName());
		return NULL;
	}

	if (item->GetType() == ITEM_BLEND)
	{
		for (int i=0; i < INVENTORY_MAX_NUM; i++)
		{
			LPITEM inv_item = GetInventoryItem(i);

			if (inv_item == NULL) continue;

			if (inv_item->GetType() == ITEM_BLEND)
			{
				if (inv_item->GetVnum() == item->GetVnum())
				{
					if (inv_item->GetSocket(0) == item->GetSocket(0) &&
							inv_item->GetSocket(1) == item->GetSocket(1) &&
							inv_item->GetSocket(2) == item->GetSocket(2) &&
							inv_item->GetCount() < ITEM_MAX_COUNT)
					{
						inv_item->SetCount(inv_item->GetCount() + item->GetCount());
						return inv_item;
					}
				}
			}
		}
	}

	int iEmptyCell;
	if (item->IsDragonSoul())
	{
		iEmptyCell = GetEmptyDragonSoulInventory(item);
	}
	else
		iEmptyCell = GetEmptyInventory(item->GetSize());

	if (iEmptyCell != -1)
	{
		if (bMsg)
			ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ľĆŔĚĹŰ Čąµć: %s"), item->GetName());

		if (item->IsDragonSoul())
			item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyCell));
		else
			item->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell));
		LogManager::instance().ItemLog(this, item, "SYSTEM", item->GetName());

		if (item->GetType() == ITEM_USE && item->GetSubType() == USE_POTION)
		{
			TQuickslot * pSlot;

			if (GetQuickslot(0, &pSlot) && pSlot->type == QUICKSLOT_TYPE_NONE)
			{
				TQuickslot slot;
				slot.type = QUICKSLOT_TYPE_ITEM;
				slot.pos = iEmptyCell;
				SetQuickslot(0, slot);
			}
		}
	}
	else
	{
		item->AddToGround(GetMapIndex(), GetXYZ());
		item->StartDestroyEvent();
		// ľČĆĽ µĺ¶ř flag°ˇ °É·ÁŔÖ´Â ľĆŔĚĹŰŔÇ °ćżě, 
		// ŔÎşĄżˇ şó °ř°ŁŔĚ ľřľîĽ­ ľîÂż Ľö ľřŔĚ ¶łľîĆ®¸®°Ô µÇ¸é,
		// ownershipŔ» ľĆŔĚĹŰŔĚ »ç¶óÁú ¶§±îÁö(300ĂĘ) ŔŻÁöÇŃ´Ů.
		if (IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_DROP))
			item->SetOwnership(this, 300);
		else
			item->SetOwnership(this, 60);
		LogManager::instance().ItemLog(this, item, "SYSTEM_DROP", item->GetName());
	}

	sys_log(0, 
		"7: %d %d", dwItemVnum, bCount);
	return item;
}

 

 

Share this post


Link to post
Share on other sites
2 minutes ago, ReFresh said:

@Legend

  Reveal hidden contents


void CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip)
{
	if (NULL == item)
	{
		sys_err ("NULL point.");
		return;
	}
	if (item->GetOwner())
	{
		sys_err ("item %d 's owner exists!",item->GetID());
		return;
	}
	
	int cell;
	if (item->IsDragonSoul())
	{
		cell = GetEmptyDragonSoulInventory(item);
	}
	else
	{
		cell = GetEmptyInventory (item->GetSize());
	}

	if (cell != -1)
	{
		if (item->IsDragonSoul())
			item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, cell));
		else
			item->AddToCharacter(this, TItemPos(INVENTORY, cell));

		LogManager::instance().ItemLog(this, item, "SYSTEM", item->GetName());

		if (item->GetType() == ITEM_USE && item->GetSubType() == USE_POTION)
		{
			TQuickslot * pSlot;

			if (GetQuickslot(0, &pSlot) && pSlot->type == QUICKSLOT_TYPE_NONE)
			{
				TQuickslot slot;
				slot.type = QUICKSLOT_TYPE_ITEM;
				slot.pos = cell;
				SetQuickslot(0, slot);
			}
		}
	}
	else
	{
		item->AddToGround (GetMapIndex(), GetXYZ());
		item->StartDestroyEvent();

		if (longOwnerShip)
			item->SetOwnership (this, 300);
		else
			item->SetOwnership (this, 60);
		LogManager::instance().ItemLog(this, item, "SYSTEM_DROP", item->GetName());
	}
}

LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, BYTE bCount, int iRarePct, bool bMsg)
{
	TItemTable * p = ITEM_MANAGER::instance().GetTable(dwItemVnum);

	if (!p)
		return NULL;

	DBManager::instance().SendMoneyLog(MONEY_LOG_DROP, dwItemVnum, bCount);

	if (p->dwFlags & ITEM_FLAG_STACKABLE && p->bType != ITEM_BLEND) 
	{
		for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
		{
			LPITEM item = GetInventoryItem(i);

			if (!item)
				continue;

			if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item))
			{
				if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT))
				{
					if (bCount < p->alValues[1])
						bCount = p->alValues[1];
				}

				BYTE bCount2 = MIN(200 - item->GetCount(), bCount);
				bCount -= bCount2;

				item->SetCount(item->GetCount() + bCount2);

				if (bCount == 0)
				{
					if (bMsg)
						ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ľĆŔĚĹŰ Čąµć: %s"), item->GetName());

					return item;
				}
			}
		}
	}

	LPITEM item = ITEM_MANAGER::instance().CreateItem(dwItemVnum, bCount, 0, true);

	if (!item)
	{
		sys_err("cannot create item by vnum %u (name: %s)", dwItemVnum, GetName());
		return NULL;
	}

	if (item->GetType() == ITEM_BLEND)
	{
		for (int i=0; i < INVENTORY_MAX_NUM; i++)
		{
			LPITEM inv_item = GetInventoryItem(i);

			if (inv_item == NULL) continue;

			if (inv_item->GetType() == ITEM_BLEND)
			{
				if (inv_item->GetVnum() == item->GetVnum())
				{
					if (inv_item->GetSocket(0) == item->GetSocket(0) &&
							inv_item->GetSocket(1) == item->GetSocket(1) &&
							inv_item->GetSocket(2) == item->GetSocket(2) &&
							inv_item->GetCount() < ITEM_MAX_COUNT)
					{
						inv_item->SetCount(inv_item->GetCount() + item->GetCount());
						return inv_item;
					}
				}
			}
		}
	}

	int iEmptyCell;
	if (item->IsDragonSoul())
	{
		iEmptyCell = GetEmptyDragonSoulInventory(item);
	}
	else
		iEmptyCell = GetEmptyInventory(item->GetSize());

	if (iEmptyCell != -1)
	{
		if (bMsg)
			ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ľĆŔĚĹŰ Čąµć: %s"), item->GetName());

		if (item->IsDragonSoul())
			item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyCell));
		else
			item->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell));
		LogManager::instance().ItemLog(this, item, "SYSTEM", item->GetName());

		if (item->GetType() == ITEM_USE && item->GetSubType() == USE_POTION)
		{
			TQuickslot * pSlot;

			if (GetQuickslot(0, &pSlot) && pSlot->type == QUICKSLOT_TYPE_NONE)
			{
				TQuickslot slot;
				slot.type = QUICKSLOT_TYPE_ITEM;
				slot.pos = iEmptyCell;
				SetQuickslot(0, slot);
			}
		}
	}
	else
	{
		item->AddToGround(GetMapIndex(), GetXYZ());
		item->StartDestroyEvent();
		// ľČĆĽ µĺ¶ř flag°ˇ °É·ÁŔÖ´Â ľĆŔĚĹŰŔÇ °ćżě, 
		// ŔÎşĄżˇ şó °ř°ŁŔĚ ľřľîĽ­ ľîÂż Ľö ľřŔĚ ¶łľîĆ®¸®°Ô µÇ¸é,
		// ownershipŔ» ľĆŔĚĹŰŔĚ »ç¶óÁú ¶§±îÁö(300ĂĘ) ŔŻÁöÇŃ´Ů.
		if (IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_DROP))
			item->SetOwnership(this, 300);
		else
			item->SetOwnership(this, 60);
		LogManager::instance().ItemLog(this, item, "SYSTEM_DROP", item->GetName());
	}

	sys_log(0, 
		"7: %d %d", dwItemVnum, bCount);
	return item;
}

 

 

 

The text phrase is not coming from the autogiveitem function as i can see. please find from where is comes and let me know.

Share this post


Link to post
Share on other sites

@Legend Auto stacking don't work when I buy something from privateshop

Spoiler

 

 // if (item->IsDragonSoul())
        // item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
    // else
        // item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
    // AutoGiveItem ( Stack )
    item = ch->AutoGiveItem(item->GetVnum(), item->GetCount());
    // End

    ITEM_MANAGER::instance().FlushDelayedSave(item);
    LogManager::instance().ItemLog(ch, item, "BUY", item->GetName());
    ch->ChatPacket(CHAT_TYPE_INFO, "You bought: %s for %u yang.", item->GetName(), dwPrice);

 

 

Share this post


Link to post
Share on other sites

System still don't work when I buy something from player private shop.

@Legend Can you fix it?

 

Can someone fix it for privateshop buying and for warp scrolls when they have the same coordinates?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×