Jump to content

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.

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...