Jump to content

Fix Koray Offline Shop - Item Disappear when you Close the Shop


Recommended Posts

  • Bot

In the koray offline shop (a good offline shop), there is a big problem, when you close the shop, items not sold disappear!

I'm there to give you the fix for this problem:

Open the shop.cpp and search the function CShop::Remove(),

change your function with this:

void CShop::Remove()
{
	if (!HasOwner())
		return;

	m_bIsLocked = true;

	TOfflineShopTable p;
	memset(&p, 0, sizeof(p));

	p.dwAID = m_dwOwnerAID;
	p.dwPID = m_dwOwnerPID;

  	LPCHARACTER ch=CHARACTER_MANAGER::instance().FindByPID(m_dwOwnerPID);
  
	p.dwX = m_pkPC->GetX();
	p.dwY = m_pkPC->GetY();
	p.dwMapIndex = m_pkPC->GetMapIndex();

	p.dwChannel = g_bChannel;

	p.ullMoney = m_Money;
	p.dwSize = m_bSize;
	p.dwColor = m_bColor;

	strlcpy(p.szSign, m_pkPC->GetShopSign().c_str(), sizeof(p.szSign));

	for (DWORD i = 0; i < m_itemVector.size() && i < SHOP_HOST_ITEM_MAX_NUM; ++i)
	{
		SHOP_ITEM& item = m_itemVector[i];

		if (item.pkItem == NULL)
			continue;

		p.items2[i] = item.itemid;
		p.price[i] = item.price;
		LPITEM item2=item.pkItem;
		
		if (item.isSold != 1) {
          
			if (ch == NULL) {
				sys_err("[OfflineShop] Shop owner was offline, i'm sending the items into the mall...\n");
				char query_pos[1025];
				snprintf(query_pos, sizeof(query_pos), "SELECT pos FROM player.item%s WHERE window='MALL' AND owner_id=%d;", get_table_postfix(), m_dwOwnerAID);
				SQLMsg * pMsg = DBManager::instance().DirectQuery(query_pos);
				if (pMsg != NULL) {
					
					int pos=0;
					
					if (pMsg->Get()->uiNumRows > 0) {
						MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
						str_to_number(pos, row[0]);
						pos+=1;
					}
					
					int random_id=number(1,999999999)+m_dwOwnerPID+number(1,50);
					int socket1=(int)item2->GetSocket(0);
					int socket2=(int)item2->GetSocket(1);
					int socket3=(int)item2->GetSocket(2);
					int applytype0=(int)item2->GetAttributeType(0);
					int applyvalue0=(int)item2->GetAttributeValue(0);
					int applytype1=(int)item2->GetAttributeType(1);
					int applyvalue1=(int)item2->GetAttributeValue(1);
					int applytype2=(int)item2->GetAttributeType(2);
					int applyvalue2=(int)item2->GetAttributeValue(2);
					int applytype3=(int)item2->GetAttributeType(3);
					int applyvalue3=(int)item2->GetAttributeValue(3);
					int applytype4=(int)item2->GetAttributeType(4);
					int applyvalue4=(int)item2->GetAttributeValue(4);
					int applytype5=(int)item2->GetAttributeType(5);
					int applyvalue5=(int)item2->GetAttributeValue(5);
					int applytype6=(int)item2->GetAttributeType(6);
					int applyvalue6=(int)item2->GetAttributeValue(6);
					
					char query[1025];
					sprintf(
					query, //     TABLE POSTFIX  RANDOM-ID - AID - WINDOW  - POS - COUNT - VNUM - S1 - S2 - S3                 -  B1    B1    B2    B2    B3    B3    B4    B4    B5    B5    B6    B6    B7    B7
					"INSERT INTO player.item%s VALUES ('%d', '%d', 'MALL', '%d', '%d', '%d', '%d', '%d', '%d', '0', '0', '0', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d');",
					get_table_postfix(),
					random_id,
					(int)m_dwOwnerAID,
					pos,
					(int)item.count,
					(int)item.vnum,
					socket1,
					socket2,
					socket3,
					applytype0,
					applyvalue0,
					applytype1,
					applyvalue1,
					applytype2,
					applyvalue2,
					applytype3,
					applyvalue3,
					applytype4,
					applyvalue4,
					applytype5,
					applyvalue5,
					applytype6,
					applyvalue6
					);
					std::auto_ptr<SQLMsg> ripristina(DBManager::instance().DirectQuery(query));
					if (ripristina->Get()->uiAffectedRows > 0) sys_err("[OfflineShop] Done, Now items of the ID: %d are in the mall!\nQUERY: %s\n", m_dwOwnerAID, query);
				}else{
					sys_err("[OfflineShop] Error while trying to get position.\n");
				}
			
			}else{
		
				LPITEM item3 = ITEM_MANAGER::instance().CreateItem(item2->GetVnum(), 1, 0, false);
				ITEM_MANAGER::CopyAllAttrTo(item2, item3);
				int Slot=ch->GetEmptyInventory(item2->GetSize());
				item3->AddToCharacter(ch, TItemPos(INVENTORY, Slot)); 
				ITEM_MANAGER::instance().FlushDelayedSave(item3);
				item3->AttrLog();
			
			}
		
		}else{

			item.pkItem->SetSkipSave(true);
			M2_DESTROY_ITEM(item.pkItem);
			memset(&item, 0, sizeof(item));
		
		}
		
	}

	db_clientdesc->DBPacket(HEADER_GD_OFFLINE_SHOP_REMOVE, 0, &p, sizeof(p));
}

 

english_banner.gif

Link to comment
Share on other sites

actually they don't disappear at all but they disappear because you have no idea about the system :)

Not sold items go to a safebox called (SAFEBOX_OFFLINE_SHOP) should be added there and that safebox will hold them there until you click on the button in the safebox window "restore items". although there is a position problem with it but it works fine.

for me it works like that.

  • Love 1
Link to comment
Share on other sites

  • Bot
3 minutes ago, metin2team said:

actually they don't disappear at all but they disappear because you have no idea about the system :)

Not sold items go to a safebox called (SAFEBOX_OFFLINE_SHOP) should be added there and that safebox will hold them there until you click on the button in the safebox window "restore items". although there is a position problem with it but it works fine.

for me it works like that.

Exactly but a lot of server haven't got the SAFEBOX OFFLINE SHOP!

english_banner.gif

Link to comment
Share on other sites

you're retarded bro ..

 

please don't use his code because if the player is not online he won't get any items ...

void CShop::Remove()
{
	if (!HasOwner())
		return;

	m_bIsLocked = true;

	TOfflineShopTable p;
	memset(&p, 0, sizeof(p));

	p.dwAID = m_dwOwnerAID;
	p.dwPID = m_dwOwnerPID;

	p.dwX = m_pkPC->GetX();
	p.dwY = m_pkPC->GetY();
	p.dwMapIndex = m_pkPC->GetMapIndex();

	p.dwChannel = g_bChannel;

	p.ullMoney = m_Money;
	p.dwSize = m_bSize;
	p.dwColor = m_bColor;

	strlcpy(p.szSign, m_pkPC->GetShopSign().c_str(), sizeof(p.szSign));

	for (DWORD i = 0; i < m_itemVector.size() && i < SHOP_HOST_ITEM_MAX_NUM; ++i)
	{
		SHOP_ITEM& item = m_itemVector[i];

		if (item.pkItem == NULL)
			continue;

		p.items2[i] = item.itemid;
		p.price[i] = item.price;
		
		LPITEM item2=item.pkItem;
		
		if (item.isSold != 1) {
          
          		LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(m_dwOwnerPID);
			LPITEM item3 = ITEM_MANAGER::instance().CreateItem(item2->GetVnum(), 1, 0, false);
			ITEM_MANAGER::CopyAllAttrTo(item2, item3);
			int Slot=ch->GetEmptyInventory(item2->GetSize());
			item3->AddToCharacter(ch, TItemPos(INVENTORY, Slot)); 
			ITEM_MANAGER::instance().FlushDelayedSave(item3);
			item3->AttrLog();
		
		}else{

			item.pkItem->SetWindow(SAFEBOX_OFFLINE_SHOP);
			
			ITEM_MANAGER::instance().SaveSingleItem(item.pkItem);

			item.pkItem->SetSkipSave(true);
			M2_DESTROY_ITEM(item.pkItem);

			memset(&item, 0, sizeof(item));
		
		}
		
	}

	db_clientdesc->DBPacket(HEADER_GD_OFFLINE_SHOP_REMOVE, 0, &p, sizeof(p));
}

what if this (LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(m_dwOwnerPID);) returns null  (an offline player) and the shop's time is up.

what's going to happen?

the SAFEBOX_OFFLINE_SHOP is just an item in the item.window enum so you've implemented the whole thing and can't add a new line to the enum? wtf is wrong with you?!

Link to comment
Share on other sites

  • Bot
On 22/6/2017 at 10:23 PM, akroma said:

Hey guys can you release korays shop?

 

The koray shop is in free download and it's easy to find it on the web:

This is the hidden content, please

Here is the offline shop by koray, my advice is check your files with these files (Folder: ready made files) with WinMerge.

 

  • Metin2 Dev 10
  • Good 3
  • Love 1
  • Love 4

english_banner.gif

Link to comment
Share on other sites

Announcements



×
×
  • 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.