Solved Saving virtual chest to variable

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

xKukiMonster

Member
Mar 14, 2020
2
0
0
24
When I am reloading script it says:
Code:
an inventory cannot be saved, i.e. the contents of the variable {save::backup::%{_player}%::%{_index}%} will be lost when the server stops.
I know it can't be saved by Skript, but is there way to save virtual inventory? Maybe on unload loop for inventory size, then set {save::backup::%{_player}%::%{_index}%::items::%{_slot}%} to loop-item and on load do it opposite way? I have no idea, I plan to have average of 10 players on server every day, and auto save is pretty often (2 minutes) so this {_index} variable can be very high(of course not infinity, there is data wipe everyday at 00:00), what results in bad performance(I think that works that way). If someone could help me with that, I would very appreciate this :emoji_slight_smile:
 
When I am reloading script it says:
Code:
an inventory cannot be saved, i.e. the contents of the variable {save::backup::%{_player}%::%{_index}%} will be lost when the server stops.
I know it can't be saved by Skript, but is there way to save virtual inventory? Maybe on unload loop for inventory size, then set {save::backup::%{_player}%::%{_index}%::items::%{_slot}%} to loop-item and on load do it opposite way? I have no idea, I plan to have average of 10 players on server every day, and auto save is pretty often (2 minutes) so this {_index} variable can be very high(of course not infinity, there is data wipe everyday at 00:00), what results in bad performance(I think that works that way). If someone could help me with that, I would very appreciate this :emoji_slight_smile:
Serialize contents of inventory into a string and save it that way. This can be done with skript-json or skript-mirror.
 
Serialize contents of inventory into a string and save it that way. This can be done with skript-json or skript-mirror.

Can you give me more details about that way? It's kinda hard to understand you properly with my english level :emoji_stuck_out_tongue:
How I am supposed to serialize contents of inventory?
 
Can you give me more details about that way? It's kinda hard to understand you properly with my english level :emoji_stuck_out_tongue:
How I am supposed to serialize contents of inventory?
Using skript-json, example for chest gui / player inventory. Im not sure how well this works on newer versions. I think I made this for 1.8.8. I can't remember.
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}

command /saveplayerinv:
    trigger:
        set {Inv.%uuid of player%} to jsonSerializeInventoryContents(player's inventory)
        message "&aInventory saved. Retrieving in 3 seconds."
        clear player's inventory
        wait 3 seconds
        jsonSetSerializedInventoryContents(player's inventory, {Inv.%uuid of player%}, true)
 
Last edited:
Status
Not open for further replies.