DJPaul Posted May 5, 2015 Share Posted May 5, 2015 I use GLOBAL.ThePlayer.components.inventory:RemoveItem() and GiveItem() to detach and re-add an inventory item (in a different position; it's a sorting mod). As I begin to test my code more extensively, I've discovered it works server-side, but not on the client. I don't think I can use the inventory_replica to do this because the RemoveItem and GiveItem methods aren't defined. I've also checked in the inventory_classified, too, and I can't see relevant methods. So: how do I RemoveItem and GiveItem on the client? Do I have to implement a custom method to do this? Perhaps something like: 1) Client = send RPC request containing a reference to the relevant player or relevant inventory object. 2) Server = handle that RPC request, and do the work based on the ID/object/etc of the provided player/inventory object. Then, I expect that the Server will then push out events to the Client, as normal, causing the inventory to be redrawn, etc. I don't expect that I will need to do any extra work here because the inventory items have already been rearranged? Link to comment https://forums.kleientertainment.com/forums/topic/53540-removingadding-player-inventory-items-on-client/ Share on other sites More sharing options...
Kzisor Posted May 5, 2015 Share Posted May 5, 2015 @DJPaul, How do I RemoveItem and GiveItem on the client?If you have properly done it on the server side then it should automatically translate to the client. Link to comment https://forums.kleientertainment.com/forums/topic/53540-removingadding-player-inventory-items-on-client/#findComment-634723 Share on other sites More sharing options...
DJPaul Posted May 5, 2015 Author Share Posted May 5, 2015 @DJPaul, How do I RemoveItem and GiveItem on the client?If you have properly done it on the server side then it should automatically translate to the client. Sure, but that's the thing. Those methods don't exist in the Client's inventory_classified or inventory_replica objects. Which is why I asked in my original post if using RPC to tell the Server to do it is the right approach. Link to comment https://forums.kleientertainment.com/forums/topic/53540-removingadding-player-inventory-items-on-client/#findComment-634734 Share on other sites More sharing options...
Kzisor Posted May 5, 2015 Share Posted May 5, 2015 @DJPaul, there is a reason they don't exist in those files because you shouldn't have to modify them in order for the client to actually get the actual effect. Directly from inventory_replica.lua: --Server intercepts messages and forwards to clients via classified net vars inst:ListenForEvent("newactiveitem", function(inst, data) self.classified:SetActiveItem(data.item) end) inst:ListenForEvent("itemget", function(inst, data) self.classified:SetSlotItem(data.slot, data.item, data.src_pos) end) inst:ListenForEvent("itemlose", function(inst, data) self.classified:SetSlotItem(data.slot) end) inst:ListenForEvent("equip", function(inst, data) self.classified:SetSlotEquip(data.eslot, data.item) end) inst:ListenForEvent("unequip", function(inst, data) self.classified:SetSlotEquip(data.eslot) end) Link to comment https://forums.kleientertainment.com/forums/topic/53540-removingadding-player-inventory-items-on-client/#findComment-634738 Share on other sites More sharing options...
DJPaul Posted May 5, 2015 Author Share Posted May 5, 2015 @Kzisor, I appreciate your advice, but I don't yet understand how it helps me. I know I need to update the inventory on the Server instance. Perhaps I am asking the wrong question. How do I run code on the server when someone on the character presses a custom hotkey? Link to comment https://forums.kleientertainment.com/forums/topic/53540-removingadding-player-inventory-items-on-client/#findComment-634779 Share on other sites More sharing options...
Kzisor Posted May 5, 2015 Share Posted May 5, 2015 @DJPaul, your original question is how do you sort the inventory on the client. The answer to that question is you do not because it's not client side. You do it all server side and then it will automatically handle it on the client side if you set it up correctly. If you're wanting to know how to do RPC's you can check out this tutorial: http://forums.kleientertainment.com/files/file/1126-tutorial-mod-rpcs-with-keyhandler/ Link to comment https://forums.kleientertainment.com/forums/topic/53540-removingadding-player-inventory-items-on-client/#findComment-634782 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now