Solved Inventory Saving

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

Maezukie

Member
May 21, 2018
15
0
1
code_language.skript:
command /Spectator:
    aliases: spectate
    trigger:
        if {Spec::%player%} is not set:
            set {Spec::%player%} to 1
            play sound "block.anvil.place" at player
            set the player's game mode to creative
            send "{@P} &7Spectator mode &aenabled"
            if {Spectate} is set:
                teleport player to {Spectate}
                send "{@P} &7Sent to &5spectate &7location"
            else:
                send "{@P} &cSpectate location not set, tell an admin"
            loop all items in the inventory of player:
                add loop-item to {SpecI:%player%::*}
                remove loop-item from the player
        else:
            delete {Spec::%player%}
            play sound "block.anvil.place" at player
            set the player's game mode to survival
            send "{@P} &7Spectator mode &cdisabled"
            execute console command "/spawn %player%"
            set {_slot} to 1
            loop {SpecI:%player%::*}:
                add 1 to {_slot}
                set slot {_slot} of player's inventory to loop-value
                delete {SpecI:%player%::*}
                stop

im trying to make it so it deletes and saves the inventory on the command toggle ON but on the toggle OFF i want it to restore the inventory. so far it only restores 1 item
 
its because you have "stop" at the end of your loop, so it stops the loop, preventing it from adding the rest of the item to the inventory
 
Overall this is a horrible skript and ill send you my version of it that i made for someone else for you and everyone else who reads this
if i can figure out how to send code xD
 
Overall this is a horrible skript and ill send you my version of it that i made for someone else for you and everyone else who reads this
if i can figure out how to send code xD
Its super easy... click the little box beside the film strip, looks like a plus... then click code, and paste your code into that box
 
code_language.skript:
options:
    prefix: &7[&bHi&7]
command /spectator:
    aliases: /spec , /spectate
    trigger:
        if {spec::%player%} isn't set:
            set {spec::%player%} to true
            play sound "block.anvil.place" at the player
            set the player's gamemode to creative
            send "{@prefix} &7Spectator mode &aenabled"
            loop integers from 0 to 35:
                add 1 to {index}
                set {specs:%player%::%{index}%} to slot loop-value of player
                set slot loop-value of player to air
            set {helmet::%player%} to player's helmet
            set {chestplate::%player%} to player's chestplate
            set {leggings::%player%} to player's leggings
            set {boots::%player%} to player's boots
            set {offhand::%player%} to slot 40 of player's inventory
            set slot 40 of player's inventory to air
            set player's helmet to air
            set player's chestplate to air
            set player's leggings to air
            set player's boots to air
            teleport player to {Spectate}
        else:
            delete {spec::%player%}
            play sound "block.anvil.place" at the player
            set the player's gamemode to survival
            send "{@prefix} &7Spectator mode &cdisabled"
            execute console command "/spawn %player%"
            set {_slot} to 0
            loop {specs:%player%::*}:
                set slot {_slot} of player's inventory to loop-value
                add 1 to {_slot}
            set slot 40 of player's inventory to {offhand::%player%}
            set player's helmet to {helmet::%player%}
            set player's chestplate to {chestplate::%player%}
            set player's leggings to {leggings::%player%}
            set player's boots to {boots::%player%}
            delete {specs:%player%::*}
            stop
saves the inventory per slot for slot 0-35 (main inv) then saves the offhand and armor seperate
sets back the main inv and then off-hand and armor. basically way better of what you had because
1. it does armor and off-hand too properly
2. it even does it if the slot is air. so everything will return the way you left it
 
  • Like
Reactions: ShaneBee
Status
Not open for further replies.