Solved Cooldown Help

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

SMH

New Member
Sep 19, 2021
5
0
1
21
I have a throwable tnt skript but i wanted to make that have a cooldown so i merged my another skript that had a cooldown with this skript but i couldn't get it to work, any help ?


Code:
on leftclick holding tnt:
  if name of event-item is "&1&lDinamit":
    set {_waited} to difference between {cooldown::%player%::epearl} and now
    if {_waited} is less than 45 seconds:
    send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 45 seconds and {_waited}% &d&lbeklemelisin!" to player
    cancel the event
         else:
            player has 1 tnt
        set {cooldown::%player%::epearl} to now
            spawn a primed tnt 1 meter above the player
            push the spawned entity in direction of player at speed 0.9
            push the spawned entity upwards at speed 0.2
            remove 1 tnt from player
 
Last edited:
I'm looking into this code too much, but the simple problem could be that the variable "{cooldown::%player%::epearl}" is not set, so it can't really be a difference of anything, thus "{_waited}" is not set.
 
You should try this:

Code:
on leftclick:
  if player's held item is tnt named "&1&lDinamit":
    if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
       set {_waited} to 46 seconds
    if {_waited} is less than 45 seconds:
       send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 45 seconds and {_waited}% &d&lbeklemelisin!" to player
       cancel the event
    else:
       player has 1 tnt
       set {cooldown::%player%::epearl} to now
       spawn a primed tnt 1 meter above the player
       push the spawned entity in direction of player at speed 0.9
       push the spawned entity upwards at speed 0.2
       remove 1 tnt from playe
I didn't test it but I don't see why it wouldn't work.
Also you should probably use "player's uuid" instead of "player", you could try to find out more about that one. All I know is that if someone changes their name their stats will reset if you didn't use their uuid.
 
You should try this:

Code:
on leftclick:
  if player's held item is tnt named "&1&lDinamit":
    if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
       set {_waited} to 46 seconds
    if {_waited} is less than 45 seconds:
       send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 45 seconds and {_waited}% &d&lbeklemelisin!" to player
       cancel the event
    else:
       player has 1 tnt
       set {cooldown::%player%::epearl} to now
       spawn a primed tnt 1 meter above the player
       push the spawned entity in direction of player at speed 0.9
       push the spawned entity upwards at speed 0.2
       remove 1 tnt from playe
I didn't test it but I don't see why it wouldn't work.
Also you should probably use "player's uuid" instead of "player", you could try to find out more about that one. All I know is that if someone changes their name their stats will reset if you didn't use their uuid.

hmmm didn't work, it says nothing when you left click where as before with the original code, it would only say the cooldown error message with none as the timer
 
hmmm didn't work, it says nothing when you left click where as before with the original code, it would only say the cooldown error message with none as the timer
Weird, try the one you did originally but replace
Code:
    set {_waited} to difference between {cooldown::%player%::epearl} and now
with
Code:
    if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
       set {_waited} to 46 seconds
 
Weird, try the one you did originally but replace
Code:
    set {_waited} to difference between {cooldown::%player%::epearl} and now
with
Code:
    if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
       set {_waited} to 46 seconds

Now, it always gives the cooldown message with 0 seconds as the timer and, the time doesnt pass its stuck there, still good progress

this is what i went with

Code:
on leftclick holding tnt:
  if name of event-item is "&1&lDinamit":
        if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
    set {_waited} to 46 seconds
    if {_waited} is less than 45 seconds:
    send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 46 seconds and {_waited}% &d&lbeklemelisin!" to player
    cancel the event
         if else:
            player has 1 tnt
            set {cooldown::%player%::epearl} to now
            spawn a primed tnt 1 meter above the player
            push the spawned entity in direction of player at speed 0.9
            push the spawned entity upwards at speed 0.2
            remove 1 tnt from player
 
Now, it always gives the cooldown message with 0 seconds as the timer and, the time doesnt pass its stuck there, still good progress

this is what i went with

Code:
on leftclick holding tnt:
  if name of event-item is "&1&lDinamit":
        if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
    set {_waited} to 46 seconds
    if {_waited} is less than 45 seconds:
    send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 46 seconds and {_waited}% &d&lbeklemelisin!" to player
    cancel the event
         if else:
            player has 1 tnt
            set {cooldown::%player%::epearl} to now
            spawn a primed tnt 1 meter above the player
            push the spawned entity in direction of player at speed 0.9
            push the spawned entity upwards at speed 0.2
            remove 1 tnt from player
I see why this happends, {_waited} gets set to 46 seconds and then you get the difference between 46 and {_waited} which is 0 since 46 = 46.
Since it's 46 seconds which is not less than 45 seconds it shouldn't send this message though so I can only assume that you forgot to use spaces after the "if" line? Can you send the code with the exact spaces/tabs you used in the code? Because if this is how it actually looks like you need to change it to this:

Code:
on leftclick holding tnt:
  if name of event-item is "&1&lDinamit":
    if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
       set {_waited} to 46 seconds
    if {_waited} is less than 45 seconds:
       send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 46 seconds and {_waited}% &d&lbeklemelisin!" to player
    cancel the event
    player has 1 tnt
    set {cooldown::%player%::epearl} to now
    spawn a primed tnt 1 meter above the player
    push the spawned entity in direction of player at speed 0.9
    push the spawned entity upwards at speed 0.2
    remove 1 tnt from player
 
I see why this happends, {_waited} gets set to 46 seconds and then you get the difference between 46 and {_waited} which is 0 since 46 = 46.
Since it's 46 seconds which is not less than 45 seconds it shouldn't send this message though so I can only assume that you forgot to use spaces after the "if" line? Can you send the code with the exact spaces/tabs you used in the code? Because if this is how it actually looks like you need to change it to this:

Code:
on leftclick holding tnt:
  if name of event-item is "&1&lDinamit":
    if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
       set {_waited} to 46 seconds
    if {_waited} is less than 45 seconds:
       send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 46 seconds and {_waited}% &d&lbeklemelisin!" to player
    cancel the event
    player has 1 tnt
    set {cooldown::%player%::epearl} to now
    spawn a primed tnt 1 meter above the player
    push the spawned entity in direction of player at speed 0.9
    push the spawned entity upwards at speed 0.2
    remove 1 tnt from player

Tried with the latest one you posted, still didn't work like i want, let me clarify again, this is a throwing tnt skript where you can throw a tnt with left click but i want the tnt to be able to thrown every 45 seconds, the latest ones results are i can throw the tnt but simply there is no cooldown and i can throw infinitely
 
Tried with the latest one you posted, still didn't work like i want, let me clarify again, this is a throwing tnt skript where you can throw a tnt with left click but i want the tnt to be able to thrown every 45 seconds, the latest ones results are i can throw the tnt but simply there is no cooldown and i can throw infinitely
If the issue is that the tnt gets thrown infinitely but the cooldown message does work it's once again because of spaces/tabs, at the momment even when it does send the message it still throws the tnt because it doesn't depend on any of the if/else statements, try changing it to this:

Code:
on leftclick holding tnt:
  if name of event-item is "&1&lDinamit":
    if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
       set {_waited} to 46 seconds
    if {_waited} is less than 45 seconds:
       send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 46 seconds and {_waited}% &d&lbeklemelisin!" to player
    else:
       cancel the event
       player has 1 tnt
       set {cooldown::%player%::epearl} to now
       spawn a primed tnt 1 meter above the player
       push the spawned entity in direction of player at speed 0.9
       push the spawned entity upwards at speed 0.2
       remove 1 tnt from player
 
If the issue is that the tnt gets thrown infinitely but the cooldown message does work it's once again because of spaces/tabs, at the momment even when it does send the message it still throws the tnt because it doesn't depend on any of the if/else statements, try changing it to this:

Code:
on leftclick holding tnt:
  if name of event-item is "&1&lDinamit":
    if {cooldown::%player%::epearl} is set:
       set {_waited} to difference between {cooldown::%player%::epearl} and now
    else:
       set {_waited} to 46 seconds
    if {_waited} is less than 45 seconds:
       send "&d&lTekrar &c&lDinamit &d&latman için &a&l%difference between 46 seconds and {_waited}% &d&lbeklemelisin!" to player
    else:
       cancel the event
       player has 1 tnt
       set {cooldown::%player%::epearl} to now
       spawn a primed tnt 1 meter above the player
       push the spawned entity in direction of player at speed 0.9
       push the spawned entity upwards at speed 0.2
       remove 1 tnt from player

ah, finally, edited this around and it finally works, thanks :emoji_smile:
 
Status
Not open for further replies.