#save all player item then get it back
1 messages · Page 1 of 1 (latest)
do u need to save as string or just a temporary object?
String
oh my, that's gone need some sort of translator
well, converter actually
what's the purpose btw?
Save all player item then get it back
yeah, but should it be temporary?
yea
setting some sort of cloud strorage actually
*storage
but it will be deleted on /reload or world restart
Np
so saving them as object would be easier
const containers = new Map()
```will act like cloud
w8, im writing it rn
Okay
class Inventory {
static containers = new Map()
inventory = {
items: Array.from({ length: 36 }),
load(player) {
const inv = player.getComponent('inventory')
const container = inv.container
this.items.forEach((_, slot) => {
container.setItem(slot, this.items[slot])
})
}
}
equipment_inventory = {
items: {
head: null, chest: null, legs: null, feet: null, offhand: null
},
load(player) {
const eq = player.getComponent('equipment_inventory')
Object.keys(this.items).forEach(slot => {
eq.setEquipment(slot, this.items[slot])
})
}
}
constructor(player, name) {
const inv = player.getComponent('inventory')
const eq = player.getComponent('equipment_inventory')
const container = inv.container
const {
equipment_inventory: { items: eqItems },
inventory: { items: invItems }
} = this
invItems.forEach((_, slot) => {
invItems[slot] = container.getItem(slot)?.clone()
})
Object.keys(eqItems).forEach(slot => {
eqItems[slot] = eq.getEquipment(slot)?.clone()
})
Inventory.containers.set(name ?? player.id, this)
}
loadAll(player) {
const { equipment_inventory, inventory } = this
equipment_inventory.load(player)
inventory.load(player)
}
}```
deng 1st try
const manage = {
load(player, id) {
Inventory.containers.get(player.id)?.loadAll(player)
},
save(player, id) {
new Inventory(player)
}
}
world.events.chat.subscribe(({ sender, message }) => {
if (!message.startsWith('ss ')) return
const arg = message.split(' ')
manage[arg[1]]?.(sender, sender.id)
})
for saving someone else's inventory, input their player.id
For load?
Inventory.containers.get(player.id)?.loadAll(player)
Okay
ok, i changed it so u can put name on it
to save, u can either
new Inventory(player)
//or
new Inventory(player,'anything')//number, or any string
Thanks
happy to help 
And for entity?
But does this load the saved items even after a world reload?
Nope

Well, u can load it on an entity, but with equipment sqving would be a different setup
No but like, if I save entity inv, and It despawn and I reload world, would the entity have its Inv loaded?
It's using js memory, so it'll be gone in /reload
Save in item lore? Is it possible?
Yes
How?
It's a complicated code, i can't write it rn, unfortunately