Jump to content

Recommended Posts

  • Active+ Member

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

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/
Share on other sites

  • Premium

                        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.

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99109
Share on other sites

  • Active+ Member

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);
}

 

 

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99396
Share on other sites

  • Active Member

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

  • Love 1
Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99441
Share on other sites

  • Active+ Member

@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.

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99442
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.

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99448
Share on other sites

  • Active+ Member

@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.

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99449
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

 

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99453
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);

 

 

  • Love 1
Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99459
Share on other sites

  • Active+ Member

@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;
}

 

 

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99464
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.

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99465
Share on other sites

  • Active+ Member

@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);

 

 

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99466
Share on other sites

  • Active+ Member

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?

I'll be always helpful!  😉

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-99511
Share on other sites

  • 6 years later...

Hey does anyone know where would be problem? I buy item from shop  like 20potions, it stacks to the other potions but also made a new stack of 20potions? So it actually buys 40potions for the price of 20. 20 potions stacks into old stack and also create whole new stack? Thanks

Link to comment
https://metin2.dev/topic/18137-feature-enhancement/#findComment-165821
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • 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.