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

AverageGamer590

New Member
Jun 27, 2021
6
0
1
Australia
Nothing is saving, when I set something it doesn't save.
Code:
function registerCrate(id:number, name:string, l:location, key:item, items:object, chances:object):
  clear {crates::%{_id}%::*}
  set {crates::%{_id}%} to {_id}
  set {crates::%{_id}%::name} to {_name}
  set {crates::%{_id}%::location} to {_location}
  set {crates::%{_id}%::key} to {_key}
  set {crates::%{_id}%::items} to {_items}
  set {crates::%{_id}%::chances} to {_chances}
  set {crates::locations} to 1
  add {_l} to {crates::locations::*}


function useKey(p:player, l:location, key:item):
  loop {crates::*}:
    if {crates::%loop-index%::key} = {_key}:
      set {_id} to loop-index-1
      set {_chancenum} to 0
      set {_random} to random integer between 1 and 100
      loop {crates::%{_id}%::items::*}:
        add index loop-value-2 of {crates::%{_id}%::chance} to {_chancenum}
        if {_random} < {_chancenum}:
          give {crates::%{_id}%::items} to {_p}
        
      send "%{_items}%" to {_p}
      # set {_random} to random integer in between 1 and the length of {_items::*}
      give random element out of {_items::*} to {_p}

function targetblock(p:player) :: location:
    return location of target block of {_p}

on right click:
  if {crates::locations::*} contains targetblock(player):
    cancel event
    useKey(player, targetblock(player), player's tool)

on right click:
  if {ccLocation::%uuid of player%} is set:
    if player has permission "crate.create":
      cancel event
      send "&aBlock selected" to player
      clear {ccLocation::%uuid of player%}
      set {createData::%uuid of player%::location} to targetblock(player)
      set {_gui} to a new chest inventory with 1 row named "&6Create Crate"
      set slot 4 of {_gui} to grass named "&6Click me to set a block"
      set slot 2 of {_gui} to oak sign named "&6Click to change name"
      if {crateData::%uuid of player%::name} is set:
        set slot 2 of {_gui} to oak sign named "%{crateData::%uuid of player%::name}%"
      set slot 6 of {_gui} to bedrock named "&6Click to set key"
      if {createData::%uuid of player%::key} is set:
        set slot 6 of {_gui} to {createData::%uuid of player%::key}
      set slot 8 of {_gui} to lime glass pane named "&aClick to confirm"
      open {_gui} to the player
  if {ccItem::%uuid of player%} is set:
    if player has permission "crate.create":
      cancel event
      send "&aKey selected" to player
      clear {ccItem::%uuid of player%}
      set {createData::%uuid of player%::key} to player's held item
      set {_gui} to a new chest inventory with 1 row named "&6Create Crate"
      set slot 4 of {_gui} to grass named "&6Click me to set a block"
      set slot 2 of {_gui} to oak sign named "&6Click to change name"
      if {crateData::%uuid of player%::name} is set:
        set slot 2 of {_gui} to oak sign named "%{crateData::%uuid of player%::name}%"
      set slot 6 of {_gui} to bedrock named "&6Click to set key"
      if {createData::%uuid of player%::key} is set:
        set slot 6 of {_gui} to {createData::%uuid of player%::key}
      set slot 8 of {_gui} to lime glass pane named "&aClick to confirm"
      open {_gui} to the player
      

on chat:
  if {ccName::%uuid of player%} is set:
    if player has permission "crate.create":
      cancel event
      clear {ccName::%uuid of player%}
      set {createData::%uuid of player%::name} to message
      send "&aName set to %{crateData::%uuid of player%::*}% " to player
      set {_gui} to a new chest inventory with 1 row named "&6Create Crate"
      set slot 4 of {_gui} to grass named "&6Click me to set a block"
      set slot 2 of {_gui} to oak sign named "&6Click to change name"
      if {crateData::%uuid of player%::name} is set:
        set slot 2 of {_gui} to oak sign named "%{crateData::%uuid of player%::name}%"
      set slot 6 of {_gui} to bedrock named "&6Click to set key"
      if {createData::%uuid of player%::key} is set:
        set slot 6 of {_gui} to {createData::%uuid of player%::key}
      set slot 8 of {_gui} to lime glass pane named "&aClick to confirm"
      open {_gui} to the player
      
command /crate create:
  permission: crate.create
  trigger:
    clear {crateData::%uuid of player%::*}
    set {createData::%uuid of player%} to 1
    set {_gui} to a new chest inventory with 1 row named "&6Create Crate"
    set slot 4 of {_gui} to grass named "&6Click me to set a block"
    set slot 2 of {_gui} to oak sign named "&6Click to change name"
    if {crateData::%uuid of player%::name} is set:
      set slot 2 of {_gui} to oak sign named "%{crateData::%uuid of player%::name}%"
    set slot 6 of {_gui} to bedrock named "&6Click to set key"
    if {createData::%uuid of player%::key} is set:
      set slot 6 of {_gui} to {createData::%uuid of player%::key}
    set slot 8 of {_gui} to lime glass pane named "&aClick to confirm"
    open {_gui} to the player

on inventory click:
  if name of event-inventory is "&6Create Crate":
    cancel event
    if event-inventory != player's inventory:
      if name of event-slot is "&6Click me to set a block":
        set {ccLocation::%uuid of player%} to 1
        close player's inventory
        send "&6Right click a block to select it"
      if name of event-slot is "&6Click to change name":
        set {ccName::%uuid of player%} to 1
        close player's inventory
        send "&6Type the name of the crate"
      if event-slot is 6:
        set {ccItem::%uuid of player%} to 1
        close player's inventory
        send "&6Right click while holding an item to select it"
      if name of event-slot is "&aClick to confirm":
        close player's inventory
        send "&aCrate registered with id %{crateData::%uuid of player%::*}%"
        registerCrate((length of {crates::*} ? 1), ({crateData::%uuid of player%::name}), ({crateData::%uuid of player%::location}), ({crateData::%uuid of player%::key}),(air), (air))
[doublepost=1626518539,1626485297][/doublepost]The thing that isn't saving is {createData::%uuid of player%::*}. When you use /crate create and change the name it will say <none>
 
Status
Not open for further replies.