Save virtual chests inventory with location

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Diabolux13

Member
Nov 2, 2023
1
0
1
Hello everyone !

First post for me, be indulgent haha

I explain my problem to you:

On my Minecraft server I want to create a system of safes chest when you click on a particular block (here end stone to start). There will be a whole system of access for certain players who own the chest and non-access for other players with unlocking systems. Here's for context. However, to begin with, I can't seem to get these virtual chests created, I don't know how to save the inventories. I had thought about playing with location variables (because the safes once placed cannot be moved, but what I did does not work. I am attaching the code (which may be wrong from A to Z . If you could direct me that would be great! Thanks in advance

Excuse my bad english :emoji_wink:

Code:
options:
  Coffre1: Coffre niveau 1

function restoreCoffre(inv: inventory, player: player, loc: location):
    loop chest size of {_inv} times:
        set slot loop-number -1 of {_inv} to {Coffre::p::%{_player}%::%{_loc}%::Items::%loop-number%}
    clear {Coffre::p::%{_player}%::%{_loc}%::Items::*}

function saveCoffre(inv: inventory, player: player, loc: location):
    clear {Coffre::p::%{_player}%::%{_loc}%::Items::*}
    loop chest size of {_inv} times:
        add slot loop-number -1 of {_inv} to {Coffre::p::%{_player}%::%{_loc}%::Items::*}
    clear {Coffre::p::%{_player}%::loc::Inv}

on inventory close:
    set {_inv} to event-inventory
    set {_loc} to event-location
    if {_inv} is {Coffre::p::%player%::%event-location%::Inv}:
        saveCoffre({_inv}, player, {_loc})

        
on right click on end stone:   
    set {_inv} to chest with 1 row named "{@Coffre1}"
    set {_loc} to event-location
    set {Coffre::p::%player%::loc::Inv} to {_inv}
    restoreCoffre({_inv}, player, {_loc})
    open {_inv} for player
 
Firstly, you’ll want to assign variables to a player’s uuid instead of just the player as if a player chanegus their username; their data will be wiped/taken by someone who uses their old username. Also, I think your issue is that you don’t use a variable for location on the right click on endstone event meaning it saves improperly.
 
Last edited: