Number Formatting

  • 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 community!

    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!

chief pickle

Member
Sep 3, 2025
18
0
1
I made a card skript that when right clicked and moved to the inventory it adds a certain amount to the {genMulti::%uuid of player%} (the multiplier) and sends the message with the variable in it displaying the number but i want it to be formatting like: "1000 = 1k, 1200 = 1.2k and so on with 1m, 1b, 1t, 1aa, 1ab etc." but i cant figure out how to do it. I do have SKQuery installed but i'm just so lost. Here is the skript:


on load:
loop all players:
if {cardsinv::%uuid of loop-player%} is not set:
set {_inv} to chest inventory with 3 rows named "Cards"
set {cardsinv::%uuid of loop-player%} to {_inv}
if {genMult::%uuid of loop-player%} is not set:
set {genMult::%uuid of loop-player%} to 1
if {moreSlots::%uuid of loop-player%} is not set:
set {moreSlots::%uuid of loop-player%} to false


on join:
if {cardsinv::%uuid of player%} is not set:
set {_inv} to chest inventory with 3 rows named "Cards"
set {cardsinv::%uuid of player%} to {_inv}
if {genMult::%uuid of player%} is not set:
set {genMult::%uuid of player%} to 1
if {moreSlots::%uuid of player%} is not set:
set {moreSlots::%uuid of player%} to false

# --- Command to open GUI ---
command /cards:
trigger:
open {cardsinv::%uuid of player%} to player
wait 1 tick

if {moreSlots::%uuid of player%} is true:
set {_slots::*} to 10, 11, 12, 13, 14, 15, 16
else:
set {_slots::*} to 12, 13, 14

# --- Fill empty card slots only ---
loop {_slots::*}:
if item in slot loop-value of player's current inventory is air:
set slot loop-value of player's current inventory to archer pottery sherd named " " with lore " "

# --- Toggle more slots command ---
command /togglemoreslots:
trigger:
if {moreSlots::%uuid of player%} is true:
set {moreSlots::%uuid of player%} to false
send "&c More slots disabled! You can now only use slots 12–14."
else:
set {moreSlots::%uuid of player%} to true
send "&a More slots enabled! You can now use slots 10–16."
play sound "ui.button.click" with volume 1 and pitch 1 to player

# --- Reset command ---
command /resetcards:
trigger:
delete {cardsinv::%uuid of player%}
delete {genMult::%uuid of player%}
delete {moreSlots::%uuid of player%}

set {_inv} to chest inventory with 3 rows named "Cards"
set {cardsinv::%uuid of player%} to {_inv}
set {genMult::%uuid of player%} to 1
set {moreSlots::%uuid of player%} to false

send "&cYour Cards inventory and generator multiplier have been reset!"
play sound "entity.experience_orb.pickup" with volume 1 and pitch 1 to player


# --- Add a card to GUI when right-clicking it ---
on right click:
if name of player's tool contains "Card":
cancel event
set {_inv} to {cardsinv::%uuid of player%}
if {_inv} is not set:
set {_inv} to chest inventory with 3 rows named "Cards"
set {cardsinv::%uuid of player%} to {_inv}

if {moreSlots::%uuid of player%} is true:
set {_slots::*} to 10, 11, 12, 13, 14, 15, 16
else:
set {_slots::*} to 12, 13, 14

# --- Find first empty card slot (leftmost) ---
loop {_slots::*}:
if item in slot loop-value of {_inv} is archer pottery sherd:
set {_name} to name of player's tool
set {_mult} to 0
set {_mat} to paper

# --- Assign multiplier and material based on name ---
if {_name} contains "Red Card":
set {_mult} to 0.05
set {_mat} to clay_ball
if {_name} contains "Orange Card":
set {_mult} to 0.1
set {_mat} to quartz
if {_name} contains "Yellow Card":
set {_mult} to 0.5
set {_mat} to flint
if {_name} contains "Green Card":
set {_mult} to 1
set {_mat} to raw_iron
if {_name} contains "Blue Card":
set {_mult} to 2
set {_mat} to rabbit_hide
if {_name} contains "Purple Card":
set {_mult} to 5
set {_mat} to brick
if {_name} contains "Silver Card":
set {_mult} to 10
set {_mat} to resin_brick
if {_name} contains "Gold Card":
set {_mult} to 30
set {_mat} to raw_copper

# --- Place the card if valid ---
if {_mult} > 0:
remove 1 of tool from player
set slot loop-value of {_inv} to {_mat} named "&f%{_name}%" with lore "&7Multiplier: %{_mult}%x"
set {genMult::%uuid of player%} to {genMult::%uuid of player%} * (1 + {_mult})
set {_rounded} to round({genMult::%uuid of player%} * 10) / 10
send "&aAdded %{_name}% &7(×%{_mult}% | Total: ×%{_rounded}%)" to player
play sound "entity.experience_orb.pickup" with volume 1 and pitch 1 to player
stop

# --- Handle removing cards from inside GUI ---
on inventory click:
if name of event-inventory is "Cards":
if clicked inventory is not player's inventory:
cancel event

if {moreSlots::%uuid of player%} is true:
set {_slots::*} to 10, 11, 12, 13, 14, 15, 16
else:
set {_slots::*} to 12, 13, 14

# --- Only remove actual cards (not pottery sherds) ---
if event-item is not archer pottery sherd:
set {_name} to name of event-item
set {_mult} to 0
set {_mat} to paper

if {_name} contains "Red Card":
set {_mult} to 0.05
set {_mat} to clay_ball
if {_name} contains "Orange Card":
set {_mult} to 0.1
set {_mat} to quartz
if {_name} contains "Yellow Card":
set {_mult} to 0.5
set {_mat} to flint
if {_name} contains "Green Card":
set {_mult} to 1
set {_mat} to raw_iron
if {_name} contains "Blue Card":
set {_mult} to 2
set {_mat} to rabbit_hide
if {_name} contains "Purple Card":
set {_mult} to 5
set {_mat} to brick
if {_name} contains "Silver Card":
set {_mult} to 10
set {_mat} to resin_brick
if {_name} contains "Gold Card":
set {_mult} to 30
set {_mat} to raw_copper

if {_mult} > 0:
set {genMult::%uuid of player%} to {genMult::%uuid of player%} / (1 + {_mult})
set {_card} to {_mat} named "&f%{_name}%" with lore "&7Multiplier: %{_mult}%x"
give player {_card}

set event-slot to air
send "&cRemoved %{_name}% &7(/%{_mult}% | Total: ×%{_rounded}%)" to player
play sound "entity.item.pickup" with volume 1 and pitch 1 to player

# --- Refill empty card slots ---
loop {_slots::*}:
if item in slot loop-value of event-inventory is air:
set slot loop-value of event-inventory to archer pottery sherd named " " with lore " "

set {cardsinv::%uuid of player%} to event-inventory

# --- Save on close ---
on inventory close:
if name of event-inventory is "Cards":
set {cardsinv::%uuid of player%} to event-inventory
 
Code:
function shortNumber(n: number) :: text:
    set {_suffixes::*} to "k", "m", "b", "t", "aa", "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak"
    set {_i} to 0
    
    while {_n} >= 1000 and {_i} < size of {_suffixes::*}:
        set {_n} to {_n} / 1000
        add 1 to {_i}
        
    if {_i} is 0:
        return "%{_n}%"
    else:
        set {_n} to round({_n} * 10) / 10
        return "%{_n}%%{_suffixes::%{_i}%}%"

on break:
    set {_n} to 112320
    # Should send 112.3k
    send "%shortNumber({_n})%"

This should be right lmk if wrong I cant test it atm