Files
README.txt
shards.sk
Code
2 252
shards.sk
# Shards Currency System
# A custom currency system with PlaceholderAPI support
# Version: 1.0
options:
prefix: &6[Shards]&r
currency-name: Shards
currency-symbol: ⭐
starting-balance: 0
on script load:
send "{@prefix} &aShards system loaded successfully!" to console
send "{@prefix} &aPlaceholderAPI support enabled!" to console
on join:
if {shards::%player%} is not set:
set {shards::%player%} to {@starting-balance}
function formatNumber(num: number) :: text:
set {_n} to {_num}
if {_n} >= 1000000:
return "%{_n} / 1000000%M"
if {_n} >= 1000:
return "%{_n} / 1000%K"
return "%{_n}%"
function getShards(p: player) :: number:
if {shards::%{_p}%} is not set:
set {shards::%{_p}%} to {@starting-balance}
return {shards::%{_p}%}
function addShards(p: player, amount: number) :: boolean:
if {shards::%{_p}%} is not set:
set {shards::%{_p}%} to {@starting-balance}
add {_amount} to {shards::%{_p}%}
return true
function removeShards(p: player, amount: number) :: boolean:
if {shards::%{_p}%} is not set:
set {shards::%{_p}%} to {@starting-balance}
if {shards::%{_p}%} < {_amount}:
return false
remove {_amount} from {shards::%{_p}%}
return true
function setShards(p: player, amount: number):
set {shards::%{_p}%} to {_amount}
command /shards [<text>] [<offline player>] [<number>]:
aliases: /shard, /crystals
trigger:
if arg-1 is not set:
set {_balance} to getShards(player)
send "{@prefix} &eYour balance: &6{@currency-symbol} %{_balance}% {@currency-name}" to player
stop
if arg-1 is "balance" or "bal":
if arg-2 is set:
if player has permission "shards.admin":
set {_balance} to getShards(arg-2)
send "{@prefix} &e%arg-2%'s balance: &6{@currency-symbol} %{_balance}% {@currency-name}" to player
else:
send "{@prefix} &cYou don't have permission to check other players' balances!" to player
else:
set {_balance} to getShards(player)
send "{@prefix} &eYour balance: &6{@currency-symbol} %{_balance}% {@currency-name}" to player
stop
if arg-1 is "give" or "add":
if player does not have permission "shards.admin":
send "{@prefix} &cYou don't have permission to use this command!" to player
stop
if arg-2 is not set:
send "{@prefix} &cUsage: /shards give <player> <amount>" to player
stop
if arg-3 is not set:
send "{@prefix} &cUsage: /shards give <player> <amount>" to player
stop
if arg-3 <= 0:
send "{@prefix} &cAmount must be greater than 0!" to player
stop
addShards(arg-2, arg-3)
send "{@prefix} &aGave &6{@currency-symbol} %arg-3% {@currency-name} &ato &e%arg-2%&a!" to player
if arg-2 is online:
send "{@prefix} &aYou received &6{@currency-symbol} %arg-3% {@currency-name}&a!" to arg-2
stop
if arg-1 is "take" or "remove":
if player does not have permission "shards.admin":
send "{@prefix} &cYou don't have permission to use this command!" to player
stop
if arg-2 is not set:
send "{@prefix} &cUsage: /shards take <player> <amount>" to player
stop
if arg-3 is not set:
send "{@prefix} &cUsage: /shards take <player> <amount>" to player
stop
if arg-3 <= 0:
send "{@prefix} &cAmount must be greater than 0!" to player
stop
set {_removed} to removeShards(arg-2, arg-3)
if {_removed} is true:
send "{@prefix} &aTook &6{@currency-symbol} %arg-3% {@currency-name} &afrom &e%arg-2%&a!" to player
if arg-2 is online:
send "{@prefix} &c%arg-3% {@currency-name} were taken from your balance!" to arg-2
else:
send "{@prefix} &c%arg-2% doesn't have enough {@currency-name}!" to player
stop
if arg-1 is "set":
if player does not have permission "shards.admin":
send "{@prefix} &cYou don't have permission to use this command!" to player
stop
if arg-2 is not set:
send "{@prefix} &cUsage: /shards set <player> <amount>" to player
stop
if arg-3 is not set:
send "{@prefix} &cUsage: /shards set <player> <amount>" to player
stop
if arg-3 < 0:
send "{@prefix} &cAmount cannot be negative!" to player
stop
setShards(arg-2, arg-3)
send "{@prefix} &aSet &e%arg-2%'s &abalance to &6{@currency-symbol} %arg-3% {@currency-name}&a!" to player
if arg-2 is online:
send "{@prefix} &eYour balance has been set to &6{@currency-symbol} %arg-3% {@currency-name}&e!" to arg-2
stop
if arg-1 is "pay":
if arg-2 is not set:
send "{@prefix} &cUsage: /shards pay <player> <amount>" to player
stop
if arg-3 is not set:
send "{@prefix} &cUsage: /shards pay <player> <amount>" to player
stop
if arg-3 <= 0:
send "{@prefix} &cAmount must be greater than 0!" to player
stop
if arg-2 is player:
send "{@prefix} &cYou cannot pay yourself!" to player
stop
set {_balance} to getShards(player)
if {_balance} < arg-3:
send "{@prefix} &cYou don't have enough {@currency-name}! You have &6{@currency-symbol} %{_balance}% {@currency-name}&c." to player
stop
removeShards(player, arg-3)
addShards(arg-2, arg-3)
send "{@prefix} &aYou paid &e%arg-2% &6{@currency-symbol} %arg-3% {@currency-name}&a!" to player
if arg-2 is online:
send "{@prefix} &aYou received &6{@currency-symbol} %arg-3% {@currency-name} &afrom &e%player%&a!" to arg-2
stop
if arg-1 is "top" or "leaderboard":
send "{@prefix} &6Top 10 {@currency-name} Holders:" to player
set {_pos} to 1
loop 10 times:
set {_highest} to 0
set {_highestPlayer} to ""
loop {shards::*}:
if loop-value > {_highest}:
if {_shown::%loop-index%} is not set:
set {_highest} to loop-value
set {_highestPlayer} to loop-index
if {_highestPlayer} is not "":
set {_shown::%{_highestPlayer}%} to true
send "&e%{_pos}%. &6%{_highestPlayer}% &7- &6{@currency-symbol} %{_highest}% {@currency-name}" to player
add 1 to {_pos}
delete {_shown::*}
stop
if arg-1 is "help":
send "&7&m-----------------------------------" to player
send "{@prefix} &6{@currency-name} Commands:" to player
send "&e/shards &7- Check your balance" to player
send "&e/shards balance [player] &7- Check balance" to player
send "&e/shards pay <player> <amount> &7- Pay another player" to player
send "&e/shards top &7- View leaderboard" to player
if player has permission "shards.admin":
send "&c/shards give <player> <amount> &7- Give shards" to player
send "&c/shards take <player> <amount> &7- Take shards" to player
send "&c/shards set <player> <amount> &7- Set shards" to player
send "&7&m-----------------------------------" to player
stop