How to cancel inventory slot click through hotkey

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

Status
Not open for further replies.
Mar 27, 2022
3
0
1
So basically when you cancel an inventory slot click, u can't click on the slot and pick it up to your cursor. But however you still can move the item using hotkey. For example:
On inventory click:
If index of event-slot is 8:
Cancel event
In this skript you can't click on the 9th slot of your inventory, but you can move it out if your mouse cursor on another slot and use your 9th slot hotkey, it will swap the item to the event slot. Is there any ways to fix this?
 
So basically when you cancel an inventory slot click, u can't click on the slot and pick it up to your cursor. But however you still can move the item using hotkey. For example:
On inventory click:
If index of event-slot is 8:
Cancel event
In this skript you can't click on the 9th slot of your inventory, but you can move it out if your mouse cursor on another slot and use your 9th slot hotkey, it will swap the item to the event slot. Is there any ways to fix this?
Try my test gui to see if you have the same problem
Code:
function gui(s: string, r: number, p: player):
    open chest inventory with {_r} rows named "%{_s}%" to {_p}

command /shop:
    trigger:
        gui("&l&eShop", 1, player)
        set slot 0 of player's current inventory to iron sword named "&l&9Skills"

on inventory click:
    #check if the clicked inventory is the one we just created
    if name of event-inventory is "&l&eShop":
        #cancel the clicking. This makes the Item unstealable
        cancel event
        if index of event-slot is 0:
            close the player's inventory
            gui("&l&eSkills", 1, player)
            set slot 0 of player's current inventory to feather named "&9Double Jumps" with lore "&l&eprice: &l&a$25"
    if name of event-inventory is "&l&eSkills":
        cancel event
        if index of event-slot is 0:
            set {doublejump::%player%} to {doublejump::%player%} + 10
            message "&eYou buy 10 double jumps. Double jump: &a%{doublejump::%player%}%"
 
Try my test gui to see if you have the same problem
Code:
function gui(s: string, r: number, p: player):
    open chest inventory with {_r} rows named "%{_s}%" to {_p}

command /shop:
    trigger:
        gui("&l&eShop", 1, player)
        set slot 0 of player's current inventory to iron sword named "&l&9Skills"

on inventory click:
    #check if the clicked inventory is the one we just created
    if name of event-inventory is "&l&eShop":
        #cancel the clicking. This makes the Item unstealable
        cancel event
        if index of event-slot is 0:
            close the player's inventory
            gui("&l&eSkills", 1, player)
            set slot 0 of player's current inventory to feather named "&9Double Jumps" with lore "&l&eprice: &l&a$25"
    if name of event-inventory is "&l&eSkills":
        cancel event
        if index of event-slot is 0:
            set {doublejump::%player%} to {doublejump::%player%} + 10
            message "&eYou buy 10 double jumps. Double jump: &a%{doublejump::%player%}%"
Well i will test it tomorrow but as im seeing this, i am pretty sure this code cancels all slots of inventory click. What i want is just to cancel 1 single slot and not be able to move the item in that slot at all. But i will test it tomorrow to check it out. Thank you for your time!
 
Well i will test it tomorrow but as im seeing this, i am pretty sure this code cancels all slots of inventory click. What i want is just to cancel 1 single slot and not be able to move the item in that slot at all. But i will test it tomorrow to check it out. Thank you for your time!
try this instead
Code:
on inventory click:
    if name of event-inventory is "&l&eShop":
        if index of event-slot is 0:
            cancel event
or you can also do this
Code:
on inventory click:
    if name of event-inventory is "&l&eShop":
        if index of event-slot is not 0:
            cancel event
 
As i said in the thread, you still can move the item in this slot using hotkey. Just get the cursor on another slot and use the slot hotkey and it will change. I want a way to prevent that.
[doublepost=1648473271,1648421555][/doublepost]Ok so i found out a way to make it almost impossible to move an item out of an specific slot. Anyways i will send the code down below for people who had the same problem as me and don't know how to fix it:
Code:
on inventory click:
    if event-inventory is player's inventory:
        if click type is number key:
            if event-slot is not (the slot you want to lock):
                if event-slot is air:
                    set {switcheditem.%player%} to air
                else:
                    set {switcheditem.%player%} to event-item
                wait 1 tick
                if event-item is (the item that is locked in the slot):
                    set event-slot to {switcheditem.%player%}
                    set slot (the slot you want to lock) of player's inventory to (the item that is locked in the slot)
        if event-slot is (the slot you want to lock):
            cancel event
        if cursor slot of player is (the item that is locked in the slot):
            set cursor slot of player to {switcheditem.%player%}
            set slot (the slot you want to lock) of player's inventory to (the item that is locked in the slot)
on drop:
    if event-item is (the item that is locked in the slot):
        cancel event
If there is any problem with this code please let me know.
Thanks for your time
 
Status
Not open for further replies.