Solved Cooldown on custom 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!

20Spaces

Member
Apr 26, 2024
21
3
3
14
Ok so I found this code to make a cooldown on custom items:

Code:
on left click:
    send "Work clcik" to player
    if player's held item is {customitems::dashrod}:
        if diference between now and {%player's uuid%.dashrod.lastUsed} is less than 5 seconds:
            message "&fWait 5 seconds before use again!" to player
        else:
            send "Work dash" to player
            push player forwards with velocity 2
            play mob spawner flames at player

However when I try to run it I get the following to errors:


[01:38:45 INFO]: [Skript] Line 12: (dashFav12.sk)
[01:38:45 INFO]: Can't understand this condition: 'diference between now and {%player's uuid%.dashrod.lastUsed} is less than 5 seconds'
[01:38:45 INFO]: Line: if diference between now and {%player's uuid%.dashrod.lastUsed} is less than 5 seconds:
[01:38:45 INFO]:
[01:38:45 INFO]: [Skript] Line 14: (dashFav12.sk)
[01:38:45 INFO]: 'else' has to be placed just after another 'if' or 'else if' section
[01:38:45 INFO]: Line: else:
 
Last edited:
That will be resolved if you correct your statement because it will then be following a valid if statement.

A better method for cooldowns (requires skript 2.8+) is to use the item cooldown expression. While this won't effect an item using an on right click event, you can make the event stop if the player's item is on cooldown, adding an easily adjustable cooldown with no need for global variables like this that works for any item.
 
That will be resolved if you correct your statement because it will then be following a valid if statement.

A better method for cooldowns (requires skript 2.8+) is to use the item cooldown expression. While this won't effect an item using an on right click event, you can make the event stop if the player's item is on cooldown, adding an easily adjustable cooldown with no need for global variables like this that works for any item.
Ah thanks for the advise. Marked as solved
 
  • Like
Reactions: NixTer
Alright, cool beans.
Sorry for pinging you, but I tested the code a bit more and while I didn't get any errors the cooldown doesn't seem to be working. Here my full code:


Code:
on load:
    set {customitems::dashrod} to fishing rod named "&1Dash Rod" with lore "&2Right click to dash, (5/5 uses)"
    set {customitems::flyboots} to golden boots named "&2Fly Boots" with lore "&1Allow the player to double jump"

command items <text>:
    trigger:
        give player {customitems::%arg-1%}

on left click:
    send "Work clcik" to player
    if player's held item is {customitems::dashrod}:
        if difference between now and {%player's uuid%.dashrod.lastUsed} is less than 5 seconds:
            message "&fWait 5 seconds before use again!" to player
        else:
            send "Work dash" to player
            push player forwards with velocity 2
            play mob spawner flames at player

Again, very sorry
 
you hae to set the last used variable to now at the start of the else section.

and as I said, I recommend using item cooldown.
 
you hae to set the last used variable to now at the start of the else section.

and as I said, I recommend using item cooldown.
Ok so if I was to use item cooldown I would do this:

Code:
on left click:
    send "Work clcik" to player
    if player's held item is {customitems::dashrod}:
        if player item cooldown for {customitems::dashrod} is not 0:
            cancel the event
        else:
            send "Work dash" to player
            push player forwards with velocity 2
            play mob spawner flames at player
            set item cooldown of player's tool for player to 2 seconds

Now ignoring the fact the my if syntax is incorrect is this the approach you were suggesting?
 
uhhhh yeah kinda but instead you'd put

Code:
if player has <variable or item> on cooldown:
    stop
else:
    #stuff

Also put the set item cooldown thing at the start of the else section
 
uhhhh yeah kinda but instead you'd put

Code:
if player has <variable or item> on cooldown:
    stop
else:
    #stuff

Also put the set item cooldown thing at the start of the else section
Alright this time it actually worked. Thanks so much!!!!
 
  • Like
Reactions: NixTer