HueHue 0 Posted March 10, 2022 Share Posted March 10, 2022 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. Link to comment Share on other sites More sharing options...
Premium xTryhard 12 Posted March 11, 2022 Premium Share Posted March 11, 2022 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 More sharing options...
HueHue 0 Posted March 11, 2022 Author Share Posted March 11, 2022 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 More sharing options...
Premium xTryhard 12 Posted March 12, 2022 Premium Share Posted March 12, 2022 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 More sharing options...
Honorable Member Solution Owsap 8181 Posted March 12, 2022 Honorable Member Solution Share Posted March 12, 2022 (edited) 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 March 12, 2022 by Owsap 1 https://owsap.dev/ / https://osf.owsap.dev/ Link to comment Share on other sites More sharing options...
HueHue 0 Posted March 12, 2022 Author Share Posted March 12, 2022 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 More sharing options...
Honorable Member Owsap 8181 Posted March 12, 2022 Honorable Member Share Posted March 12, 2022 (edited) 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 March 12, 2022 by Owsap 1 https://owsap.dev/ / https://osf.owsap.dev/ Link to comment Share on other sites More sharing options...
HueHue 0 Posted March 12, 2022 Author Share Posted March 12, 2022 44 minutes ago, Owsap said: for i in xrange(player.INVENTORY_PAGE_SIZE * 4): I've tried this before with different combinations but it doesn't really want to work. Anyway thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now