Jump to content

[ 40k ] Items by right-clicking from stock to inventory


Recommended Posts

 

Hello everybody!

Is the function already public ?

1 ) How to DE I would like to move on my server items from the stock (warehouse) with RIGHT CLICK the mouse in my inventory .

2 ) Is it tolls. also possible to implement this reversed so that items are if you have the stock open transferred by right-clicking into the camp ? ( Which has not DE I know )

Would be great someone had ne instructions would need for changes in the source so that 1 ) and / or even including 2 ) works .

 

thank you in advance

Link to comment
Share on other sites

  • Honorable Member

This and this, oh and brain.exe:

#[...]
import item
#[...]
class SafeboxWindow(ui.ScriptWindow):
#[...]
	def GetEmptyItemPos(self, itemHeight):
		#DaRealFreak is freak :o ;)
		inventory_size = player.INVENTORY_PAGE_SIZE * player.INVENTORY_PAGE_COUNT 
		# function to return the blocked slots based on the item size 
		GetBlockedSlots = lambda slot, size: [slot+(round*5) for round in xrange(size)] 
		# check if an item in on the slot and get the blocked slots, in the end chain all of our lists together 
		blocked_slots = [element for sublist in [GetBlockedSlots(slot, item.GetItemSize(item.SelectItem(player.GetItemIndex(slot)))[1]) for slot in xrange(inventory_size) if player.isItem(slot)] for element in sublist] 
		# check is only necessary if our item size is > 1, else bigger performance loss in list comprehension 
		if itemHeight > 1: 
			# add the slots where f.e. size 2 items won't fit because of the 2-page-separated inventory 
			[[blocked_slots.append(slot) for slot in range(inventory_size/round-(itemHeight-1)*5, inventory_size/round) if not slot in blocked_slots] for round in xrange(1,3)] 
		# check for every slot if it's not in the blocked_slots list and check also for the size the lower slots  
		free_slots = [slot for slot in xrange(inventory_size) if not slot in blocked_slots and not True in [e in blocked_slots for e in [slot+(round*5) for round in xrange(itemHeight)]]] 
		# if our free_slot list is empty return -1 as error code, else return the first possible slot 
		return [free_slots, -1][len(free_slots) == 0]

	def UseItemSlot(self, slotIndex):
		if mouseModule.mouseController.isAttached():
			mouseModule.mouseController.DeattachObject()

		item.SelectItem(safebox.GetItemID(self.__LocalPosToGlobalPos(slotIndex)))

		(w, h) = item.GetItemSize()
		emptyInvenSlots = self.GetEmptyItemPos(h)
		if emptyInvenSlots == -1:
			return

		net.SendSafeboxCheckoutPacket(slotIndex, emptyInvenSlots[0])
#[...]

 

Edit: Tested, and works.
There is a little mistake, when you log into your account, and open safebox than "checkout" some items, those items will new items, I mean the slots will be activated, because of this:

void CInputMain::SafeboxCheckout(LPCHARACTER ch, const char * c_pData, bool bMall)
{
//[...]
		pkSafebox->Remove(p->bSafePos);
		pkItem->SetLastOwnerPID(ch->GetPlayerID()); #fixme slothighlight
		pkItem->AddToCharacter(ch, p->ItemPos);
		ITEM_MANAGER::instance().FlushDelayedSave(pkItem);
//[...]
}

https://www.youtube.com/watch?v=k7oYpzP2tUc
 

For that you can put items into safebox by clicks you have to check that safebox is opened or not, and rewrite/modify the useslot function in uiInventory.py(InventoryWindow class)

Edited by xP3NG3Rx
fix4work | changed global slot from local slot to works on every page
  • Metin2 Dev 1
  • Good 1
  • Love 8
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...
  • Bronze

Other kind of implementation, looking less complicated. Might be useful understanding xP3NG3Rx`s code basing on list`s comprehension:

	def	GetEmptyGridSlot(self, size):
		SIZE_X = 5
		SITE_MAX_NUM = 5
		RET_SLOT = -1

		## Setting up grid
		mtrx = {i : False for i in xrange(player.INVENTORY_PAGE_SIZE*SITE_MAX_NUM)}
		for i in xrange(player.INVENTORY_PAGE_SIZE*SITE_MAX_NUM):
			if player.GetItemCount(i) != 0 and mtrx[i] == False:

				## Checking grid`s item size if exists
				item.SelectItem(player.GetItemIndex(i))
				(trash, size_y) = item.GetItemSize()

				## 'Disabling' grid slot if there is an item
				for x in xrange(size_y):
					mtrx[i+(SIZE_X*x)] = True

		## Looking for empty slot considering item`s size
		for i in xrange(player.INVENTORY_PAGE_SIZE*SITE_MAX_NUM):
			RET_SLOT = i
			for a in xrange(size):
				if mtrx[i+(SIZE_X*a)] != False:
					RET_SLOT = -1
					break

			if RET_SLOT != -1:
				break

		return RET_SLOT

 

  • Love 1
Link to comment
Share on other sites

  • 1 year later...
Dnia 17.07.2016 o 02:23, xP3NG3Rx napisał:

This and this, oh and brain.exe:


#[...]
import item
#[...]
class SafeboxWindow(ui.ScriptWindow):
#[...]
	def GetEmptyItemPos(self, itemHeight):
		#DaRealFreak is freak :o ;)
		inventory_size = player.INVENTORY_PAGE_SIZE * player.INVENTORY_PAGE_COUNT 
		# function to return the blocked slots based on the item size 
		GetBlockedSlots = lambda slot, size: [slot+(round*5) for round in xrange(size)] 
		# check if an item in on the slot and get the blocked slots, in the end chain all of our lists together 
		blocked_slots = [element for sublist in [GetBlockedSlots(slot, item.GetItemSize(item.SelectItem(player.GetItemIndex(slot)))[1]) for slot in xrange(inventory_size) if player.isItem(slot)] for element in sublist] 
		# check is only necessary if our item size is > 1, else bigger performance loss in list comprehension 
		if itemHeight > 1: 
			# add the slots where f.e. size 2 items won't fit because of the 2-page-separated inventory 
			[[blocked_slots.append(slot) for slot in range(inventory_size/round-(itemHeight-1)*5, inventory_size/round) if not slot in blocked_slots] for round in xrange(1,3)] 
		# check for every slot if it's not in the blocked_slots list and check also for the size the lower slots  
		free_slots = [slot for slot in xrange(inventory_size) if not slot in blocked_slots and not True in [e in blocked_slots for e in [slot+(round*5) for round in xrange(itemHeight)]]] 
		# if our free_slot list is empty return -1 as error code, else return the first possible slot 
		return [free_slots, -1][len(free_slots) == 0]

	def UseItemSlot(self, slotIndex):
		if mouseModule.mouseController.isAttached():
			mouseModule.mouseController.DeattachObject()

		item.SelectItem(safebox.GetItemID(self.__LocalPosToGlobalPos(slotIndex)))

		(w, h) = item.GetItemSize()
		emptyInvenSlots = self.GetEmptyItemPos(h)
		if emptyInvenSlots == -1:
			return

		net.SendSafeboxCheckoutPacket(slotIndex, emptyInvenSlots[0])
#[...]

 

Edit: Tested, and works.
There is a little mistake, when you log into your account, and open safebox than "checkout" some items, those items will new items, I mean the slots will be activated, because of this:


void CInputMain::SafeboxCheckout(LPCHARACTER ch, const char * c_pData, bool bMall)
{
//[...]
		pkSafebox->Remove(p->bSafePos);
		pkItem->SetLastOwnerPID(ch->GetPlayerID()); #fixme slothighlight
		pkItem->AddToCharacter(ch, p->ItemPos);
		ITEM_MANAGER::instance().FlushDelayedSave(pkItem);
//[...]
}

https://www.youtube.com/watch?v=k7oYpzP2tUc
 

For that you can put items into safebox by clicks you have to check that safebox is opened or not, and rewrite/modify the useslot function in uiInventory.py(InventoryWindow class)

 

Dnia 5.03.2018 o 00:51, Sherer napisał:

Other kind of implementation, looking less complicated. Might be useful understanding xP3NG3Rx`s code basing on list`s comprehension: 


	def	GetEmptyGridSlot(self, size):
		SIZE_X = 5
		SITE_MAX_NUM = 5
		RET_SLOT = -1

		## Setting up grid
		mtrx = {i : False for i in xrange(player.INVENTORY_PAGE_SIZE*SITE_MAX_NUM)}
		for i in xrange(player.INVENTORY_PAGE_SIZE*SITE_MAX_NUM):
			if player.GetItemCount(i) != 0 and mtrx[i] == False:

				## Checking grid`s item size if exists
				item.SelectItem(player.GetItemIndex(i))
				(trash, size_y) = item.GetItemSize()

				## 'Disabling' grid slot if there is an item
				for x in xrange(size_y):
					mtrx[i+(SIZE_X*x)] = True

		## Looking for empty slot considering item`s size
		for i in xrange(player.INVENTORY_PAGE_SIZE*SITE_MAX_NUM):
			RET_SLOT = i
			for a in xrange(size):
				if mtrx[i+(SIZE_X*a)] != False:
					RET_SLOT = -1
					break

			if RET_SLOT != -1:
				break

		return RET_SLOT

 

@xP3NG3Rx

@Sherer

The problem with your codes is as follows: When a player on e.g. the first page has at least one free slot, an item with the size "2" will not be moved to e.g. the other side until this one free slot on this first page is moved, an item with "2" in this case will be moved to the next page. For everything to work as it should be created an element that will check the actual size of the item that it moves, and then check the number of free slots (x) on one of the pages and when the value of x will be less than the value of x of the item to be transferred it will be transferred on the next page.

If I'm wrong please correct it.

 

//At least it was with me when I tested these codes looking for an ideal solution for editing my code.

Edited by Crowlai
Explanation on my example
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

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.