Making Numbers To Letters

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

TimeStellar

New Member
Mar 4, 2024
5
0
1
23
I have a mob skript that has a billion hp and how can i make it say 1 b instend of 1000000000 the code:

command /devp:
trigger:
open chest inventory with 3 rows named "&cDev Panel" to player
wait 1 tick
set slot 0 of player's current inventory to stone named "&aZombie"

on inventory click:
if name of event-inventory is "&cDev Panel":
if index of event-slot is 0:
summon zombie at location of player
set max health of last spawned mob to 10000
set health of last spawned entity to 10000
set {_mhp} to maximum health of last spawned entity
set {_hp} to health of last spawned entity
set display name of last spawned mob to "&cZombie &a%{_hp}%&f/&a%{_mhp}%"
cancel event

on damage of zombie:
if display name of victim contains "&cZombie ":
set {_hp} to health of victim
set {_mhp} to maximum health of victim
set display name of victim to "&cZombie &a%{_hp}%&f/&a%{_mhp}%"
 
I have a mob skript that has a billion hp and how can i make it say 1 b instend of 1000000000 the code:

command /devp:
trigger:
open chest inventory with 3 rows named "&cDev Panel" to player
wait 1 tick
set slot 0 of player's current inventory to stone named "&aZombie"

on inventory click:
if name of event-inventory is "&cDev Panel":
if index of event-slot is 0:
summon zombie at location of player
set max health of last spawned mob to 10000
set health of last spawned entity to 10000
set {_mhp} to maximum health of last spawned entity
set {_hp} to health of last spawned entity
set display name of last spawned mob to "&cZombie &a%{_hp}%&f/&a%{_mhp}%"
cancel event

on damage of zombie:
if display name of victim contains "&cZombie ":
set {_hp} to health of victim
set {_mhp} to maximum health of victim
set display name of victim to "&cZombie &a%{_hp}%&f/&a%{_mhp}%"
To do this, you should use a function that takes a number and returns a text value based on data. You can then split that data (Given it's one text component) and do a bit of math to determine what abbreviation to give the number,

Code:
function f(n: number) :: text:
    set {_data} to "QT,18|Q,15|T,12|B,9|M,6|k,3" # Defines abbreviations, the number is how many zeroes
    loop split {_data} at "|": # Splits the data nicely
        set {_s::*} to split loop-value at "," # Removes commas
        {_n} >= 10 ^ {_s::2} parsed as number
        return "%{_n} / 10 ^ {_s::2} parsed as number%%{_s::1}%" 
    return "%{_n}%" # Returns the abbreviated number

Keep in mind, ONLY use this in text otherwise your code won't understand how to add/remove "1B" to a variable.