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!

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

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

Solved Inventory Saving

Discussion in 'Skript' started by Maezukie, Aug 3, 2018.

Tags:
Thread Status:
Not open for further replies.
  1. Maezukie

    Maezukie Member

    Joined:
    May 21, 2018
    Messages:
    15
    Likes Received:
    0
    Code (Skript):
    1.  
    2. command /Spectator:
    3.     aliases: spectate
    4.     trigger:
    5.         if {Spec::%player%} is not set:
    6.             set {Spec::%player%} to 1
    7.             play sound "block.anvil.place" at player
    8.             set the player's game mode to creative
    9.             send "{@P} &7Spectator mode &aenabled"
    10.             if {Spectate} is set:
    11.                 teleport player to {Spectate}
    12.                 send "{@P} &7Sent to &5spectate &7location"
    13.             else:
    14.                 send "{@P} &cSpectate location not set, tell an admin"
    15.             loop all items in the inventory of player:
    16.                 add loop-item to {SpecI:%player%::*}
    17.                 remove loop-item from the player
    18.         else:
    19.             delete {Spec::%player%}
    20.             play sound "block.anvil.place" at player
    21.             set the player's game mode to survival
    22.             send "{@P} &7Spectator mode &cdisabled"
    23.             execute console command "/spawn %player%"
    24.             set {_slot} to 1
    25.             loop {SpecI:%player%::*}:
    26.                 add 1 to {_slot}
    27.                 set slot {_slot} of player's inventory to loop-value
    28.                 delete {SpecI:%player%::*}
    29.                 stop
    30.  
    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

     
  2. Best Answer:
    Post #5 by DaakuBotto, Aug 3, 2018
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,010
    Likes Received:
    139
    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
     
  4. D

    Supporter

    Joined:
    Jul 25, 2018
    Messages:
    2
    Likes Received:
    1
    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
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,010
    Likes Received:
    139
    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
     
  6. D

    Supporter

    Joined:
    Jul 25, 2018
    Messages:
    2
    Likes Received:
    1
    Code (Skript):
    1. options:
    2.     prefix: &7[&bHi&7]
    3. command /spectator:
    4.     aliases: /spec , /spectate
    5.     trigger:
    6.         if {spec::%player%} isn't set:
    7.             set {spec::%player%} to true
    8.             play sound "block.anvil.place" at the player
    9.             set the player's gamemode to creative
    10.             send "{@prefix} &7Spectator mode &aenabled"
    11.             loop integers from 0 to 35:
    12.                 add 1 to {index}
    13.                 set {specs:%player%::%{index}%} to slot loop-value of player
    14.                 set slot loop-value of player to air
    15.             set {helmet::%player%} to player's helmet
    16.             set {chestplate::%player%} to player's chestplate
    17.             set {leggings::%player%} to player's leggings
    18.             set {boots::%player%} to player's boots
    19.             set {offhand::%player%} to slot 40 of player's inventory
    20.             set slot 40 of player's inventory to air
    21.             set player's helmet to air
    22.             set player's chestplate to air
    23.             set player's leggings to air
    24.             set player's boots to air
    25.             teleport player to {Spectate}
    26.         else:
    27.             delete {spec::%player%}
    28.             play sound "block.anvil.place" at the player
    29.             set the player's gamemode to survival
    30.             send "{@prefix} &7Spectator mode &cdisabled"
    31.             execute console command "/spawn %player%"
    32.             set {_slot} to 0
    33.             loop {specs:%player%::*}:
    34.                 set slot {_slot} of player's inventory to loop-value
    35.                 add 1 to {_slot}
    36.             set slot 40 of player's inventory to {offhand::%player%}
    37.             set player's helmet to {helmet::%player%}
    38.             set player's chestplate to {chestplate::%player%}
    39.             set player's leggings to {leggings::%player%}
    40.             set player's boots to {boots::%player%}
    41.             delete {specs:%player%::*}
    42.             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 Like x 1
    • Informative Informative x 1
Thread Status:
Not open for further replies.
Loading...