1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Anyone know how to put a cooldown every time you click (LMB)

Discussion in 'Skript' started by JadeInnit1, Oct 3, 2022.

  1. JadeInnit1

    JadeInnit1 Member

    Joined:
    Oct 3, 2022
    Messages:
    14
    Likes Received:
    0
    Hello, Ultra beginner noob here. I was just testing out skript the past day and wanted to make an explosion happen in front of the player (already done that) And to stop people from spamming it I want a 1-second delay between each press of the LMB. This is prob simple and my tiny brain can't handle it so I thought I'd ask you, smart people.

    Code so far is.

    Skript version: 2.6.2.
    Skript author: Quiettee (me)
    on leftclick holding wooden shovel:
    cooldown:1
    create an explosion of force 1 10 block infront of player

    Any and all help would be much appreciated :emoji_slight_smile:
     
  2. Best Answer:
    Post #2 by lotzy, Oct 4, 2022
  3. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    138
    Likes Received:
    22
    Code (Text):
    1. on leftclick holding wooden shovel:
    2.   if {-p::%uuid of player%::cooldown} is not set:
    3.     set {-p::%uuid of player%::cooldown} to true
    4.     create an explosion of force 1 10 block infront of player
    5.     wait ? ticks
    6.     delete {-p::%uuid of player%::cooldown}

    Code (Text):
    1. on leftclick holding wooden shovel:
    2.   if unix timestamp of now is greater than 0+{-p::%uuid of player%::cooldown}:
    3.     set {-p::%uuid of player%::cooldown} to unix timestamp of now+%cooldown?%
    4.     create an explosion of force 1 10 block infront of player
     
    • Like Like x 1
  4. JadeInnit1

    JadeInnit1 Member

    Joined:
    Oct 3, 2022
    Messages:
    14
    Likes Received:
    0
    Mind If I ask what the line "if {-p::%uuid of player%::cooldown} is not set:" and "set {-p::%uuid of player%::cooldown} to true" does
     
  5. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    138
    Likes Received:
    22
    well we set some variable so we can keep track of the delay. In fact, if the variable is set, then the user still has a delay, if not set, then he can already use the item
    I apologize if something is not quite correctly described, I do not know English perfectly
    --- Double Post Merged, Oct 4, 2022, Original Post Date: Oct 4, 2022 ---
    As for the variable itself, usually the '-' symbol is put in the 'Skript' config so that variables with this prefix are not saved on disk, only in RAM. That is, after a server restart, all player delays will not be saved
    Value in Skript's config
    Code (Text):
    1.      
    2.     default:
    3.      
    4.         type: CSV
    5.      
    6.         pattern: (?!-).* # <== here
    7.      
    8.         file: ./plugins/Skript/variables.csv
    9.      
    10.         backup interval: 0 hours
    --- Double Post Merged, Oct 4, 2022 ---
    but I still prefer to use the second variant of code than the first one you mentioned
    Just do not forget when the player exits to free memory from this:
    Code (Text):
    1. on disconnect:
    2.   delete {-p::%uuid of player%::*}
     
    • Like Like x 1
  6. JadeInnit1

    JadeInnit1 Member

    Joined:
    Oct 3, 2022
    Messages:
    14
    Likes Received:
    0
    I see thank you for the explanation! Helped a lot
     
    • Friendly Friendly x 1

Share This Page

Loading...