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.

Player Balance change event

Discussion in 'Skript' started by sandor_1234, Jan 26, 2017.

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

    sandor_1234 Active Member

    Joined:
    Jan 26, 2017
    Messages:
    165
    Likes Received:
    5
    I have an scoreboard with the money the player has:
    Code (Skript):
    1. every 1 second:
    2.     loop all players:
    3.         wipe loop-player's sidebar
    4.         set score "%balance of loop-player%" in sidebar of loop-player to 9
    But this is causing huge lagg is there another way how to detect an change off a players balance without lagging my whole server.
     
  2. Best Answer:
    Post #2 by ShaneBee, Jan 26, 2017
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    Instead of doing a periodical event, which is known to cause lag, you could use a while loop.

    Code (Skript):
    1. on join:
    2.     while player is online:
    3.         wipe player's sidebar
    4.         set score "%balance of player%" in sidebar of player to 9
    5.         wait 1 second   #this is important and you should always add some kind of wait
     
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    I think that there is no event for this. One way you could do that is that you script your currency system yourself and build your fourth line in every transaction part of the script :emoji_grin:. But I think this takes a little bit of time. But if there is such event i don't know that it exist.
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    This is a nice solution. But also can cause laggs when many players are online :emoji_slight_smile:.
     
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    I am just using essentials + vaults econemy system
     
  7. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    Year and thats what i mean. I also use only Vault (Essentials mostly self scripted and no economy plugin). Skript deliveres the "player's balance" function. So if you would a smooth method you can script a small transaction system and then you could integrate the scoreboard update function. It takes time but is the solution wich needs the lowest server-power.
     
  8. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    Thanks didn't see your answer at first :emoji_stuck_out_tongue:
     
  9. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    Another option too, in case your server run only with Skript, you can create a function to change the player's money and update the scoreboard.
    Code (Skript):
    1. function updatePlayerMoney(player: Player, newValue: Number):
    2.     set {_player}'s money to {_newValue}
    3.     wipe {_player}'s sidebar
    4.     set score "%{_player}'s money%" in sidebar of {_player} to 9
     
  10. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    I am now using this skript:
    Code (Skript):
    1. on join:
    2.     while player is online:
    3.         set {_c} to yaml value "Userdata.Faction" of file "plugins/Skript/scripts/Factions/Userdata/%uuid of player%.yml"
    4.         set {_r} to yaml value "Userdata.Rank" of file "plugins/Skript/scripts/Factions/Userdata/%uuid of player%.yml"
    5.         set {_t} to yaml value "GebiedOwnedBy" of file "plugins/Skript/scripts/Factions/Territories/%chunk of player%.yml"
    6.         set {_a} to yaml list "Faction.Allies" of file "plugins/Skript/scripts/Factions/Factions/%{_c}%.yml"
    7.         if {_c} is set:
    8.             wipe player's sidebar
    9.             set name of sidebar of player to "{@psc}"
    10.             set score "&eGeld" in sidebar of player to 10
    11.             set score "%balance of player%" in sidebar of player to 9
    12.             set score " &1" in sidebar of player to 8
    13.             set score "&e{@p}" in sidebar of player to 7
    14.             set score "&f%{_c}%" in sidebar of player to 6
    15.             set score "&1&l" in sidebar of player to 5
    16.             set score "&e{@p} Rank" in sidebar of player to 4
    17.             set score "&6%{_r}%" in sidebar of player to 3
    18.             set score "&1 " in sidebar of player to 2
    19.             set score "&eGebied" in sidebar of player to 1
    20.             if {_t} is set:
    21.                 if {_t} is equal to "%{_c}%":
    22.                     set score "&b%{_t}%" in sidebar of player to 0
    23.                 else:
    24.                     if {_a::*} contains "%{_t}%":
    25.                         set score "&a%{_t}%" in sidebar of player to 0
    26.                     else:
    27.                         if {_t} is equal to "(Safe) Spawn" or "(Safe) Shop":
    28.                             set score "&b%{_t}%" in sidebar of player to 0
    29.                         else:
    30.                             set score "&6%{_t}%" in sidebar of player to 0
    31.             else:
    32.                 set score "&7Wildernis" in sidebar of player to 0
    33.         else:
    34.             wipe player's sidebar
    35.             set name of sidebar of player to "{@psc}"
    36.             set score "&eGeld" in sidebar of player to 7
    37.             set score "%balance of player%" in sidebar of player to 6
    38.             set score " &1" in sidebar of player to 5
    39.             set score "&e{@p}" in sidebar of player to 4
    40.             set score "&cNo {@p}" in sidebar of player to 3
    41.             set score "&1 " in sidebar of player to 2
    42.             set score "&eGebied" in sidebar of player to 1
    43.             if {_t} is set:
    44.                 if {_t} is equal to "(Safe) Spawn" or "(Safe) Shop":
    45.                     set score "&b%{_t}%" in sidebar of player to 0
    46.                 else:
    47.                     set score "&6%{_t}%" in sidebar of player to 0
    48.             else:
    49.                 set score "&7Wildernis" in sidebar of player to 0
    50.         wait 1 second
    Is this gonna lag on my server with around 60 people online with 3 gigs off ram.
    I just don't wanna ruin my player base i am testing on a local server as well but i won't know how this will do with around 60 players online.
     
  11. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    It depends on many things (amout of plugins, scripts etc.). So I think you can test it. You can loop this whole script in the while online statement 60 times. This will never happen on the real server because all players must connect at the same time. But if the server can run this it won't be a problem. To make sure your test server should also have 3 gb of ram and the same plugins/scripts.

    I hope you know what I mean and I hope it helps.
     
    • Informative Informative x 1
  12. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    Change '1 second' to like '10 seconds'. There's no need for almost instant updates.
    Also, do not get YAML values like that in a 'while' loop. YAML is slow and is better for configs, not database.

    Your code is a waaaay big for a 1 second loop.

    And most importantly, I don't recommend using things like that in Skript. Try replacing with a scoreboard plugin compatible with Skript - Featherboard or any scoreboard plugin that uses PlaceholderAPI (install Umbaska to make it work).
     
  13. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    WolvSK has an event for this if you're using Essentials.
     
    • Informative Informative x 2
  14. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    I removed halve off the code but is it possible to remove an unknown object from the scoreboard with a value for exaple:
    Code (Skript):
    1. on join:
    2.     set name of sidebar of player to "{@psc}"
    3.     set score "&eMoney" in sidebar of player to 10
    4.     set score "&1" in sidebar of player to 8
    5.     set score "&eFaction" in sidebar of player to 7
    6.     set score "&1" in sidebar of player to 5
    7.     set score "&eFaction Rank" in sidebar of player to 4
    8.     set score "&1" in sidebar of player to 2
    9.     set score "&eLand" in sidebar of player to 1
    10.     while player is online:
    11.         set {_c} to yaml value "Userdata.Faction" of file "plugins/Skript/scripts/Factions/Userdata/%uuid of player%.yml"
    12.         set {_r} to yaml value "Userdata.Rank" of file "plugins/Skript/scripts/Factions/Userdata/%uuid of player%.yml"
    13.         set {_t} to yaml value "GebiedOwnedBy" of file "plugins/Skript/scripts/Factions/Territories/%chunk of player%.yml"
    14.         set {_a} to yaml list "Faction.Allies" of file "plugins/Skript/scripts/Factions/Factions/%{_c}%.yml"
    15.         if {_c} is set:
    16.             set score "%balance of player%" in sidebar of player to 9
    17.             set score "&f%{_c}%" in sidebar of player to 6
    18.             set score "&6%{_r}%" in sidebar of player to 3
    This i was i would like to use ^^ in this skript it doesn't have to replace all this scores:
    Code (Skript):
    1.     set name of sidebar of player to "{@psc}"
    2.     set score "&eMoney" in sidebar of player to 10
    3.     set score "&1" in sidebar of player to 8
    4.     set score "&eFaction" in sidebar of player to 7
    5.     set score "&1" in sidebar of player to 5
    6.     set score "&eFaction Rank" in sidebar of player to 4
    7.     set score "&1" in sidebar of player to 2
    8.     set score "&eLand" in sidebar of player to 1
    Every 1 second but the problem is that it gets doubled. So for example: [​IMG]
    It won't remove the prevorious set money is there a way to not have to over and over set every static value in the scoreboard but just wipe the value's with the score 9 for example
    --- Double Post Merged, Jan 28, 2017, Original Post Date: Jan 27, 2017 ---
    bump
     
  15. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    You have to delete the score and then set it other time or that will happen

    I would recommend to use id based scores and update them for this kind of things, and if you go yet more advanced, team entries and blank score entries for have no flicker
     
  16. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    How would i do that for example?
     
  17. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
    The only thing i've seen is this :

    reset [value] [of] score %string% (for|in) [score][board] %string%

    But it needs Umbaska 2.0 ...
     
  18. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
  19. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,179
    Likes Received:
    218
Thread Status:
Not open for further replies.

Share This Page

Loading...