#multiple inventory save system

1 messages · Page 1 of 1 (latest)

gusty scroll
#

Is it possible to "store" a players inventory and then give it back to them?
Basically what I want is to create a Survival area, a Creative area, and a Games area. I do not want players to bring their inventory from any or the areas into any of the other areas but I also do not want to simply "clear" their inventory causing them to loose things.
If this is possible where should I be looking for examples or ideas to help me figure it out? Is this something I should be trying to do with script or should I be looking to a different method of doing it?
A note, I'm actually working on this for Education Edition so I'm still working in Stable on 1.20.13 and should try to avoid any experimental features.

Jayly recommended transfering the player's inventory to an entity and back. That sounds promising to me but I'm not sure how to go about doing that.

Mohamed shared a script that appears to be able to save an reload an inventory so I will be looking into that to see if it will work or help me in this situation. @flint sequoia that script you shared, what versions of everything are required to use that script? I've been away for a while and I really don't know what the current developments are since I'm sure last time I tinkered with any of this Education was still in version 1.19

flint sequoia
#

also i was using runCommand than to save the inv in a chest in a structure
we have now a native structure api

#

#1067535608660107284 message

midnight kiln
gusty scroll
#

Ok I have been doing some tutorials to educate myself a little more.
As noted I'm in Education version 1.20.13
So first I have to try to make sure I can get things working in Bedrock then I need to go into education and see if it still works. I have been able to at least get a server form to come up in education I was able to use

      {
        "module_name": "@minecraft/server",
        "version": "1.4.0-beta"
      },
      {
        "module_name": "@minecraft/server-ui",
        "version": "1.2.0-beta"
      }
    ]```
#

Yes I have done some things in education so I can see the content log and I can access the experimental toggles.

#

that will be enough for the night.

#

I will have to test it out tomorrow to see if the inv_save_load.js will work in 1.4.0-beta

#

First test in Bedrock 1.20.81
I'm getting the following error

#

[SyntaxError: Could not find export 'Vector' in module '@minecraft/server']
@midnight kiln any Idea what's up with that error or how I deal with it?

lofty sparrow
cold dock
#

you can i have one

flint sequoia
#

@gusty scroll

midnight kiln
#

There are other ppl who made their own vector libs, use one.

gusty scroll
midnight kiln
#

I mean if you dont like it okay then... but like

gusty scroll
midnight kiln
#

Thats Minato's

#

The one i sent you does not require Vector

#

import { world, system, EquipmentSlot } from "@minecraft/server";

#

Thats all you need

gusty scroll
#

ok, will look again when I get back

midnight kiln
#

If its telling you u need vector3 then its prob spawnAll & you dont need vector you need an object {x: 0, y: 100, z: 0}

#

& also spawnAll requires the area ur gonna spawn the items in to be in a tickingarea or to be loaded

midnight kiln
#

Idk when they changed the equipment_inventory to equippable

#

But thats the version you need to be using at least

#

& i dont think the inventory saver & loader works in stable versions only in beta

#

That's all the info you need to help you with the inventory saver & loader system i sent u

gusty scroll
#

@midnight kiln So I'm not figuring out quite how to use this. Trying to test first in Bedrock 1.20.81 using

  {
    "module_name": "@minecraft/server",
    "version": "1.11.0-beta"
  }
]```
#

I know there are more parts I need to add to that .js file bit you sent so I can actually make it work for testing but I'm in need of a more complete example I fear.

midnight valve
#

Are you fine with using the beta version of the server module?

midnight kiln
midnight kiln
gusty scroll
#

Well, I have confirmed that I can use the beta in education edition. However, educaiton edition is still only at 1.20.13 so I would be in 1.4.0 Beta

#

I'm using Bedrock 1.20.81 for testing

midnight kiln
#

Then its 1.11-beta

gusty scroll
#

but I want to figure out something I can use for education which is 1.20.13 still

midnight kiln
#

Look i don't know if the script i sent you works for education edition minecraft, if u mean it, but if you mean education edition toggle on worlds then its 1.11.0-beta for 1.20.80 & 1.20.81, & for minecraft 1.21 its 1.12.0-beta

gusty scroll
#

At the moment I'm just trying to figure out how to use the portion of the code @midnight kiln shared with me

midnight kiln
#

Lemme give u manifest.json rq

gusty scroll
#

I've got a manifest.

midnight valve
gusty scroll
# midnight kiln Lemme give u manifest.json rq

right now I'm trying to just test it in game. I need have whatever I need in order to save the inventory and then see if I can re-load it. I don't care if that means using a stick or typing something in chat but I don't seem to be able to get that part working

gusty scroll
midnight kiln
midnight kiln
#

Why would you even use 1.20.10???

midnight valve
#

Ya the only issue with beta is everytime a new beta is released they remove the previous one meaning you'll constantly have to change the manifest to the new version or you'd have to switch to the stable version which could completely change the script

midnight kiln
#

& chatSend event is in beta lol

midnight valve
gusty scroll
midnight valve
#

Ya but he wouldn't need chat send right? Only for testing, he could just use scriptevents which are stable

midnight kiln
gusty scroll
#

Sure whatever I need to use

midnight valve
#

So your on the latest version of the game though right?

gusty scroll
#

I have Bedrock 1.20.81

midnight valve
#

But the students dont?

gusty scroll
#

But eventually I'm trying to figure out something I can do for 1.20.13 education edition.

midnight valve
#

Well I don't think we can access the actual education edition since it's strictly for your position so I'm not entirely sure how it works on that edition

midnight kiln
#

Yeah there is a completely different api

gusty scroll
#

now I know I can do at least some of this without even doing scripts, but I thought it might be cleaner if I can use script.

#

Actually Education edition is really just Bedrock with some added security features and they hide some things from the UI

#

Addons for Bedrock work in education as long as you make sure it is from the older Bedrock edition.

#

Experimental toggels are a little tricky but I have accessed them for worlds I creat/host

midnight valve
#

Ok I didn't know that, I thought it didn't even have stuff like survival mode, I thought it was just those teaching modes

midnight valve
#

So 1.4.0 beta is the latest script version in education?

midnight kiln
#

Hope yall figure something out

gusty scroll
#

Education Edition is bedrock but there is no dedicated server and only people from the same "school" can join multiplayer etc.

midnight kiln
midnight valve
#

Ok that might restrict things, idk if I've ever looked at that module

gusty scroll
#

Yea, looking at the documentation 1.4,0 beta is the server version

midnight valve
#

I'll see what I can find

gusty scroll
#

Yea my other option is along the lines of killing the player to store their inventory in a structure for each ZONE but that is clunky since I normally have keep inventory ON for Students and doesn't do a good job of automatically putting equipment back on.

midnight valve
#

It still looks possible to save the items and load them back in to the players inventory in that version but there does look to be some restrictions regarding saving the durability and possibly enchantments of items

#

They show an example of getting the durability but the class they use doesn't even exist so I'm not sure what's up with that

gusty scroll
#

Ok, I'm willing to try it. I'm just not all that skilled at coding.

flint sequoia
gusty scroll
#

As a side note, I use NPC dialoges extensively in my Addons

#

so if it is possible to trigger the script using a command in an NPC or via animation controller on the player, I'm already doing those things.

flint sequoia
gusty scroll
#

We are actually trying to figure something out for Education edition which is still 1.20.13 so server 1.4.0-beta is the best I can work in for it.

flint sequoia
gusty scroll
#

Cool.

flint sequoia
#

the script look like

system.afterEvents.scriptEventReceive.subscribe((event) => {
    const { id, message, sourceEntity, sourceType } = event;

});

i don't remember the command syntax

gusty scroll
#

command syntax in game is about the easiest thing to figure out just by typing in and seeing options

midnight valve
#

The messageId is whatever you want to use to check for in the script and the message is optional

flint sequoia
#

where did you reach in your project?
any progress?

gusty scroll
#

Have not actually gotten very far I'm afraid.

flint sequoia
#

let me boot up my game and help with what i can
because i am in 1.20.80

gusty scroll
#

ok. I've managed to get some basic stuff to work in Education (1.20.13) using server 1.4.0-beta and server-ui 1.2.0-beta

#

I've also got Bedrock 1.20.81 available for testing things if needed just to learn what I'm doing but I haven't had that much luck getting things working any better in that.

#

@flint sequoia hay, Vector might still work in 1.4.0-beta

#

but
[Scripting][error]-TypeError: not a function at saveInv (inventory/inventory.js:25)
at <anonymous> (inventory/inventory.js:10)

flint sequoia
#

i am re writing the script without it

gusty scroll
#

no what I'm saying is that for Education Edition, I'm not getting the vector error, I believe Vector is still in there for that version.

#

But it is giving me the not a function error

flint sequoia
#

i know but it will be gone in feature update
i am trying to see what did i use that not available in 1.4.0 beta

gusty scroll
#

ok

#

AFK for a bit.

midnight valve
flint sequoia
midnight valve
#

i agree, im honestly surprised that 1.20.13 doesnt have them. Didnt realize how quick scripts have been advancing until now

flint sequoia
#

yeah

gusty scroll
#

moving fast since I looked at stuff last summer

flint sequoia
#

@gusty scroll
i changed somethings and made the script able to save multiple inventories (each inv have id)
so the scriptevent command should look like
/scriptevent id:test <load/save> <invId>
here is the script and a video of me using it

gusty scroll
#

Awsome, let me test it out.

#

still getting this error
[Scripting][error]-TypeError: not a function at saveInv (inventory/inventory.js:31)
at <anonymous> (inventory/inventory.js:21)

#

it doesn't seem to like const block2 = block.south(2);

midnight valve
#

south doesnt exist in that server module

gusty scroll
#

can we define the block2 location in another way?

midnight valve
#

change that line to

const block2 = dimension.getBlock({ x: location.x, y: -64, z: location.z + 1 });
#

+z is south in minecraft its weird but that should be the same location

gusty scroll
#

Ok, I was trying to figure that out in the previous verson.

#

so next we have

[Scripting][error]-TypeError: Native type conversion failed. at saveInv (inventory/inventory.js:33)
at <anonymous> (inventory/inventory.js:21)

midnight valve
#

oh ya

#

setType doesnt exist either i forgot

#

hold on ill fix those 2 lines

#

Replace lines 33 and 34 with these

block.setPermutation(BlockPermutation.resolve("minecraft:chest"));
block2.setPermutation(BlockPermutation.resolve("minecraft:chest"));
#

and line 1 youll need too add BlockPermutation to the import list should look like this

import {system ,Player, BlockPermutation} from "@minecraft/server";
gusty scroll
#

ok

#

Now we have
[Scripting][error]-TypeError: cannot read property 'getEquipment' of undefined at saveInv (inventory/inventory.js:53)
at <anonymous> (inventory/inventory.js:21)

#

brb

midnight valve
#

are you using the npcs?

#

he has it set to use them so if not then thats why

gusty scroll
#

I set up one npc to test with

midnight valve
#

strange

gusty scroll
#

But line 53 is about getEquipment

midnight valve
#

the issue is that getEquipment is being called on a variable that is undefined. in this case it seems like player.getComponent('equippable') is not returning what is expected. I dont necessarily know why though because getComponent should work

#

im curious if equippable was named something else in that version or if it didnt exist. Ill need to check that

gusty scroll
#

I decided to // out those lines so I could check if the other parts are working and they are. So just need to figure out how to handle equipment.

#

maybe EquipmentSlot

midnight valve
#

ya getComponent exists in that version but i did hear about the equippable component changing or something like that at one point in time

gusty scroll
#

yea, I think you are right there. Looking to see if I can figure out what it was called

#

maybe it is getEquipmentSlot or getEquipment

#

Methods
getEquipment

getEquipment(equipmentSlot): ItemStack
Parameters
    equipmentSlot: EquipmentSlot

    The equipment slot. e.g. "head", "chest", "offhand"
Returns ItemStack

Returns the item equipped to the given EquipmentSlot. If empty, returns undefined.
Remarks

Gets the equipped item for the given EquipmentSlot.

This function can't be called in read-only mode.
midnight valve
#

i mean i guess you could try making the slots lowercase and see if that works but i dont think it will. In the index.d.ts there just isnt even an equippable component, theres other entity components though

gusty scroll
#

yea, it isn't equipable

#

componentId: "minecraft:equipment_inventory" = 'minecraft:equipment_inventory'

midnight valve
#

yep thats it

#

youd just change

 //equipment
    const Chest = player.getComponent("equippable").getEquipment("Chest");
    blockRest.setItem(9, Chest);
    const Feet = player.getComponent("equippable").getEquipment("Feet");
    blockRest.setItem(10, Feet);
    const Head = player.getComponent("equippable").getEquipment("Head");
    blockRest.setItem(11, Head);
    const Legs = player.getComponent("equippable").getEquipment("Legs");
    blockRest.setItem(12, Legs);
    const Offhand = player.getComponent("equippable").getEquipment("Offhand");
    blockRest.setItem(13, Offhand);

to this

 //equipment
    const Chest = player.getComponent("equipment_inventory").getEquipment("Chest");
    blockRest.setItem(9, Chest);
    const Feet = player.getComponent("equipment_inventory").getEquipment("Feet");
    blockRest.setItem(10, Feet);
    const Head = player.getComponent("equipment_inventory").getEquipment("Head");
    blockRest.setItem(11, Head);
    const Legs = player.getComponent("equipment_inventory").getEquipment("Legs");
    blockRest.setItem(12, Legs);
    const Offhand = player.getComponent("equipment_inventory").getEquipment("Offhand");
    blockRest.setItem(13, Offhand);
#

also the first thing i had you change i only added 1 to the z position but it looks like he was adding 3 to it. I believe south already defaults to 1 block away and then the (2) would be an extra 2 blocks so you may need to change the first thing i helped fix to be z + 3 or z + 2 im not entirley sure which one

gusty scroll
#

as t the equipment change, I don't think we are quite there yet.

#

const getEntityEquipmentInventoryComponent = entity.getComponent(
"equipment_inventory"
);
getEntityEquipmentInventoryComponent.getEquipment(EquipmentSlot.MainHand);
const equipmentSlot = EquipmentSlot.Head;
getEntityEquipmentInventoryComponent.getEquipmentSlot(equipmentSlot);
getEntityEquipmentInventoryComponent.setEquipment(EquipmentSlot.OffHand); // Assuming undefined (empty slot) as an example

#

that was from the page. I think we need to do EquipmentSlot

midnight valve
#

EquipmentSlot.Head is just minecraft pre typed strings that is the same as typing "Head"

#

also that first line you sent is just another extra line of code thats not actually necessary

gusty scroll
#

is there something else I need to import?

midnight valve
#

no if you use EquipmentTypes then you would have to download the VanillaData module i believe and import it from that but its easier to just type the strings so you should be fine with the imports you have

gusty scroll
#

well it is still complaining about line 53 which is where we start constructing the equipment inventory

[Scripting][error]-TypeError: Native type conversion failed. at saveInv (inventory/inventory.js:53)
at <anonymous> (inventory/inventory.js:21)

midnight valve
#

well thats atleast a new error so we made some sort of progress

gusty scroll
#

is it an entity vs player thing?

midnight valve
#

it sucks because i cant actually test the code myself. I am only able to use the server version 1.4.0 and not the beta

#

well that error is really not helpful so i cant exactly say but line 53 is still the same line right?

gusty scroll
#

yea

#

line 53 is

#

const Chest = player.getComponent("equipment_inventory").getEquipment("Chest");

#

and if I comment out the block of equipment, the rest of the script works

midnight valve
#

Actually it looks like you can use the EquipmentSlot enums as they are just in the server module. You'd need to import it at the top but it's the only thing I could think of for fixing it.

#

Try adding EquipmentSlot in the server import list

#

Then instead of "Chest" try EquipmentSlot.Chest

gusty scroll
#

the equipmentslot in the import is still showing as kinda greyed out

#

still getting that same error

#

do I need to
const equipmentSlot = EquipmentSlot.Head; before getting it?

midnight valve
#

Are you using visual studio code?

#

If you hover over EquipmentSlot in the import when it's grayed out it should say it's just not being used

gusty scroll
#

Yes and right it says not being used

midnight valve
#

But no you don't need to do that, again the EquipmentSlot enums are just strings so EquipmentSlot.Head is the same as typing "Head". I'm gonna go make some food but when I get back I'll try to help figure it out. I might need to downgrade my minecraft to that version though

gusty scroll
#

Thanks for the help. I need to go do the chores myself.

gusty scroll
#

@midnight valve I could probably set you up with a temporary minecraft education test account for my tenet. you can download education edition free https://aka.ms/downloadmee-desktopApp that is the windows installer.
That RP has to be enabled globally in order to see the experimental toggles
But to enable the content log you actually have to go do it in the options.txt in the minecraftpe folder

midnight valve
#

ok thanks

flint sequoia
#

messed a lot : )

#

did it work?

midnight valve
#

it had a few issues, the only issue that seems to be persistent is the equippable component doesnt exist in that version as it was called equipment_inventory instead but for some reason thats also not working

flint sequoia
#

he should get all and print to the console

gusty scroll
midnight valve
#

oh lol was just gonna say it wouldnt even get to the main meny

#

menu

midnight valve
#

fixed it

#

once i fix the rest ill send the script

#

its all working, the main issue was the equipment slots had to be lowercase

#

and i did have to change the location to be +2 on the z as it was throwing an error when it was +1

gusty scroll
#

cool, I'll be back in a few to check it out. Thanks

gusty scroll
#

Hay Guys, @midnight valve @flint sequoia you are awesome Thanks for the help it is working!!!
Now I get the fun of implementing it into the systems for my Classroom management Pack

flint sequoia
gusty scroll
#

looks like only
{system ,Player, BlockPermutation, Container
are used

#

EquipmentSlot, ItemStack, world} appear unused

midnight valve
#

if you add

/**@type {Variable Type Here}*/

before a variable it lets vscode know what it is

#

but it has to be in the imports to use it

flint sequoia
midnight valve
#

ya im so used to c# the whole generic variable thing really bothers me so i always put that before the variables in my function inputs then i get all autocompletions when writing functions

#

typescript would be better for me but i dont like how it compiles

flint sequoia
#

yeah auto completions work fine outside functions but if i used player as arg in the function
his properties don't auto completions

gusty scroll
#

Cool, I'm learning extra little bits now! I had not understood the whole /**@type {Variable Type Here}*/ I kept seeing in code.

midnight valve
#

exactly, its just because javascript variables can be changed to be any type at any time. These both work kinda the same way

// Typescript
function SendPlayerMessage(message: String){
}
//Javascript
function SendPlayerMessage(/**@type {String}*/message){
}
#

most coding languages are strict and require a variable to be set to a specific type right away, then they cant be changed

flint sequoia
#

is this correct ?

function SendPlayerMessage(message){
/**@type {String}*/
}
midnight valve
#

not exactly

#

youd need to put it before message

#

basically right above the variable or to the left of it

flint sequoia
#

i remember doing something like this
let me test it out lol

gusty scroll
#

So if I don't want the inventory structure deleted when some one loads the associated inventory, would it work to simply let the program overwrite the structure when a new set is saved?

midnight valve
#

Both of these work

/**@type {String}*/const message = "hi";

/**@type {String}*/
const message = "hi";
midnight valve
flint sequoia
#

it was like this

/**
 * Saves the player's inventory to a specified id.
 * @param {Player} player - The player whose inventory is being saved.
 * @param {string} id - The id used to identify the saved inventory.
 * @returns {void}
 */
function saveInv(player,id){}
midnight valve
#

yep i just prefer to write the other one since most of my functions are just for my own projects and i dont like having extra lines if i dont need to

#

thats what i used in my MathUtils module though, i wrote a bunch of Vector related functions and a class for Vector3s and other math related stuff. Since it was meant to be public for anyone to use it only made sense to add all that to it. Although now it makes it a pain to look through with all the extra lines

midnight valve
#

exactly! i dont want to be scrolling forever just to find something lol

flint sequoia
#

yeah lol
my code is 600 line
1000 if i format it with vs code

#

also never used multiple files lol
i can read it and that what matter

midnight valve
#

i do use multiple files now since alot of my projects require alot of different custom classes, i usually keep all the main events and intervals in the main.js then have all my extra classes in their own files

#

This is the math utils module, wouldve been like 300 lines if i didnt add all the helper stuff

flint sequoia
#

yeah that what i meant
but like if i only want "add" from vec3 class
i just add a one line function

midnight valve
#

i totally get that, its more stuff like my vein miner addon that im making that would be a mess in one file. I have to make a new line for every block i want to add to it and i dont want my main.js to have 200 lines of just blocks when i could just separate that

flint sequoia
#

yeah
do you have any public addons shared?

midnight valve
#

none of my "good" addons have been published though because they are usually way more complicated and take too much time for me to complete.

flint sequoia
midnight valve
gusty scroll
#

Ok I'm gonna have to make some changes to be able to use this in other dimensions.

#

or just say they can only use this at a particular entry point to the other zones.

flint sequoia
#

send dimension type to the save/load function as an arg and use it to control the chest corrds

#

or just use player.dimension

gusty scroll
#

oh this might be something I can modify to create an inventory inspection system!!! Where Admin could have a room full of barrels and run a command to check a particular players inventory for banned items.

burnt wedge
#

can i get a background on how you guys are storing inventory data

gusty scroll
#

I have altered the script to stack the chests instead of putting them over on the z axis I just changed the heights so the first one is at y-64 and the other one is at y-63.
I also removed the structure delete command and the tag check for saving an inventory.

gusty scroll
waxen rivet
gusty scroll
#

Keep in mind, this was written for 1.20.10 since I am working with Minecraft Education edition and we are still only version 1.20.13 at this point. This is using server 1.4.0-beta

burnt wedge
#

how about custom chests? like opening a chest UI natively -- have you guys thought of that?

gusty scroll
#

Basically the script is just looking at the players inventory and equipment and storing them into a couple chests by inventory slot. Then saving those in structures. When you load it it basically does the reverse

midnight valve
midnight valve
daring summit
#

it’s how people make chat commands utilising forms. since you can’t force open it. it will usually just cancel but we can make it wait until the player isn’t “busy” and then open the form simulating a force open

midnight valve
#

I mean that's still the forms though

midnight valve
daring summit
#

oh sorry i didn’t see that you were talking about ui's in general 😭

#

that’s my bad

midnight valve
#

Ya it's all good I realized after reading it that i wasn't very clear about what I meant

daring summit
#

i would think custom chests would be something like chest form ui and a whacky way to put items in it

#

unless we get something like non entity containers soon

midnight valve
#

That's how java server plugins work. You create a inventory panel the same way as a modal form data then just add stuff to it. It is just an empty inventory everytime you create it. Something like that could be useful for scripts when it comes to force opening a chest ui

#

But even just giving us block inventories and letting us force open them in scripts would be nice

#

Well custom block inventories

daring summit
#

oh i thought java just was able to use chests normally as a ui and edit it. since other people can access it at the same time

#

block inventories would change scripting.

#

it would change everything

gusty scroll
#

Getting back to the Original Topic. The Inventory Save/Load script. Warning, if you have some item locked and always replaced in a particular slot in the players inventory, be sure to remove that slot from the script so that you don't wind up with duplicates clogging up their inventory.

daring summit
#

weird that it would cause duplicates

#

anyone have the script of this working for 1.20.80? would be nice to see what people are doing for saving items

gusty scroll
#

@midnight kiln shared a script with me that I think works for 1.20.80 and I'm sure others have similar scripts that will work for the current versions at least with the beta api.
I expect this one could be edited to work in the current version too. Main issue is that they have changed the terminology for the equipment. The older version it was getComponent("equipment_inventory").getEquipment(legs");
in the newer versions I think it has changed to getComponent("equipable")
if you look back through this thread I think the you may find one that probably works in the current version.

gusty scroll
daring summit
#

yea i’ll see thank you! i’m looking for alternatives as my way is kinda weird and i want stuff to be efficient. i’m currently working on a sorta player shop system

flint sequoia
gusty scroll
#

Yea, I have the item in the last hotbar slot. I simply changed the hotbar to <8 instead of <9

#

Now I'm considering an inventory inspection script that a teacher (op) could run on a player (student) how would I change the subscribe to allow an op or player with a designated tag to run the script
event command on a particular player.

daring summit
#

it returns true or false

gusty scroll
#

ok

#

I'm trying to figure out how I should write the
system.afterEvents.scriptEventReceive.subscribe((event) => {

#

I'm thinking I want to set this up so I can type the command in chat so I can enter the player's name or a score to check their inventory.

daring summit
#

hm i can’t really help with that. i’ve never used script events

#

you can test if message has a player name

gusty scroll
#

Ah. The One for the initial save/load script is
system.afterEvents.scriptEventReceive.subscribe((event) => {
const {id, initiator:player, message, sourceEntity:npc} = event
if(id !== 'id:test' || !(player instanceof Player)) return
if(message.startsWith("load ")){
const [type,id] = message.split(" ")
if(!player.hasTag("inv_saved" + id)){
player.sendMessage("§cYou don't have saved inventory with the id : " + id)
return
}
loadInv(player, id)
player.sendMessage("§aInventory loaded with the id : " + id)
} else if(message.startsWith("save ")){
const [type,id] = message.split(" ")

    saveInv(player,id)
    player.sendMessage("§aInventory saved with the id : " + id)
    player.addTag("inv_saved" + id)
}

})

#

But that one is made to have the command come from an NPC

gusty scroll
#

@flint sequoia or @midnight valve or anyone else
How might I write this to be able to say, run it from a player animation or a function being run from a player animation?

flint sequoia
#

change the command with the script event one
and change the molang

#

there example in the site

gusty scroll
#

I just need to learn how to change the syntax of the script event subscribe in the script

flint sequoia
#

what didn't you understand about it?

gusty scroll
#

Like if I want to just type the /scriptevent command into chat. How do I need to set up the script to accept the source entity

#

Or if I want to use my custom tc:remote npc entity as the source how do I get that to work?

#

Does the script pack need to be in the same behavior pack as my entity files?

flint sequoia
gusty scroll
#

What is the syntax I need to use in the subscribe int he .js file

flint sequoia
#

for the script event?

gusty scroll
#

const {id, initiator:player, message, sourceEntity:npc} = event

#

that is the line in the script you and jayden helped me with

#

But if I want to be able to just type the event in chat how would I cange it

#

or if I were to have the script event get run by a player animation how should I cange it.

flint sequoia
#

remove the initiator and change
sourceEntity:npc
to
sourceEntity:player
and remove the check for npc

but if you want to run the command in chat and use the script on another player that will be more complicated
you will need to pass player name with the command and get the player in the event

gusty scroll
#

Understood about not being as easy in chat to run on other players.

flint sequoia
#

if the cmd is from player animation
then the player is the sourceEntity

gusty scroll
#

so I could have const {id, message, sourceEntity:player} = event

flint sequoia
#

yeah

gusty scroll
#

Ok thanks

flint sequoia
#

np

gusty scroll
#

So if I wanted to have it generate an invId based on a tag the player has, how would I make that work.
Like if the player has tag survival when the /scriptevent gets run, I want the invId to be invSurvival. If they have the tag showcase then I want to id to be invShowcase and if the tag is games I want the id to be invGames

gusty scroll
#

@flint sequoia @midnight valve
So this is what I'm using right now. It is working for the invBkp
But when I try to save anything else I get

[Scripting][error]-TypeError: Native setter cannot be assigned null or undefined. at saveInv (inventory/inventory.js:90)
at <anonymous> (inventory/inventory.js:29)

This is line 90
const block = dimension.getBlock({ x: player_number, y: -63, z: zCord });

Why does that work for the saveBackupInv Function but not in the saveInv function

#

appologies, I don't know how to insert the code with the .js colors

flint sequoia
gusty scroll
#

So I've actually adjusted it so that I can have the inventories stored in a teacher only space. Player_number is a score that each player gets when they first join the world.
and zCord is for the z coordinate so basically I get 4 rows of inventories that the teacher can inspect. I will make this only accessible to the overworld and this space is in a ticking area covered by the teacher control room

#

Now I don't understand why the saveBackupInv function works but the saveInv function is throwing an error. They are essentially the exact same function except the saveInv one clears the player's inventory after saving it.

#

Ok never mind. I had a typo in there!!!!! it's invGames nor invGanes argh

flint sequoia
#

lol

gusty scroll
#

Thanks again for the help you guys provided to get me going on this!!!

flint sequoia
#

ur wlc

gusty scroll
gusty scroll
#

Here is where I'm asking about fixing the bug that locks things up after a cross dimension tp
#1242096768070717541 message

steel condor
steel condor
gusty scroll
#

I'm using the scriptevent command to trigger these
// /scriptevent tc:inv <load/save> <invId>

flint sequoia
#

/scriptevent id:test save invId

steel condor
#

how do i specify the id of the save

gusty scroll
#

well in the script I'm using I use
// /scriptevent tc:inv <load/save> <invId>
// /scriptevent tc:inv save DefaultGames
// /execute as @s[tag=!games,tag=!showcase] run scriptevent tc:inv save invSurvival
// /execute as @s[tag=!survival,tag=!showcase] run scriptevent tc:inv save invGames
// /execute as @s[tag=!games,tag=!survival] run scriptevent tc:inv save invShowcase
// /execute as @s[tag=!games,tag=!showcase] run scriptevent tc:inv save invBkp
// /execute at @s run scriptevent tc:inv save invBackup
// /execute as @s[tag=!games,tag=!showcase] run scriptevent tc:inv load invSurvival
// /execute as @s[tag=!survival,tag=!showcase] run scriptevent tc:inv load invGames
// /execute as @s[tag=!games,tag=!survival] run scriptevent tc:inv load invShowcase
// /execute at @s run scriptevent tc:inv load invBkp
// /execute at @s run scriptevent tc:inv load invBackup

#

because I'm testing for certain conditions to choose what to save or load

waxen rivet
#

what

flint sequoia
gusty scroll
#

Above are the commented out examples of the commands I use in game to have the different parts or options in the script run.

gusty scroll
#

Ok so if you read this whole thread, you should know that I'm working in Education so version 1.20.13 and my manifest has server 1.4.0 - beta
to simplify things you might want to start with the basic version of the script that @flint sequoia provided further up the thread rather than the more complex version I changed it to to suite my particular situation. Seeing as for my particular situation, I have a ticking area centered on 0 0 in the overworld and my script uses a combination of scores and coordinates based on which sort of inventory I'm saving.

steel condor
#

i see

flint sequoia
#

the script i sent was tested in both 1.10.0 beta and 1.11.0 beta

gusty scroll
#

I think this post is where @midnight valve got it working for me.
#1237061226547118172 message

#

And then I went messing with it a whole bunch for my particular use.

#

and here is the original post link where @flint sequoia shared the script #1237061226547118172 message

#

Player number is a score since each player gets one when they initially join the world and the zcord is simply a variable that changes based on which inventory is getting saved or loaded

#

Basically I made myself a teacher inventory inspection room.

steel condor
#

here's my solution:
system.afterEvents.scriptEventReceive.subscribe((event) => {
const { id, message, sourceEntity: player } = event

if (message.startsWith("a")) {
    const [type, id] = message.split(" ")
    update1(player)
} else if (message.startsWith("b")) {
    const [type, id] = message.split(" ")
    update2(player)
}

})

function update1(playa) {
const dimensions = ['overworld', 'nether', 'the_end'];
let tc = [];
dimensions.forEach(dim => {
const t = world.getDimension(dim).getEntities({ tags: ['transfer'] });
tc = tc.concat(t);
});
const fromInventory = playa.getComponent(EntityComponentTypes.Inventory);
const toInventory = tc[0].getComponent(EntityComponentTypes.Inventory);
let slotId = 0
system.run(() => {
for (let slotId = 0; slotId < 36; slotId++)
fromInventory.container.moveItem(slotId, slotId, toInventory.container);
})

}

function update2(playb) {
const dimensions = ['overworld', 'nether', 'the_end'];
let tc = [];
dimensions.forEach(dim => {
const t = world.getDimension(dim).getEntities({ tags: ['transfer'] });
tc = tc.concat(t);
});
const fromInventory = tc[0].getComponent(EntityComponentTypes.Inventory);
const toInventory = playb.getComponent(EntityComponentTypes.Inventory);
let slotId = 0
system.run(() => {
for (let slotId = 0; slotId < 36; slotId++)
fromInventory.container.moveItem(slotId, slotId, toInventory.container);
})

}

glass solstice
#

@gusty scroll

#

Im tryna make one rn lmao dm me or join my discord in my description

#

Il lyk if i finish it

gusty scroll
#

Ok, I know this is necroposting but I'm back and trying to update this script to work with version 1,21,05
It appears that the equipment slots have changed but I'm not quite sure what things have changed to.

#

content log is sending me these
[Scripting][error]-TypeError: cannot read property 'getEquipment' of undefined at saveBackupInv (inventory/inventory.js:81)
at <anonymous> (inventory/inventory.js:37)

[Scripting][error]-TypeError: cannot read property 'getEquipment' of undefined at saveInv (inventory/inventory.js:132)
at <anonymous> (inventory/inventory.js:43)

it is sort of working in that it will save the general inventory and hotbar but it isn't saving the armor or sheild slots and that seems to be stopping it from applying the tags and it isn't working to load the inventory back again at all currently.

midnight valve
#

in most versions the equippable component is just "equippable" so that may fix it. basically just replace this

//equipment
  const Chest = player.getComponent("equipment_inventory").getEquipment("chest");
  blockRest.setItem(9, Chest);
  const Feet = player.getComponent("equipment_inventory").getEquipment("feet");
  blockRest.setItem(10, Feet);
  const Head = player.getComponent("equipment_inventory").getEquipment("head");
  blockRest.setItem(11, Head);
  const Legs = player.getComponent("equipment_inventory").getEquipment("legs");
  blockRest.setItem(12, Legs);
  const Offhand = player.getComponent("equipment_inventory").getEquipment("offhand");
  blockRest.setItem(13, Offhand);

With this

//equipment
  const Chest = player.getComponent("equippable").getEquipment("chest");
  blockRest.setItem(9, Chest);
  const Feet = player.getComponent("equippable").getEquipment("feet");
  blockRest.setItem(10, Feet);
  const Head = player.getComponent("equippable").getEquipment("head");
  blockRest.setItem(11, Head);
  const Legs = player.getComponent("equippable").getEquipment("legs");
  blockRest.setItem(12, Legs);
  const Offhand = player.getComponent("equippable").getEquipment("offhand");
  blockRest.setItem(13, Offhand);

and anywehere else using the equippable component just swap the id of the component to "equippable"

gusty scroll
#

Oh, sorry. Originally I was on v1.20.10 and using server 1.4.0 beta and server ui 1.2.0 beta
Now I'm on v1.21.05 and server 1.12.0 beta and server ui 1.2.0 beta

gusty scroll
#

hum, first try didn't work. Let me just get out of the game since I don't always trust reload when things are not working right.

#

Hum, still getting this
[Scripting][error]-TypeError: Native type conversion failed. Function argument [0] expected type: EquipmentSlot at saveInv (inventory/inventory.js:132)
at <anonymous> (inventory/inventory.js:43)

knotty mist
#

Chest

#

uppercase 1st letter

gusty scroll
worthy drift
#

what is the script that works?

gusty scroll
#

it is working in education v1.21.05 with server 1.11.0 stable

#

I create an InventoryRoom down at the bottom of the overworld.

worthy drift
#

thx

gusty scroll
#

Welcome

gusty scroll
#

Ok so I decided to add a "default" inventory option in case players don't have anything yet for games or showcase but now it is giving me an error.
[Scripting][error]-TypeError: cannot read property 'container' of undefined at <anonymous> (inventory/inventory.js:220)
I'm having trouble figuring out what I messed up.

gusty scroll
#

The script seems to be working, I just really don't like seeing the error as I'm trying to fix everything in my pack.

wise charmBOT
#

Debug result for [code](#1237061226547118172 message)

Compiler Result

Compiler found 0 errors.

Lint Result

ESLint results:

inventory.js

14:51 error 'Container' is defined but never used @typescript-eslint/no-unused-vars

14:62 error 'BlockSignComponent' is defined but never used @typescript-eslint/no-unused-vars

29:12 error 'type' is assigned a value but never used @typescript-eslint/no-unused-vars

37:12 error 'type' is assigned a value but never used @typescript-eslint/no-unused-vars

42:12 error 'type' is assigned a value but never used @typescript-eslint/no-unused-vars

51:9 error 'playerInv' is assigned a value but never used @typescript-eslint/no-unused-vars

83:9 error 'playerInv' is assigned a value but never used @typescript-eslint/no-unused-vars

179:3 warning The /clear command can be fully replaced with the Container.clearAll api in the @minecraft/server module. See https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/container#clearall for more information. minecraft-linting/avoid-unnecessary-command

218:3 warning The /clear command can be fully replaced with the Container.clearAll api in the @minecraft/server module. See https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/container#clearall for more information. minecraft-linting/avoid-unnecessary-command

gusty scroll
#

FYI, the above is for education stable v1.21.05
using server 1.11.0 stable

gusty scroll
#

I think I found the error and fixed it but I'm too busy at the moment to double check till I get back home.

#

Been working on this stuff in very short broken up bits of time which is of course a bit less efficient every time I forget where I was or what I was trying to do.

flint sequoia
#

let me know if it is still there

gusty scroll
#

Seems to be fixed. Thanks.

fluid sparrow
#

how to use the save inventory i cant figure it out