Another world inventory skript

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

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

Status
Not open for further replies.

iTzFlo

Member
Aug 6, 2019
4
0
1
24
I'm looking for a skript by having a different inventory in each world
the inventory should be saved
 
set {%player%.inventory.world1} to player's serialized inventory


restore inventory of player to {%player%.inventory.world1}
 
I don't think that serializing inventory works correctly right now. Thankfully there is a way to do it with skript-json. Correct me if I am wrong about the serialization not working, I just tested and it doesn't work properly... I made a snippet on the skript hub discord server for serializing inventories with skript-json (Tested on Skript 2.3.6+ / skript-json)

code_language.skript:
function jsonSerializeInventoryContents(inventory: inventory) :: String:
    set {_size} to {_inventory}'s amount of rows * 9
    set {_c} to 0
    loop {_size} times:
        add slot {_c} of {_inventory} to {_items::*}
        add 1 to {_c}
    if "%{_inventory}%" is not "inventory of <none>":
        loop 5 times:
            set {_i} to slot {_c} of {_inventory}
            if "%{_i}%" is "<none>":
                add air to {_items::*}
            else:
                add slot {_c} of {_inventory} to {_items::*}
            add 1 to {_c}
            delete {_i}
    return {_items::*}'s serialized json form

function jsonSetSerializedInventoryContents(inventory: inventory, json: string, includeArmor: boolean):
    map json {_json} to {_items::*}
    set {_c} to 1
    loop ({_inventory}'s amount of rows * 9) times:
        set slot {_c}-1 of {_inventory} to {_items::%{_c}%}
        add 1 to {_c}
    if "%{_inventory}%" is not "inventory of <none>":
        if {_includeArmor} is true:
            loop 5 times:
                set slot {_c}-1 of {_inventory} to {_items::%{_c}%}
                add 1 to {_c}

In your case, you can save the player's inventory with the functions above in the world change event.

code_language.skript:
on player world change:
    set {%uuid of player%.Inventory.%past changed world%} to jsonSerializeInventoryContents(player's inventory)
    clear player's inventory
    jsonSetSerializedInventoryContents(player's inventory, {%uuid of player%.Inventory.%event-world%}, true)
When a player changes worlds, it will save their inventory for that world and load up their inventory for the world they are going to.
 
Last edited:
Status
Not open for further replies.