Jump to content

Assign an item/quest to a keyboard's key button.


Go to solution Solved by Owsap,

Recommended Posts

  • Premium
2 hours ago, HueHue said:

Hi.

Is there a way to assign an item or a quest to a button on the keyboard?

For example I have an item 50053 and I want to use it by pressing TAB key on my keyboard.

Or I have a quest and I want to open the quest by pressing ~ key on my keyboard.

yes you can do this go to game.py create a function with your key send this to the server check if you have this item id in your inventory and if you have it do what you want and send it back to the client

Link to comment
Share on other sites

8 hours ago, xTryhard said:

yes you can do this go to game.py create a function with your key send this to the server check if you have this item id in your inventory and if you have it do what you want and send it back to the client

Ok that's great but could you or someone help me to write the code for this as I have never done something like this before.
All i know is that i need to use this command in game.py

onPressKeyDict[app.DIK_TAB]	= lambda : self?????

So basically what I want to have is when i press Tab key an item 50053 is being used.
Thank you in advance.

Link to comment
Share on other sites

  • Premium
18 hours ago, HueHue said:

Ok that's great but could you or someone help me to write the code for this as I have never done something like this before.
All i know is that i need to use this command in game.py

onPressKeyDict[app.DIK_TAB]	= lambda : self?????

So basically what I want to have is when i press Tab key an item 50053 is being used.
Thank you in advance.

you have to know C++ to do this there is no magic button for the pc to know what you think

Link to comment
Share on other sites

  • Honorable Member
  • Solution

Although I'm not entirely sure why you would want something like this, I will leave you an example for items.

Python Method Only

Spoiler
''' 1. @ root/game.py '''
# Search
		onPressKeyDict[app.DIK_F] = lambda : self.__PressFKey()

# Add below
		onPressKeyDict[app.DIK_TAB] = lambda : self.__PressTABKey()

# Search
	def __PressFKey(self):

# Add below
	def __PressTABKey(self):
		if self.interface:
			self.interface.UseInventoryItem(50053)

''' 2. @ root/interfaceModule.py '''
# Search
if __name__ == "__main__":

# Add above
	def UseInventoryItem(self, itemVNum):
		self.wndInventory.UseItem(itemVNum)

''' 3. @ root/uiInventory.py '''
# Search
	def UseItemSlot(self, slotIndex):

# Add above
	def UseItem(self, itemVNum):
		if player.GetItemCountByVnum(itemVNum) <= 0:
			return

		getItemVNum = player.GetItemIndex
		for i in xrange(player.INVENTORY_PAGE_SIZE):
			slotNumber = self.__InventoryLocalSlotPosToGlobalSlotPos(i)
			if getItemVNum(slotNumber) == itemVNum:
				self.UseItemSlot(slotNumber)
				break

 

Python & C++ Method

Spoiler
''' 1. @ root/game.py '''
# Search
		onPressKeyDict[app.DIK_F] = lambda : self.__PressFKey()

# Add below
		onPressKeyDict[app.DIK_TAB] = lambda : self.__PressTABKey()

# Search
	def __PressFKey(self):

# Add below
	def __PressTABKey(self):
		net.SendChatPacket("/use_item_vnum 50053")
/// 2. @ game/src/cmd.cpp
// Search
ACMD(do_use_item);

// Add below
ACMD(do_use_item_vnum);

// Search
	{ "use_item", do_use_item, 0, POS_DEAD, GM_LOW_WIZARD },

// Add below
	{ "use_item_vnum", do_use_item, 0, POS_DEAD, GM_PLAYER },

/// 3. @ game/src/cmd_general.cpp
// Add to the bottom of the document
ACMD(do_use_item_vnum)
{
	char szArg[256];
	one_argument(argument, szArg, sizeof(szArg));

	DWORD dwVNum = 0;
	str_to_number(dwVNum, szArg);

	LPITEM pItem = ch->FindSpecifyItem(dwVNum);
	if (pItem == nullptr)
		return;

	if (pItem->GetCount() > 0)
		ch->UseItem(TItemPos(INVENTORY, pItem->GetCell()));
}

 

I did not test before posting, excuse me if something goes wrong.

Edited by Owsap
  • Love 1
Link to comment
Share on other sites

4 hours ago, Owsap said:

Although I'm not entirely sure why you would want something like this, I will leave you an example for items.

Python Method Only

  Reveal hidden contents
''' 1. @ root/game.py '''
# Search
		onPressKeyDict[app.DIK_F] = lambda : self.__PressFKey()

# Add below
		onPressKeyDict[app.DIK_TAB] = lambda : self.__PressTABKey()

# Search
	def __PressFKey(self):

# Add below
	def __PressTABKey(self):
		if self.interface:
			self.interface.UseInventoryItem(50053)

''' 2. @ root/interfaceModule.py '''
# Search
if __name__ == "__main__":

# Add above
	def UseInventoryItem(self, itemVNum):
		self.wndInventory.UseItem(itemVNum)

''' 3. @ root/uiInventory.py '''
# Search
	def UseItemSlot(self, slotIndex):

# Add above
	def UseItem(self, itemVNum):
		if player.GetItemCountByVnum(itemVNum) <= 0:
			return

		getItemVNum = player.GetItemIndex
		for i in xrange(player.INVENTORY_PAGE_SIZE):
			slotNumber = self.__InventoryLocalSlotPosToGlobalSlotPos(i)
			if getItemVNum(slotNumber) == itemVNum:
				self.UseItemSlot(slotNumber)
				break

 

Python & C++ Method

  Reveal hidden contents
''' 1. @ root/game.py '''
# Search
		onPressKeyDict[app.DIK_F] = lambda : self.__PressFKey()

# Add below
		onPressKeyDict[app.DIK_TAB] = lambda : self.__PressTABKey()

# Search
	def __PressFKey(self):

# Add below
	def __PressTABKey(self):
		net.SendChatPacket("/use_item_vnum 50053")
/// 2. @ game/src/cmd.cpp
// Search
ACMD(do_use_item);

// Add below
ACMD(do_use_item_vnum);

// Search
	{ "use_item", do_use_item, 0, POS_DEAD, GM_LOW_WIZARD },

// Add below
	{ "use_item_vnum", do_use_item, 0, POS_DEAD, GM_PLAYER },

/// 3. @ game/src/cmd_general.cpp
// Add to the bottom of the document
ACMD(do_use_item_vnum)
{
	char szArg[256];
	one_argument(argument, szArg, sizeof(szArg));

	DWORD dwVNum = 0;
	str_to_number(dwVNum, szArg);

	LPITEM pItem = ch->FindSpecifyItem(dwVNum);
	if (pItem == nullptr)
		return;

	if (pItem->GetCount() > 0)
		ch->UseItem(TItemPos(INVENTORY, pItem->GetCell()));
}

 

I did not test before posting, excuse me if something goes wrong.

Oh man that "Python Method Only" works PERFECTLY!
Thank you soooo much i really appreciate it!

5 hours ago, Owsap said:

Although I'm not entirely sure why you would want something like this, I will leave you an example for items.

Python Method Only

  Reveal hidden contents
''' 1. @ root/game.py '''
# Search
		onPressKeyDict[app.DIK_F] = lambda : self.__PressFKey()

# Add below
		onPressKeyDict[app.DIK_TAB] = lambda : self.__PressTABKey()

# Search
	def __PressFKey(self):

# Add below
	def __PressTABKey(self):
		if self.interface:
			self.interface.UseInventoryItem(50053)

''' 2. @ root/interfaceModule.py '''
# Search
if __name__ == "__main__":

# Add above
	def UseInventoryItem(self, itemVNum):
		self.wndInventory.UseItem(itemVNum)

''' 3. @ root/uiInventory.py '''
# Search
	def UseItemSlot(self, slotIndex):

# Add above
	def UseItem(self, itemVNum):
		if player.GetItemCountByVnum(itemVNum) <= 0:
			return

		getItemVNum = player.GetItemIndex
		for i in xrange(player.INVENTORY_PAGE_SIZE):
			slotNumber = self.__InventoryLocalSlotPosToGlobalSlotPos(i)
			if getItemVNum(slotNumber) == itemVNum:
				self.UseItemSlot(slotNumber)
				break

 

Python & C++ Method

  Reveal hidden contents
''' 1. @ root/game.py '''
# Search
		onPressKeyDict[app.DIK_F] = lambda : self.__PressFKey()

# Add below
		onPressKeyDict[app.DIK_TAB] = lambda : self.__PressTABKey()

# Search
	def __PressFKey(self):

# Add below
	def __PressTABKey(self):
		net.SendChatPacket("/use_item_vnum 50053")
/// 2. @ game/src/cmd.cpp
// Search
ACMD(do_use_item);

// Add below
ACMD(do_use_item_vnum);

// Search
	{ "use_item", do_use_item, 0, POS_DEAD, GM_LOW_WIZARD },

// Add below
	{ "use_item_vnum", do_use_item, 0, POS_DEAD, GM_PLAYER },

/// 3. @ game/src/cmd_general.cpp
// Add to the bottom of the document
ACMD(do_use_item_vnum)
{
	char szArg[256];
	one_argument(argument, szArg, sizeof(szArg));

	DWORD dwVNum = 0;
	str_to_number(dwVNum, szArg);

	LPITEM pItem = ch->FindSpecifyItem(dwVNum);
	if (pItem == nullptr)
		return;

	if (pItem->GetCount() > 0)
		ch->UseItem(TItemPos(INVENTORY, pItem->GetCell()));
}

 

I did not test before posting, excuse me if something goes wrong.

Just one more thing the "Python Method Only" works only on the 1st inventory page.
How to change it so that it will work on all 4 inventory pages.

Link to comment
Share on other sites

  • Honorable Member
7 hours ago, HueHue said:

Just one more thing the "Python Method Only" works only on the 1st inventory page.

How to change it so that it will work on all 4 inventory pages.


for i in xrange(player.INVENTORY_PAGE_SIZE * 4):
	if getItemVNum(i) == itemVNum:
		self.UseItemSlot(i)
		break

 

Edited by Owsap
  • Good 1
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.