Solved Enable/Disable Scoreboard with %loop-player% and %player%

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

Status
Not open for further replies.

ItsMCB

Member
May 20, 2018
46
1
8
23
www.vexel.media
I'm trying to create a command that will toggle the scoreboard for that certain player. One player might want to play with it on while another might want it off. This gives them that option. I have gotten the enable and disable part of the code to work, but I'm not sure how I can fit it in with my scoreboard loop. Thanks in advance.

Code:
variables:
   {show_info.%player%} = false


every second:
    loop all players:
        if  is in "world":
            if {show_info.%player%} is true:
                wipe loop-player's sidebar
                set name of sidebar of loop-player to "&8&l┃●&d&lWelcome&1&8&l●┃"
                set score "&5&l" in sidebar of loop-player to 5
                set score "&3» &7&lNAME &a%loop-player%" in sidebar of loop-player to 4
                set score "&3» &7&lONLINE &c%number of all players%" in sidebar of loop-player to 3
                set score "&5&l" in sidebar of loop-player to 2
                set score "&b&lMCHS.mcpro.io" in sidebar of loop-player to 1

command /toggleinfo:
    trigger:
        send "Triggered" to player
        if {show_info.%player%} is false:
            set {show_info.%player%} to true
            send "True" to player
        else:
            set {show_info.%player%} to false
            send "False" to player
 
Hey,

I don't know exactly what your problem is, but using "every second" by a scoreboard is very bad. It will lead to very bad "flicker". By creating scoreboards, you should use functions and update the scoreboard just on an event. On your scoreboard, the online players will change sometimes, so "on join" and "on quit" should update the scoreboard, not "every second". Here I have some Skript code that I have tested. It works with your toggle command:

Code:
function Scoreboard(player: player):
 wipe {_player}'s sidebar
 set name of sidebar of {_player} to "&8&l┃●&d&lWelcome&1&8&l●┃"
 set score "&5&l" in sidebar of {_player} to 5
 set score "&3» &7&lNAME &a%{_player}%" in sidebar of {_player} to 4
 set score "&3» &7&lONLINE &c%number of all players%" in sidebar of {_player} to 3
 set score "&5&l" in sidebar of {_player} to 2
 set score "&b&lMCHS.mcpro.io" in sidebar of {_player} to 1
 
on join:
 loop all players:
  if loop-player is in "world":
   if {show_info.%loop-player%} is true:
    Scoreboard(loop-player)
 
on quit:
 wait 2 ticks
 loop all players:
  if loop-player is in "world":
   if {show_info.%loop-player%} is true:
    Scoreboard(loop-player)
 
command /toggleinfo:
    trigger:
        send "Triggered" to player
        if {show_info.%player%} is false:
            set {show_info.%player%} to true
            Scoreboard(player)
            send "True" to player
        else:
            set {show_info.%player%} to false
            wipe player's sidebar
            send "False" to player

I hope I could help you :emoji_slight_smile:
 
Hey,

I don't know exactly what your problem is, but using "every second" by a scoreboard is very bad. It will lead to very bad "flicker". By creating scoreboards, you should use functions and update the scoreboard just on an event. On your scoreboard, the online players will change sometimes, so "on join" and "on quit" should update the scoreboard, not "every second". Here I have some Skript code that I have tested. It works with your toggle command:

Code:
function Scoreboard(player: player):
 wipe {_player}'s sidebar
 set name of sidebar of {_player} to "&8&l┃●&d&lWelcome&1&8&l●┃"
 set score "&5&l" in sidebar of {_player} to 5
 set score "&3» &7&lNAME &a%{_player}%" in sidebar of {_player} to 4
 set score "&3» &7&lONLINE &c%number of all players%" in sidebar of {_player} to 3
 set score "&5&l" in sidebar of {_player} to 2
 set score "&b&lMCHS.mcpro.io" in sidebar of {_player} to 1
 
on join:
 loop all players:
  if loop-player is in "world":
   if {show_info.%loop-player%} is true:
    Scoreboard(loop-player)
 
on quit:
 wait 2 ticks
 loop all players:
  if loop-player is in "world":
   if {show_info.%loop-player%} is true:
    Scoreboard(loop-player)
 
command /toggleinfo:
    trigger:
        send "Triggered" to player
        if {show_info.%player%} is false:
            set {show_info.%player%} to true
            Scoreboard(player)
            send "True" to player
        else:
            set {show_info.%player%} to false
            wipe player's sidebar
            send "False" to player

I hope I could help you :emoji_slight_smile:


Wow! Thank you! I really appreciate the help. I have one more question about the player's balance. Say I added
Code:
 set score "&3» &7Balance: &f%{_player}'s balance%" in sidebar of {_player} to 3
into the scoreboard. How could I get the scoreboard to update when their balance changes?

And yes I have Vault installed. Thanks again!
 
I don't know and didn't find an "on balance change" event. But you could use something similar to "every second":

Code:
on join:
 while player is online:
  wait a second

This code is something like every second, but better: https://forums.skunity.com/threads/player-balance-change-event.93/
To keep the less "flicker" scoreboard, you should not use this for updating your scoreboard (the thread did it :emoji_frowning:), you should use it to check, if the player balance has been changed, with having a variable "A", which will be set ONE time to your balance and variable "B", which will be set every second to your balance.

The code that I have also tested will check every second, if variable "A" and "B" are not the same. If it is not the same, it will update the scoreboard of the player and set variable "A" again ONE time to the player's balance. I hope you understood what I mean. Here is the code to copy and paste :emoji_slight_smile:

Code:
on join:
 set {%player%.bbalance} to "%player's balance%"
 while player is online:
  set {%player%.balance} to "%player's balance%"
  if "%{%player%.balance}%" is not "%{%player%.bbalance}%":
   set {%player%.bbalance} to "%player's balance%"
   Scoreboard(player)
  wait a second #If you delete this, your server will crash

Just add this to your Skript and add this "set score "&3» &7&lBalance: &f%{_player}'s balance%" in sidebar of {_player} to NUMBER" to your Scoreboard function.

I hope I could help you again :emoji_slight_smile:
[doublepost=1585995348,1585994927][/doublepost]And and to update your scoreboard on "/reload" or "/sk reload all" you can add

Code:
on script load:
 loop all players:
  if loop-player is in "world":
   if {show_info.%loop-player%} is true:
    Scoreboard(loop-player)

I think you know this yourself.
 
Last edited:
I don't know and didn't find an "on balance change" event. But you could use something similar to "every second":

Code:
on join:
 while player is online:
  wait a second

This code is something like every second, but better: https://forums.skunity.com/threads/player-balance-change-event.93/
To keep the less "flicker" scoreboard, you should not use this for updating your scoreboard (the thread did it :emoji_frowning:), you should use it to check, if the player balance has been changed, with having a variable "A", which will be set ONE time to your balance and variable "B", which will be set every second to your balance.

The code that I have also tested will check every second, if variable "A" and "B" are not the same. If it is not the same, it will update the scoreboard of the player and set variable "A" again ONE time to the player's balance. I hope you understood what I mean. Here is the code to copy and paste :emoji_slight_smile:

Code:
on join:
 set {%player%.bbalance} to "%player's balance%"
 while player is online:
  set {%player%.balance} to "%player's balance%"
  if "%{%player%.balance}%" is not "%{%player%.bbalance}%":
   set {%player%.bbalance} to "%player's balance%"
   Scoreboard(player)
  wait a second #If you delete this, your server will crash

Just add this to your Skript and add this "set score "&3» &7&lBalance: &f%{_player}'s balance%" in sidebar of {_player} to NUMBER" to your Scoreboard function.

I hope I could help you again :emoji_slight_smile:
[doublepost=1585995348,1585994927][/doublepost]And and to update your scoreboard on "/reload" or "/sk reload all" you can add

Code:
on script load:
 loop all players:
  if loop-player is in "world":
   if {show_info.%loop-player%} is true:
    Scoreboard(loop-player)

I think you know this yourself.

Thank you! You've been very helpful.
 
If your problem was solved, please mark the post as solved. Thanks :emoji_slight_smile:
 
Status
Not open for further replies.