Jump to content

Recommended Posts

Hey, Icy here again..

So after playing the game for a while, I've noticed that when you unequip a weapon by equipping something else, it tries to put that weapon in the last place, it has been before equipping, rather then just simply swapping it. This often makes my inventory quite messy and it's really frustrating to sort it over and over again.

 

Now, I don't know how to create this mod by myself, so I'm asking for your help.

Could anyone please make this little mod, that would instead of doing what I mentioned above, simply just SWAP the weapons (and tools) instead?

 

It would be really, really helpful!

@IcyTheWhite

 

Try this code.

AddSimPostInit(function(inst)	local old_Equip = inst.components.inventory.Equip	function inst.components.inventory:Equip(item, old_to_active)		local eslot = item.components.equippable.equipslot		local olditem = self.equipslots[eslot]		if olditem ~= item then			olditem.prevslot = self:GetItemSlot(item)		end		return old_Equip(self, item, old_to_active)	endend)

-

 

You might also wanna check out this Sort Inventory mod.

You need to check if there actually was an old item before attempting to compare it.

        if olditem and olditem ~= item then

 

I don't think that's the issue. If olditem is nil, then it would be "(nil) ~= item". As far as I know, that's perfectly fine, and will evaluate to false.

See below.
Edited by Blueberrys

@Blueberrys,

 

That's the problem, olditem ~= item returns true when nil ~= item since nil is in fact not equal to item.

 

(in contrast to languages that will either always return false or null when a nil/null is used in a comparison)

Edited by Corrosive

So between backpacks, it still works the old-fashioned way, but between chests and chester, it makes the equipped item drop in the 1st free space in inventory (probably same too as in vanilla).

 

Would there be a way at the very least to make it work the same way for backpacks as for inventory items?

Sadly @Blueberrys, I can't. I'm not a programmer and most of the code doesn't speak to me. =/

I'm much more into graphics than programming, and that's why I won't most likely ever be able to make something more than basic code..

If you want to help me, you would have to literally write down the whole code for me. I'm sorry..

@IcyTheWhite I took a quick look at it and did not figure out what needs to be changed. I'm sorry, but I don't have the time to continue working on this. You're gonna have to try to figure it out yourself. It might take you longer to do that than it would take me, but I think it would be worthwhile. Look through the code for those components, see if you can understand what's going on. Do a few tests on what you find, then ask if you get stuck.

 

Here are some resources to get you started:

Edited by Blueberrys

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...