Solved Player gets a item

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

Neelix_bear

Active Member
Aug 11, 2023
215
7
18
Hey, so I want to do something when a player gets a item I've tried googling and looking through skunity docs but all I find is "on pickup" but I want it to happen whenever they get a item whether it was from a /give command a skript using "give player 5 diamonds" or picking it up this is the code I tried before I realized "on pickup" only works when a player PICKS up a item obviously
Code:
on pickup:
    if 10 <= amount of diamonds in player's inventory:
        broadcast "DIAMONDS!!!"
 
Heres an code example, although obviously It's not the best solution to loop all players every 2 ticks. Other ways would be to use a while loop or listen for each event a player gets an item (on command "give", on pickup, on inventory click etc etc).

Heres my example with the every 2 ticks:
Python:
every 2 ticks:
    loop all players:
        set {_diamonds} to amount of diamonds in loop-player's inventory
    wait a tick
    amount of diamonds in loop-player's inventory > {_diamonds}
    send "Seems like you received diamonds" to loop-player
Def not the best solution and also may be a bit buggy if the server lags
 
Heres an code example, although obviously It's not the best solution to loop all players every 2 ticks. Other ways would be to use a while loop or listen for each event a player gets an item (on command "give", on pickup, on inventory click etc etc).

Heres my example with the every 2 ticks:
Python:
every 2 ticks:
    loop all players:
        set {_diamonds} to amount of diamonds in loop-player's inventory
    wait a tick
    amount of diamonds in loop-player's inventory > {_diamonds}
    send "Seems like you received diamonds" to loop-player
Def not the best solution and also may be a bit buggy if the server lags
I use free server hosting so definitely gonna lag but I'll try the code
 
So, I ran into another problem, im trying to make a autocompresser skript but its clearing the compressed items too heres the code i tried
Code:
if 64 <= amount of emeralds in loop-player's inventory:
                    remove 64 emeralds from loop-player
                    give 1 emerald of silk touch with all flags hidden named "&a&lCompressed Emerald" to loop-player
this is in a repeating function for every 0.5 seconds and it loops all players to get loop-player
 
So, I ran into another problem, im trying to make a autocompresser skript but its clearing the compressed items too heres the code i tried
Code:
if 64 <= amount of emeralds in loop-player's inventory:
                    remove 64 emeralds from loop-player
                    give 1 emerald of silk touch with all flags hidden named "&a&lCompressed Emerald" to loop-player
this is in a repeating function for every 0.5 seconds and it loops all players to get loop-player
This is because you're removing 64 of any type of emeralds every 0.5 seconds if they have more than 64. This includes the compressed ones. Try this:
Code:
remove all emeralds where [name of input does not contain "&a&lCompressed Emerald"] from player
I'm not 100% sure it's going to work but SkUnity parser returns no errors. I am unable to test at this time.

Another thing you need to look at is your condition. It will count the compressed emeralds in that amount of emeralds in player's inventory. Adding the same in-line condition should fix that as well.
Code:
if 64 <= amount of emeralds where [name of input does not contain "&a&lCompressed Emerald"] in loop-player's inventory:
 
Last edited:
This is because you're removing 64 of any type of emeralds every 0.5 seconds if they have more than 64. This includes the compressed ones. Try this:
Code:
remove all emeralds where [name of input does not contain "&a&lCompressed Emerald"] from player
I'm not 100% sure it's going to work but SkUnity parser returns no errors. I am unable to test at this time.

Another thing you need to look at is your condition. It will count the compressed emeralds in that amount of emeralds in player's inventory. Adding the same in-line condition should fix that as well.
Code:
if 64 <= amount of emeralds where [name of input does not contain "&a&lCompressed Emerald"] in loop-player's inventory:
i got this error
1709859509377.png
 
JavaScript:
loop all items in loop-player's inventory:
    loop-item is emerald:
        name of loop-item does not contain "&a&lCompressed Emerald":
            remove 64 of loop-item from player
 
JavaScript:
loop all items in loop-player's inventory:
    loop-item is emerald:
        name of loop-item does not contain "&a&lCompressed Emerald":
            remove 64 of loop-item from player
k so this gives no errors but just removes the item and when I add a give thing it just gives removes and loops again
 
k so this gives no errors but just removes the item and when I add a give thing it just gives removes and loops again
Strange. So I checked docs and "remove enchanted <item> from player" seems to work so this might work.
JavaScript:
remove 64 of unenchanted emerald from player
 
k so this gives no errors but just removes the item and when I add a give thing it just gives removes and loops again
Weird. Maybe this will work?
JavaScript:
loop all items in player's inventory:
    loop-item is emerald:
        name of loop-item does not contain "&a&lCompressed Emerald":
            loop-item is not enchanted:
                remove 64 of loop-item from player
 
Weird. Maybe this will work?
JavaScript:
loop all items in player's inventory:
    loop-item is emerald:
        name of loop-item does not contain "&a&lCompressed Emerald":
            loop-item is not enchanted:
                remove 64 of loop-item from player
k did the same thing but i think i know why loop-item isnt all the data its just the item (emerald) so when you run "remove 64 of loop-item (emerald) from player" it removes the enchanted one too
 
Ok, so i kinda figured it out but heres the code lol
Code:
every 0.5 seconds:
    loop all players:
        if loop-player has permission "skript.autocompress":
            if {ac::%loop-player's uuid%} is true:
                if 1 <= amount of diamonds in loop-player's inventory:
                    loop amount of diamonds in loop-player's inventory times:
                        remove 1 diamond from loop-player
                        give 1 echo shard named "money" to loop-player
                if 64 <= amount of echo shards named "money" in loop-player's inventory:
                    remove 64 echo shards named "money" from loop-player
                    give 1 recovery compass to loop-player
                if 64 <= amount of recovery compass in loop-player's inventory:
                    remove 64 recovery compass from loop-player
                    give 1 bell named "&c&lBELL" to loop-player
                if 64 <= amount of bells named "&c&lBELL" in loop-player's inventory:
                    remove 64 bells named "&c&lBELL" from loop-player
                    give 1 fletching table named "&eFLETCH!!!" to loop-player
                if 64 <= amount of emeralds in loop-player's inventory:
                    remove 64 emeralds from loop-player
                    give 1 emerald block of silk touch with all flags hidden named "&a&lCompressed Emerald Block" to loop-player
                if 64 <= amount of emerald blocks of silk touch with all flags hidden named "&a&lCompressed Emerald Block" in loop-player's inventory:
                    remove 64 emerald block of silk touch with all flags hidden named "&a&lCompressed Emerald Block" from loop-player
                    give 1 crying obsidian of silk touch with all flags hidden named "&5&lCompressed Sad Obsidian" with lore "&6&lIt lost its family" to loop-player
                if 64 <= amount of crying obsidian of silk touch with all flags hidden named "&5&lCompressed Sad Obsidian" with lore "&6&lIt lost its family" in loop-player's inventory:
                    remove 64 crying obsidian of silk touch with all flags hidden named "&5&lCompressed Sad Obsidian" with lore "&6&lIt lost its family" from loop-player
                    give 1 obsidian of silk touch with all flags hidden named "&5&lCompressed Happy Obsidian" with lore "&6&lYou reunited it with its family!!!" to loop-player