Items on inventory open lock

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

Sympathischer

Member
Sep 18, 2022
14
0
1
24
I have a small problem and as soon as the player opens the inventory an item is deleted from the inventory and it should not be picked up again but the whole thing with opening the inventory doesn't work. I replaced it with clicking on the inventory for now, but I have a problem with picking up the item because it doesn't work because items are only written in lowercase by the script and also sometimes written completely differently like with leaves. Does anyone have an idea how to fix this?

Code:
on load:
    set {remove} to ""

on inventory click:
    set {_items::*} to all items of player
    set {_item} to random item out of {_items::*}
    add "%{_item}% , " to {remove}
    remove {_item} from all players
    broadcast "&8Du hast kein &c%{_item}%&8 mehr du bastard"

on pick up:
    if {remove} contain event-item's type:
    remove {_item} from all players

command /cock:
    trigger:
        broadcast "&4%{remove}%"
 
I have a small problem and as soon as the player opens the inventory an item is deleted from the inventory and it should not be picked up again but the whole thing with opening the inventory doesn't work. I replaced it with clicking on the inventory for now, but I have a problem with picking up the item because it doesn't work because items are only written in lowercase by the script and also sometimes written completely differently like with leaves. Does anyone have an idea how to fix this?

Code:
on load:
    set {remove} to ""

on inventory click:
    set {_items::*} to all items of player
    set {_item} to random item out of {_items::*}
    add "%{_item}% , " to {remove}
    remove {_item} from all players
    broadcast "&8Du hast kein &c%{_item}%&8 mehr du bastard"

on pick up:
    if {remove} contain event-item's type:
    remove {_item} from all players

command /cock:
    trigger:
        broadcast "&4%{remove}%"
One of the biggest issues I see is how you are saving the items. If you are to save something, let's say a number to a list and wish to reuse it later, you do not want to save it as a text.

Example:
add 1, 2 and 3 to {numbers::*} instead of:
add "1", "2", and "3" to {numbers::*}
Your second issue is that you are saving the item into a variable that only has one value. So, instead of {remove} having multiple values in a list like my example above, it instead has one continuously long text value with commas (Which is undesirable). To fix this, simply change the format of the line which you add the item to {remove} to be only of an item.
Example 2:
add iron axe to {weapons::*}
You do not need to add commas to this when you add it to your variable and also, you have a minor third issue. Variables which start with an underscore (Example: {_test}) Can only be used once per action (Example: {_test} being used for a command will ONLY be used for that command alone and no other events). So that means your on pick up event removes nothing from any player. Hopefully this explanation with the issues with your code will be helpful in resolving those issues! :emoji_grinning: