#Swap Items (equip best armour)

1 messages · Page 1 of 1 (latest)

faint mauve
#

Hi Scipters,

I want to make a script that means if the player has armour in their inventory that is better than that equipped, then swap the armours (so if diamond boots in inventory, and iron boots equipped, swap them).

I have managed to get "swapItems" to work, but now I need to work out a method to check all inventory slots and compare to the armour slots.

This is my swap code atm, which if the player has the tag "SWAP", it will rapidly swap the items in slot 1 and 2 (hotbar 2nd and 3rd slot)

    const inventory = player.getComponent("inventory").container
    if (player.hasTag("SWAP")) {
      inventory.swapItems(1, 2, inventory)
    }

Any help working out how to set this up would be amazing. I am a noob when it comes to complex functions like this 🙂

unborn raptor
#

Yes

faint mauve
unborn raptor
#

U need to

#

Iterate through all players inventory

#

I ll make u a one

faint mauve
#

yeah, that's what I thought, I am just unsure of the best way to do this

#

thanks!

#

if you can show me a sample, then I should be able to work it out and expand 🙂

unborn raptor
#

@faint mauve

faint mauve
# unborn raptor <@599524543241125890>

Hey, I have been working on other bits, forgot about this.

I have seen some other iterators, which have given me a rough idea, I'll probably look again in a couple of weeks, as I'm busy tomorrow and away next week 😉

unborn raptor
#

Ok