Jump to content

Swapping items' positions within the player's inventory


DJPaul

Recommended Posts

Hello; I am new to modding DST and would appreciate advice from experienced developers.

 

I have a situation where I need to swap the position of two inventory items. For example, on the player's screen, they have an item in each of the two left-most inventory slots. The item in slot 1 needs to be moved to slot 2, and the item that was in slot 2, needs to move to slot 1. What's the best way to do this?

 

I'm hoping there's a built-in function that will get me close. I've found Inventory:GiveItem() which looks about right, though if it is the correct function, I am not yet familiar enough with Lua to understand if it will swap the inventory items' positions non-destructively, or whether it's going to spawn new items.

Link to comment
Share on other sites

First of all, this is the DS modding section. You're more likely to get useable code in the DST one.

 

The function you mentioned gives an existing item to that inventory. Which means you need to get a reference to that specific item you want to swap.

I suggest you use inventory:RemoveItem(item, wholestack) before though, to assure the item gets removed from the original owner.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...