Cancel event in main inventory (Can't move items)

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

    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!

ctrlcheeb

New Member
Aug 4, 2023
6
0
1
Hi, I was just making a quick skript that opens a gui for a player where they can place an item and the skript checks to see if it's correct.
However I was trying to make it so that the player is unable to move things around in the chest inventory that opens for the player but can still move things around in their main inventory.
However when trying this I can disable and enable items being moved around in the opened GUI but the players actual inventory also seems to cancel on any event of moving items not allowing them to place items in the opened GUI.


Code:
on inventory click:
    if name of event-inventory is "&8&lPlace Coins here":
        # cancel event
        if index of event-slot = 49:
            if slot 22 of player's current inventory is sunflower named "&eLOST COIN":
                close player's inventory
                send message "amazing"
            else:
                close player's inventory
                send message "wrong"
        else:
    else:

I've been messing around with different variations of this but cannot seem to get it to work. Any help would be greatly appreciated
 
I still haven't figured it out quite yet but it seems when I say something like

"if index of event-slot = 12:
cancel event"

Even though it is in the if statement of being in the event-inventory named "&8&lPlace Coins here" the cancel event also applies to the players default inventory and that seems to be the issue if anyone knows how to fix this that would be great
 
The way to fix this issue (I have faced it before) is to understand what cancel event does. When using a cancel event expression, you’re not cancelling a single event but instead the entire lines of code after it. To resolve your issue, move the cancel event line to the very bottom of your code (After the if and else statements, line 10 in the code you’ve posted).
 
The way to fix this issue (I have faced it before) is to understand what cancel event does. When using a cancel event expression, you’re not cancelling a single event but instead the entire lines of code after it. To resolve your issue, move the cancel event line to the very bottom of your code (After the if and else statements, line 10 in the code you’ve posted).
Thanks for the advice I tried to do that on the code snippet I said but no matter where it always seemed to cancel nothing or both the gui and player's inventory.

I had another attempt at it earlier on since I needed slots 22 and 49 to be interacted with.


Code:
on inventory click:
    if name of event-inventory is "&8&lPlace Coins here":
        # cancel event
        if index of event-slot = 49:
            if slot 22 of player's current inventory is sunflower named "&eLOST COIN":
                close player's inventory
                send message "amazing"
            else:
                close player's inventory
                send message "wrong"
        else if index of event-slot is between 0 and 21:
            if name of event-inventory is "&8&lPlace Coins here":
                cancel event
        else if index of event-slot is between 21 and 48:
            if name of event-inventory is "&8&lPlace Coins here":
                cancel event
        else if index of event-slot is between 50 and 53:
            if name of event-inventory is "&8&lPlace Coins here":
                cancel event
    else:

If you would be so kind please could you explain where I would need to place the cancel events in here or how to modify it to only work with the opened GUI since I was struggling last time, thanks
 
Lol you put # cancel event there # means comment you silly goose. Do cancel event in the same place with no #