[MINI] Button for sort of Inventory

05/25/2017 00:13 xP3NG3Rx#1
Hello,

I saw a new custome "system" by name Sort, which is resorting the whole inventory, and I made a little button for it from the standard metin2 interface files. I think I saw this on Rubinum and Shiro3 with an ugly icon :awesome:
[Only registered and activated users can see links. Click Here To Register...]

[Only registered and activated users can see links. Click Here To Register...]

I think no need to explain how to implement it.
05/25/2017 06:16 EULOG1SON#2
nice

you can make the code? the part which is sorting your inventory with /sort_inventory command
05/25/2017 12:05 I´m Raylee#3
Nice work dude...
05/25/2017 12:55 BizepsSupportAccount#4
Nettes release, wird der Source Part nicht releast?
05/26/2017 23:40 xP3NG3Rx#5
The sorting function is on my TODO list only, I didn't start to code yet.
05/28/2017 12:01 BizepsSupportAccount#6
Quote:
Originally Posted by xP3NG3Rx View Post
The sorting function is on my TODO list only, I didn't start to code yet.
'd be amazing if you code & release it.
05/31/2017 08:41 EULOG1SON#7
You can coding the sorting function are you sure?
06/04/2017 01:37 .Alpha.#8
Code:
ACMD(do_sort_inventory)
{
	std::vector<CItem*> collectItems;
	std::vector<WORD> oldCells;
	int totalSize = 0;
	for (auto i = 0; i < INVENTORY_MAX_COUNT; ++i) {
		auto item = ch->GetInventoryItem(i);
		if (item) {
			totalSize += item->GetSize();
			oldCells.push_back(item->GetCell());
			collectItems.push_back(item);
		}
	}
	if (totalSize - 3 >= INVENTORY_MAX_COUNT) {
		ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("INVENTORY_FULL_CANNOT_SORT"));
		return;
	}

	for (auto& item : collectItems) {
		item->RemoveFromCharacter();
	}

	std::sort(collectItems.begin(), collectItems.end(),
	          []( CItem* a,  CItem* b) {
		          return a->GetVnum() < b->GetVnum();
	          });

	for (auto& sortedItem : collectItems) {
		auto cell = ch->GetEmptyInventory(sortedItem->GetSize());
		sortedItem->AddToCharacter(ch, TItemPos(INVENTORY, cell), false);
	}
}
Not the best but should work, could not work possibly im pretty drunk right now
06/04/2017 02:41 DasSchwarzeT#9
Quote:
Originally Posted by .Alpha. View Post
im pretty drunk right now
+1
06/07/2017 02:04 LordMG#10
Quote:
Originally Posted by .Alpha. View Post
Code:
ACMD(do_sort_inventory)
{
	std::vector<CItem*> collectItems;
	std::vector<WORD> oldCells;
	int totalSize = 0;
	for (auto i = 0; i < INVENTORY_MAX_COUNT; ++i) {
		auto item = ch->GetInventoryItem(i);
		if (item) {
			totalSize += item->GetSize();
			oldCells.push_back(item->GetCell());
			collectItems.push_back(item);
		}
	}
	if (totalSize - 3 >= INVENTORY_MAX_COUNT) {
		ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("INVENTORY_FULL_CANNOT_SORT"));
		return;
	}

	for (auto& item : collectItems) {
		item->RemoveFromCharacter();
	}

	std::sort(collectItems.begin(), collectItems.end(),
	          []( CItem* a,  CItem* b) {
		          return a->GetVnum() < b->GetVnum();
	          });

	for (auto& sortedItem : collectItems) {
		auto cell = ch->GetEmptyInventory(sortedItem->GetSize());
		sortedItem->AddToCharacter(ch, TItemPos(INVENTORY, cell), false);
	}
}
Not the best but should work, could not work possibly im pretty drunk right now
Works pretty well. Thanks. And thanks to penger too.
06/08/2017 19:56 EULOG1SON#11
can you do also a autostack function?
03/02/2024 16:46 cherezcl#12
Hi, could anyone help me implement this function within my metin please?