1. 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 comminuty!

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

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Save / Restore Inventory

Discussion in 'Snippets' started by ShaneBee, Nov 21, 2018.

  1. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Sep 7, 2017
    Likes Received:
    This is just a quick snippet for saving and restoring a player's inventory.
    I have been asked a few times how to do this, so here is a simple method.

    NOTE: This has been tested on Spigot 1.12.2 and Skript 2.2 dev37c (May or may not work on older versions)
    Code (Skript):
    1. command /inv <text> <player=%player%>:
    2.     trigger:
    3.         if arg-1 is "save":
    4.             loop 41 times:
    5.                 set {inventory::%uuid of arg-2%::slot::%loop-number%} to slot loop-number - 1 of arg-2
    6.             clear inventory of player
    7.         else if arg-1 is "restore":
    8.             loop 41 times:
    9.                 set slot loop-number -1 of arg-2 to {inventory::%uuid of arg-2%::slot::%loop-number%}
    10.         else:
    11.             send "&6Correct Usage: &b/inv <save/restore> [player]"

    Here are some easy to use functions:
    Code (Skript):
    1. function loadInv(p: player):
    2.     set {_u} to uuid of {_p}
    3.     loop 41 times:
    4.         set slot loop-number -1 of inventory of {_p} to {inventory::%{_u}%::slot::%loop-number%}
    6. function saveInv(p: player):
    7.     set {_u} to uuid of {_p}
    8.     loop 41 times:
    9.         set {inventory::%{_u}%::slot::%loop-number%} to slot loop-number -1 of inventory of {_p}
    #1 ShaneBee, Nov 21, 2018
    Last edited: May 2, 2019

Share This Page