Solved Help with a skript

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

Jolt

New Member
Oct 19, 2019
9
0
0
24
Category: command

Suggested name: Invsee

Spigot/Skript Version:

What I want: I want an invsee command that will be able to see the inventory of an offline player

Ideas for commands: /iv

Ideas for permissions: invsee.use

When I'd like it by: Any time would be amazing
 
Category: command

Suggested name: Invsee

Spigot/Skript Version:

What I want: I want an invsee command that will be able to see the inventory of an offline player

Ideas for commands: /iv

Ideas for permissions: invsee.use

When I'd like it by: Any time would be amazing
I'll make it. Give me a couple hours and I'll send it in this post. :emoji_slight_smile:
[doublepost=1571526751,1571521684][/doublepost]This should work on all Spigot and Skript versions from 1.8.8-1.14.4
Report any bugs by messaging me on discord: AsuDev#0714
Code is attached to post and so is a file you can download.

There is one CAVEAT about this script:
I did not use NBT file (player data files) editing for this, rather it goes by saving player's inventories when they leave. This means that to edit a player's offline inventory, they have to have joined and left the server at least once after this script has been loaded.

code_language.skript:
# ##############################################################################################################

# Inventory See for Online/Offline Players
# Made by AsuDev
# Report bugs by messaging me on discord: AsuDev#0714

# There is one CAVEAT:
# I did not use NBT inventory editing for this, rather it goes by saving a players inventories.
# This means that to edit a player's offline inventory, they have to have joined and left the server
# at least once after this script has been loaded.

# ##############################################################################################################

# Save a players inventory when they leave the server
function saveInventoryPlayer(p: player):
    set {_uuid} to uuid of {_p}
    delete {offlineInventory.%{_uuid}%::*}
    set {_counter} to 0
    loop 36 times:
        add slot {_counter} of {_p}'s inventory to {offlineInventory.%{_uuid}%::*}
        add 1 to {_counter}

# Save the offline player's inventory after edits
function saveInventoryOfflinePlayer(inv: inventory, p: offline player):
    set {_uuid} to uuid of {_p}
    delete {offlineInventory.%{_uuid}%::*}
    set {_counter} to 0
    loop 36 times:
        add slot {_counter} of {_inv} to {offlineInventory.%{_uuid}%::*}
        add 1 to {_counter}

# Retrieve the offline players inventory when they join
function retrievePlayerInventory(inv: inventory, p: offline player):
    set {_uuid} to uuid of {_p}
    set {_counter} to 1
    loop 36 times:
        set slot {_counter}-1 of {_inv} to {offlineInventory.%{_uuid}%::%{_counter}%}
        add 1 to {_counter}

# Join event for updating a players inventory and also checks to see if someone is editing their offline inventory
on join:
    size of {offlineInventory.%uuid of player%::*} is not 0
    retrievePlayerInventory(player's inventory, player)
    loop all players:
        if metadata value "Invsee" of loop-player is "%player%":
            set metadata value "CancelInvsee" of loop-player to "True"
            send "&c%player% &7just logged in, your invsee has been updated." to loop-player
            wait 10 ticks
            close loop-player's inventory
            open player's inventory to loop-player

# Quit event for saving the players inventory and also checks to see if someone is editing their live inventory
on quit:
    saveInventoryPlayer(player)
    loop all players:
        if loop-player's current inventory is player's inventory:
            set metadata value "CancelInvsee" of loop-player to "True"
            send "&c%player% &7just logged in, your invsee has been updated." to loop-player
            wait 10 ticks
            close loop-player's inventory
            make loop-player execute command "iv %player%"

# Inventory close event for editing offline player inventories
on inventory close:
    metadata value "Invsee" of player is set
    if metadata value "CancelInvsee" of player is not set:
        set {_p} to metadata value "Invsee" of player
        set {_p} to "%{_p}%" parsed as offline player
        saveInventoryOfflinePlayer(player's current inventory, {_p})
    delete metadata value "Invsee" of player
    delete metadata value "CancelInvsee" of player

# Main invsee command for players/offline players
command /iv [<offline player>]:
    aliases: invsee
    permission: invsee.use
    permission message: &cYou do not have permission to execute this command.
    trigger:
        if arg 1 is set:
            if arg 1 is online:
                open arg 1's inventory to player
            else:
                if arg 1 has played before:
                    if size of {offlineInventory.%uuid of arg 1%::*} is not 0:
                        set metadata value "Invsee" of player to "%arg 1%"
                        open chest with 4 rows named "%arg 1%'s Inventory" to player
                        retrievePlayerInventory(player's current inventory, arg 1)
                        while name of player's current inventory is "%arg 1%'s Inventory":
                            saveInventoryOfflinePlayer(player's current inventory, arg 1)
                            wait 3 ticks
                    else:
                        message "&cThat player has played before, but they haven't joined since this script was added so there is no saved inventory data..."
                else:
                    message "&cThat player has not played before."
        else:
            message "&fView a player or offline player's inventory."
            message "&f/invsee <player>"
 

Attachments

  • invsee.sk
    3.9 KB · Views: 204
  • Like
Reactions: Jolt