Solved Click Event Failing in Some Cases

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

Status
Not open for further replies.

A248

Member
Jan 31, 2017
43
3
8
21
Skript and all addons: Skript v2.2-dev23. SkQuery v3.21.4, skRayFall v1.9.7, TuSKe v1.6.7, SharpSK v1.6.0, RandomSK v2.7.1, SkStuff v1.6.2.

MC Version: 1.8.8.

code_language.skript:
on leftclick holding mushroom stew:
    if player has permission "arim.soup":
        set {_prot} to spawnProt(player)
        if {_prot} is false:
            sendOwner("&5%name of player% &3–– &anormal soup leftclick.")
            soup(player)
    else:
        set player's action bar to "&cSoups disabled in this world"

on rightclick holding mushroom stew:
    if player has permission "arim.soup":
        set {_prot} to spawnProt(player)
        if {_prot} is false:
            sendOwner("&5%name of player% &3–– &anormal soup rightclick.")
            soup(player)
    else:
        set player's action bar to "&cSoups disabled in this world"

function soup(p: player):
    clear tool of {_p}
    heal {_p} by 1 hearts
    remove regeneration from {_p}
    apply potion of regeneration of tier 3 to {_p} for 3 seconds
    play orb pickup at {_p} with pitch 1
Note: The sendOwner function is irrelevant. It works fine. It is simply helpful to debug stuff, which is why I have used it to try to debug this script.

Errors on reload: None
Console Errors: None

Troubleshooting:
Have tried the docs.
Have searched the forums. Perhaps I am using the wrong search words?
I have also tried using "on leftclick on any block:" or "on leftclick on a block:" to replace the leftclick event.


Full Description of Error:
If I leftclick (holding soup) normally, looking at the air, everything works fine. Similarly, if I rightclick (holding soup) normally while looking at a block within range, everything still works fine. Soup works in those cases.

However, when I right click (holding soup) in the air, the soup applies regeneration, healing, sends the sendOwner notification, and plays the sound, though it does not remove the soup.
Also, when I left click (holding soup) on a block within range, nothing happens. The event does not fire, I believe.
Note: I tested this in adventure mode. I will need the script to work while players are in adventure mode.

code_language.skript:
#Entire function works when left clicking in the air OR righ tclicking a block
function soup(p: player): #Entire function does not work when left clicking a block
    clear tool of {_p} #Does not work while right click the air
    heal {_p} by 1 hearts
    remove regeneration from {_p}
    apply potion of regeneration of tier 3 to {_p} for 3 seconds
    play orb pickup at {_p} with pitch 1

When clicking with soup:
  • Normal leftclick in air: Works fine.
  • Normal rightclick in air: Soup is not removed ('clear tool of {_p}' does not work)
  • Normal leftclick on block: Nothing happens. Event is not fired.
  • Normal rightclick on block: Works fine.
EDIT: Earlier, I had said that rightclicks in the air worked, while rightclicks on a block failed to clear the item. It is actually the other way around – When you rightclick the air, the soup is not cleared. When you rightclick a block, the soup is cleared. The leftclick event is experiencing the same errors. No edits regarding the leftclick event.
[doublepost=1500303385,1500219677][/doublepost]UPDATE

Creating a new issue at github.com/bensku/Skript/etc.





SOLUTION

Rightclicking bug – I have simply removed rightclicking from the script. Soups are left-click only.

Leftclick bug fix:

1. I have set the players to survival and disabled block-editing.
2. I am using 2 events – on leftclick and on block damage.
on block damage fills the void that on leftclick leaves when players leftclick a block.
 
Last edited:
Skript and all addons: Skript v2.2-dev23. SkQuery v3.21.4, skRayFall v1.9.7, TuSKe v1.6.7, SharpSK v1.6.0, RandomSK v2.7.1, SkStuff v1.6.2.

MC Version: 1.8.8.

code_language.skript:
on leftclick holding mushroom stew:
    if player has permission "arim.soup":
        set {_prot} to spawnProt(player)
        if {_prot} is false:
            sendOwner("&5%name of player% &3–– &anormal soup leftclick.")
            soup(player)
    else:
        set player's action bar to "&cSoups disabled in this world"

on rightclick holding mushroom stew:
    if player has permission "arim.soup":
        set {_prot} to spawnProt(player)
        if {_prot} is false:
            sendOwner("&5%name of player% &3–– &anormal soup rightclick.")
            soup(player)
    else:
        set player's action bar to "&cSoups disabled in this world"

function soup(p: player):
    clear tool of {_p}
    heal {_p} by 1 hearts
    remove regeneration from {_p}
    apply potion of regeneration of tier 3 to {_p} for 3 seconds
    play orb pickup at {_p} with pitch 1
Note: The sendOwner function is irrelevant. It works fine. It is simply helpful to debug stuff, which is why I have used it to try to debug this script.

Errors on reload: None
Console Errors: None

Troubleshooting:
Have tried the docs.
Have searched the forums. Perhaps I am using the wrong search words?
I have also tried using "on leftclick on any block:" or "on leftclick on a block:" to replace the leftclick event.


Full Description of Error:
If I leftclick (holding soup) normally, looking at the air, everything works fine. Similarly, if I rightclick (holding soup) normally while looking at a block within range, everything still works fine. Soup works in those cases.

However, when I right click (holding soup) in the air, the soup applies regeneration, healing, sends the sendOwner notification, and plays the sound, though it does not remove the soup.
Also, when I left click (holding soup) on a block within range, nothing happens. The event does not fire, I believe.
Note: I tested this in adventure mode. I will need the script to work while players are in adventure mode.

code_language.skript:
#Entire function works when left clicking in the air OR righ tclicking a block
function soup(p: player): #Entire function does not work when left clicking a block
    clear tool of {_p} #Does not work while right click the air
    heal {_p} by 1 hearts
    remove regeneration from {_p}
    apply potion of regeneration of tier 3 to {_p} for 3 seconds
    play orb pickup at {_p} with pitch 1

When clicking with soup:
  • Normal leftclick in air: Works fine.
  • Normal rightclick in air: Soup is not removed ('clear tool of {_p}' does not work)
  • Normal leftclick on block: Nothing happens. Event is not fired.
  • Normal rightclick on block: Works fine.
EDIT: Earlier, I had said that rightclicks in the air worked, while rightclicks on a block failed to clear the item. It is actually the other way around – When you rightclick the air, the soup is not cleared. When you rightclick a block, the soup is cleared. The leftclick event is experiencing the same errors. No edits regarding the leftclick event.
[doublepost=1500303385,1500219677][/doublepost]UPDATE

Creating a new issue at github.com/bensku/Skript/etc.


I can't particularly give you any useful information because you're running a relatively older server version.

That being said, I tested your code, and I found it was working fine, other than left clicking blocks while in adventure mode. This is most likely because Skript listens for events. In adventure mode, Minecraft prevents the event from happening, so there's nothing for Skript to hear.

I am unable to reproduce the error of the soup not being removed when rightclicking in air, though; it's working fine on my end.
 
I have merely removed the rightclick event from my script, set the players to survival, and used on block damage in addition to on leftclick.

Will mark as solved.
 
Status
Not open for further replies.