1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Skript' started by ItsMCB, Apr 1, 2020.

Thread Status:
Not open for further replies.
  1. ItsMCB

    ItsMCB Member

    Joined:
    May 20, 2018
    Messages:
    46
    Likes Received:
    1
    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 (Text):
    1. variables:
    2.    {show_info.%player%} = false
    3.  
    4.  
    5. every second:
    6.     loop all players:
    7.         if  is in "world":
    8.             if {show_info.%player%} is true:
    9.                 wipe loop-player's sidebar
    10.                 set name of sidebar of loop-player to "&8&l┃●&d&lWelcome&1&8&l●┃"
    11.                 set score "&5&l" in sidebar of loop-player to 5
    12.                 set score "&3» &7&lNAME &a%loop-player%" in sidebar of loop-player to 4
    13.                 set score "&3» &7&lONLINE &c%number of all players%" in sidebar of loop-player to 3
    14.                 set score "&5&l" in sidebar of loop-player to 2
    15.                 set score "&b&lMCHS.mcpro.io" in sidebar of loop-player to 1
    16.  
    17. command /toggleinfo:
    18.     trigger:
    19.         send "Triggered" to player
    20.         if {show_info.%player%} is false:
    21.             set {show_info.%player%} to true
    22.             send "True" to player
    23.         else:
    24.             set {show_info.%player%} to false
    25.             send "False" to player
    26.  
     
  2. 11thDoctor314

    11thDoctor314 Member

    Joined:
    Feb 10, 2019
    Messages:
    10
    Likes Received:
    0
    Shouldn't line 8 be {show_info.%loop-player%}, because it's in a loop all players: ?
     
  3. ItsMCB

    ItsMCB Member

    Joined:
    May 20, 2018
    Messages:
    46
    Likes Received:
    1
    Yes but then the toggle wouldn't work. How could I make the toggle work for loop players?
     
  4. TCXeption

    TCXeption Member

    Joined:
    Apr 2, 2020
    Messages:
    16
    Likes Received:
    0
    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 (Text):
    1. function Scoreboard(player: player):
    2.  wipe {_player}'s sidebar
    3.  set name of sidebar of {_player} to "&8&l┃●&d&lWelcome&1&8&l●┃"
    4.  set score "&5&l" in sidebar of {_player} to 5
    5.  set score "&3» &7&lNAME &a%{_player}%" in sidebar of {_player} to 4
    6.  set score "&3» &7&lONLINE &c%number of all players%" in sidebar of {_player} to 3
    7.  set score "&5&l" in sidebar of {_player} to 2
    8.  set score "&b&lMCHS.mcpro.io" in sidebar of {_player} to 1
    9.  
    10. on join:
    11.  loop all players:
    12.   if loop-player is in "world":
    13.    if {show_info.%loop-player%} is true:
    14.     Scoreboard(loop-player)
    15.  
    16. on quit:
    17.  wait 2 ticks
    18.  loop all players:
    19.   if loop-player is in "world":
    20.    if {show_info.%loop-player%} is true:
    21.     Scoreboard(loop-player)
    22.  
    23. command /toggleinfo:
    24.     trigger:
    25.         send "Triggered" to player
    26.         if {show_info.%player%} is false:
    27.             set {show_info.%player%} to true
    28.             Scoreboard(player)
    29.             send "True" to player
    30.         else:
    31.             set {show_info.%player%} to false
    32.             wipe player's sidebar
    33.             send "False" to player
    I hope I could help you :emoji_slight_smile:
     
  5. ItsMCB

    ItsMCB Member

    Joined:
    May 20, 2018
    Messages:
    46
    Likes Received:
    1

    Wow! Thank you! I really appreciate the help. I have one more question about the player's balance. Say I added
    Code (Text):
    1.  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!
     
  6. TCXeption

    TCXeption Member

    Joined:
    Apr 2, 2020
    Messages:
    16
    Likes Received:
    0
    I don't know and didn't find an "on balance change" event. But you could use something similar to "every second":

    Code (Text):
    1. on join:
    2.  while player is online:
    3.   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 (Text):
    1. on join:
    2.  set {%player%.bbalance} to "%player's balance%"
    3.  while player is online:
    4.   set {%player%.balance} to "%player's balance%"
    5.   if "%{%player%.balance}%" is not "%{%player%.bbalance}%":
    6.    set {%player%.bbalance} to "%player's balance%"
    7.    Scoreboard(player)
    8.   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:
    --- Double Post Merged, Apr 4, 2020, Original Post Date: Apr 4, 2020 ---
    And and to update your scoreboard on "/reload" or "/sk reload all" you can add

    Code (Text):
    1. on script load:
    2.  loop all players:
    3.   if loop-player is in "world":
    4.    if {show_info.%loop-player%} is true:
    5.     Scoreboard(loop-player)
    I think you know this yourself.
     
    #6 TCXeption, Apr 4, 2020
    Last edited: Apr 4, 2020
  7. ItsMCB

    ItsMCB Member

    Joined:
    May 20, 2018
    Messages:
    46
    Likes Received:
    1
    Thank you! You've been very helpful.
     
  8. Goose

    Supporter

    Joined:
    Nov 23, 2019
    Messages:
    429
    Likes Received:
    30
    If your problem was solved, please mark the post as solved. Thanks :emoji_slight_smile:
     
Thread Status:
Not open for further replies.

Share This Page

Loading...