Solved Daily Lootchest - each player own loot

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

Lutrex

Member
Jul 20, 2022
12
0
1
18
Hey, I'm currently doing a daily lootchest for my server. Every player can get new stuff there every day.
The problem with my current script is that when you click on the box, new loot comes up and any player can take it. Can anyone help me that each player has separate DailyChests?


Code:
on load:
    clear {dailychest::*}
    add 9 honey bottle to {dailychest::*}
    add 13 coal to {dailychest::*}
    add 6 apple to {dailychest::*}
    add 11 pumpkin pie to {dailychest::*}
    add 13 oak log to {dailychest::*}
    add 2 obsidian to {dailychest::*}
    add 10 gold ingot to {dailychest::*}
    add 17 bricks to {dailychest::*}
    add 10 arrow to {dailychest::*}
    add 1 ender pearl to {dailychest::*}
    add 3 golden apple to {dailychest::*}                   
    add 1 iron sword to {dailychest::*}
    add 6 xp bottle to {dailychest::*}       
    add 1 iron axe to {dailychest::*}
    add 4 slimeball to {dailychest::*}

every 40 seconds:
    if "%now%" contains "00:00":
        loop all players:
            set {lootchest.%uuid of loop-player%} to false
        loop all offline players:
            set {lootchest.%uuid of loop-offline player%} to false

on rightclick:
    if location of event-block is {lootchest}:
        if {lootchest.%uuid of player%} is false:
            loop all blocks in radius 3 of player:
                if loop-block is a chest:
                    clear loop-block's inventory
                    set {lootchest.%uuid of player%} to true
                    set {_items} to a random number between 4 and 8
                    loop {_items} times:
                        set {_randomitems} to random element out of {dailychest::*}
                        set {_slots} to random integer between 0 and 27
                        set slot {_slots} of loop-block's inventory to {_randomitems}
        else:
            stop
    else:
        stop
 
Maybe instead of placing the items in the chest just open a chest gui to the player with the items for him to take.
 
to save:
Code:
    set {_slot} to 0 #we save starting from slot 0
    loop 26 times: #we save 26 slots (depends on how much row u have)
        set {chest::%{_slot}%::%player's uuid%} to slot {_slot} of current inventory of player
        add 1 to {_slot}
to restaure :
Code:
    set {_slot} to 0
    loop 26 times:
        set slot {_slot} of current inventory of player to {chest::%{_slot}%::%player's uuid%}
        add 1 to {_slot}
 
something like that

Code:
on rightclick:
    if location of event-block is {lootchest}:
        if {lootchest.%uuid of player%} is false:
            cancel event
            set {lootchest.%uuid of player%} to true
            open virtual chest inventory named "lootchest" with size 4 to player
            #do your  thing with the loot here
        else:
            loop 26 times:
                set slot {_slot} of current inventory of player to {chest::%{_slot}%::%player's uuid%}
                add 1 to {_slot}
     else:
          stop

on inventory close:
    if event-inventory's name contains "lootchest":
         set {_slot} to 0 #we save starting from slot 0
         loop 26 times: #we save 26 slots (depends on how much row u have)
             set {chest::%{_slot}%::%player's uuid%} to slot {_slot} of current inventory of player
             add 1 to {_slot}
 
Have it now, it works too. Only if you close the inventory and open the chest again is it empty. Means it wasn't saved?

Code:
on rightclick:
    if location of event-block is {lootchest}:
        if {lootchest.%uuid of player%} is false:
            cancel event
            set {lootchest.%uuid of player%} to true
            loop all blocks in radius 1 of {lootchest}:
                if loop-block is a chest:
                    set {_dailychest} to a new chest inventory with 3 row with name "&e&lDaily Chest"
                    set {_items} to a random number between 4 and 8
                    loop {_items} times:
                        set {_randomitems} to random element out of {dailychest::*}
                        set {_slots} to random integer between 0 and 27
                        set slot {_slots} of {_dailychest} to {_randomitems}
                        open {_dailychest} to player
        else:
            loop 26 times:
                set slot {_slot} of current inventory of player to {chest::%{_slot}%::%player's uuid%}
                add 1 to {_slot}
    else:
        stop
 
on inventory close:
    if event-inventory's name contains "&e&lDaily Chest":
        set {_slot} to 0 #we save starting from slot 0
        loop 26 times: #we save 26 slots (depends on how much row u have)
            set {chest::%{_slot}%::%player's uuid%} to slot {_slot} of current inventory of player
            add 1 to {_slot}
 
Oops that's my mistake, before line 16 add this: " set {_slot} to 0"
also line 12: 3 row inv, slot 27 doesnt exist (last index of row 3 is 26)
 
doesn't work :emoji_astonished:
It is set to true and therefore no longer works. How can I fix this?


Code:
every 40 seconds:
    if "%now%" contains "00:00":
        loop all players:
            set {lootchest.%uuid of loop-player%} to false
        loop all offline players:
            set {lootchest.%uuid of loop-offline player%} to false

on rightclick:
    if location of event-block is {lootchest}:
        if {lootchest.%uuid of player%} is false:
            cancel event
            set {lootchest.%uuid of player%} to true
            loop all blocks in radius 1 of {lootchest}:
                if loop-block is a chest:
                    set {_dailychest} to a new chest inventory with 3 row with name "&e&lDaily Chest"
                    set {_items} to a random number between 4 and 8
                    loop {_items} times:
                        set {_randomitems} to random element out of {dailychest::*}
                        set {_slots} to random integer between 0 and 26
                        set slot {_slots} of {_dailychest} to {_randomitems}
                        open {_dailychest} to player
        else:
            set {_slot} to 0
            loop 26 times:
                set slot {_slot} of current inventory of player to {chest::%{_slot}%::%player's uuid%}
                add 1 to {_slot}
    else:
        stop
 
on inventory close:
    if event-inventory's name contains "&e&lDaily Chest":
        set {_slot} to 0 #we save starting from slot 0
        loop 26 times: #we save 26 slots (depends on how much row u have)
            set {chest::%{_slot}%::%player's uuid%} to slot {_slot} of current inventory of player
            add 1 to {_slot}
 
Can you post the whole skript ? I will try it myself and try to figure it out when im at home
 
Hey, so the problem was because we don't open a gui which makes sens I guess
Code:
        else:
            cancel event
            set {_dailychest} to a new chest inventory with 3 row with name "&a&lDaily Chest"
            open {_dailychest} to player
            set {_slot} to 0
            loop 26 times:
                set slot {_slot} of current inventory of player to {chest::%{_slot}%::%player's uuid%}
                add 1 to {_slot}

For L3 and L4, it can be done in one line (wasn't sure if it needed an addon or not, just try it, always better to be able to compact.
Code:
open virtual chest inventory named "&a&lDaily Chest" with size 3 to player

also another mistake from me
Code:
            loop 26 times:
needs to be 27 times (on both), instinctively did that because of slots starting from 0
 
Last edited:
omg i think it works. Thank you!!

One more question, but I don't think it's possible.. Can you animate the chest when you open and close it? To make it look "real"?
 
Code:
on rightclick:
    if location of event-block is {lootchest}:
        play open animation on event-block
        if {lootchest.%uuid of player%} is false:

Code:
on inventory close:
    if event-inventory's name contains "&e&lDaily Chest":
        set {_slot} to 0 #we save starting from slot 0
        loop 27 times: #we save 27 slots (depends on how much row u have)
            set {chest::%{_slot}%::%player's uuid%} to slot {_slot} of current inventory of player
            add 1 to {_slot}
            play close animation on block at {lootchest}
 
Code:
on rightclick:
    if location of event-block is {lootchest}:
        play open animation on event-block
        if {lootchest.%uuid of player%} is false:

Code:
on inventory close:
    if event-inventory's name contains "&e&lDaily Chest":
        set {_slot} to 0 #we save starting from slot 0
        loop 27 times: #we save 27 slots (depends on how much row u have)
            set {chest::%{_slot}%::%player's uuid%} to slot {_slot} of current inventory of player
            add 1 to {_slot}
            play close animation on block at {lootchest}
thank you!!! <3
 
Status
Not open for further replies.