This is a simple Skript that I developed for a friend to assist in their own Skript. It allows users to call a function with given parameters and create a cooldown for an item/ability with a custom duration. You can customize the messages shown. You can also customize the boss bar color and other items if you do your own editing, but that will be made easier in the future.
The skript is pretty well documented in of itself, and explains most of its features. It also includes a few QOL features such as resetting cooldowns on server restarts and other little features that help out.
Code (skript (Unknown Language)):
# Cooldown Skript v1.0
# Created by Skptical
# A simple cooldown API that utilizes the bossbar
# to show a counting down cooldown for specific items or abilities.
#
# Requirements:
# - Skellete
# - Skript
# Global variables
# Can be changed to adjust the cooldown message in the bossbar
# Must be a string datatype
variables:
noCoolDownMessaage = " &eis ready to use!"
coolDownMessage = " &ewill be ready to use again in &c "
# Debug() Function
# Broadcasts information with debug prefix
# Only intended to be used to debug variables and functions
# Usage: debug(debugInfo)
function debug(message :text):
loop all players:
send message "&c(DEBUG BROADCAST) %{_message}%" to loop-player
# updateCoolDown() Function
# Updates and displays the bossbar used for the cooldown, main function.
# Usage: update(playerToShowCooldown, nameOfCoolDownItem)
# Do not use this function to do a cooldown please use showCoolDown()
# this function is meant to be used by API's and other built in functions (Only use if you know what your doing)
function updateCoolDown(player: player, name: text):
if {%{_player}%.cooldown.%{_name}%} > -4:
while true:
if {%{_player}%.cooldown.%{_name}%} is 0:
set {%{_player}%.active.%{_name}%} to false
set bossbar "%{_player}%.cooldown.%{_name}%" title to "%{_name}%%{noCoolDownMessaage}%"
set bossbar "%{_player}%.cooldown.%{_name}%" color to green
wait 3 seconds
remove bossbar "%{_player}%.cooldown.%{_name}%"
set {%{_player}%.cooldown.%{_name}%} to -4
stop
else:
create bossbar titled "%{_name}%%{coolDownMessage}%%{%{_player}%.cooldown.%{_name}%}%" and id "%{_player}%.cooldown.%{_name}%" for {_player} with colors yellow
set bossbar "%{_player}%.cooldown.%{_name}%" value to 100
loop {%{_player}%.cooldown.%{_name}%} times:
wait 1 second
set {%{_player}%.cooldown.%{_name}%} to {%{_player}%.cooldown.%{_name}%} - 1
set bossbar "%{_player}%.cooldown.%{_name}%" title to "%{_name}%%{coolDownMessage}%%{%{_player}%.cooldown.%{_name}%}%"
# ShowCoolDown() Function
# Shows a visible cooldown to the player via the boss bar, until it has ended.
# Usage: showCooldown(cooldownInSeconds, nameOfCoolDownItem, playerToShowCooldown)
function showCooldown(cooldown: number, name: text, player: player):
if {%{_player}%.active.%{_name}%} is false:
set {%{_player}%.active.%{_name}%} to true
set {%{_player}%.cooldown.%{_name}%} to {_cooldown}
updateCoolDown({_player}, "%{_name}%")
if {%{_player}%.active.%{_name}%} is not true:
if {%{_player}%.active.%{_name}%} is not false:
set {%{_player}%.active.%{_name}%} to true
set {%{_player}%.cooldown.%{_name}%} to {_cooldown}
updateCoolDown({_player}, "%{_name}%")
if {cooldowns.plist::*} contains {_player}:
set {%{_player}%.active.%{_name}%} to true
set {%{_player}%.cooldown.%{_name}%} to {_cooldown}
updateCoolDown({_player}, "%{_name}%")
remove player from {cooldowns.plist::*}
# Player join event
# Called when players join the server
# This is event is important and should not be removed.
# It ensures that when joining after a restart the players cooldown running variables:
# is reset and that they dont get "free cooldowns".
on player join:
if {cooldowns.clist::*} does not contain player:
add player to {cooldowns.plist::*}
add player to {cooldowns.clist::*}
# Server start event
# Called when skript is loaded
# This is event is important and should not be removed.
# It ensures that if the server is closed or crashes while a player cooldown is active and does not finish
# the players cooldown running variable is reset upon next join.
on server start:
clear {cooldowns.plist::*}
clear {cooldowns.clist::*}
# !!!!!!!IMPORTANT SECTION!!!!!!!
# If you want to check if a player has a cooldown running
# or the cooldown is currently counting down/active you
# can do so by checking the following player variables:
#
# {%{_player}%.cooldown.%{_name}%} - This is the current cooldown in seconds for an item the player has left.
# this value will go down to -4 as it also displays a "item ready to use "
# message in the bossbar which requires this. If the value is 0 less the cooldown is not active.
# But remember to take into account that this variable will countdown to -4 when using it.
# NOTE: Please replace %{_name}% with the name of the item you created the cooldown with and replace
# %{_player}% with the player that you started the cooldown with.
#
#
# {%{_player}%.active.%{_name}%} - This is the boolean variable that will return true/false based on weather the player
# has the cooldown active for the current item. If the variable is neither true or false,
# then the item or player you are checking the cooldown for doesnt exist so is false. But will return [<none>]. This should be noted.
# NOTE: Please replace %{_name}% with the name of the item you created the cooldown with and replace
# %{_player}% with the player that you started the cooldown with.
#
# This is just some code to check that the cooldown functions with basic items
# This code can be safely removed:
on right click with stick:
showCooldown(10, "Stick", player)
send message "Cooldown" to player
on right click with diamond:
showCooldown(10, "Diamond", player)
send message "Cooldown" to player
# Developers Notes
# TODO:
# - Fix server ending/crashing mid cooldown causing cooldowns to bugged - DONE
# - Add multi item compatability -DONE
# - Fix boss bar power up animation
# - Add choice between bossbar and action bar for the cooldown
# - Fix cooldown so that a new one can be started after the cooldown has ended, not when the bossbar has finished showing. - FIXED
If you have any questions or require help using this feel free to leave a comment or DM me.