Centering Text

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

Status
Not open for further replies.

1ogiq

Member
Sep 5, 2022
1
0
1
Hi there, I was wondering how or if I would be able to center text with skript.
I have looked around and found one syntax for it in Skellett, but it has been removed since.

Thanks!
 
With skript-reflect
Code:
import:
  org.bukkit.map.MinecraftFont

function getWidth(text: string) :: number:
  set {_s::*} to {_text} split at "&l"
  loop {_s::*}:
    add (MinecraftFont.Font.getWidth(unformatted loop-value) + (size of (loop-value split at "")) - (size of loop-value split at " ")) to {_result} if mod(loop-index parsed as integer, 2) = 0
    add MinecraftFont.Font.getWidth(unformatted loop-value) to {_result} if mod(loop-index parsed as integer, 2) = 1
  return {_result}

# 154 for chat, 127 for motd
function centeredText(text: string, lenght: integer) :: string:
  while {_compensated} ? 0 < ({_lenght} - (getWidth({_text}) / 2)):
    set {_return} to "%{_return} ? ""%&r "
    add (getWidth(" ") + 1) to {_compensated}
  return "%{_return}%%{_text}%"
 
Status
Not open for further replies.