Player Balance change event

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

sandor_1234

Active Member
Jan 26, 2017
165
5
0
21
I have an scoreboard with the money the player has:
code_language.skript:
every 1 second:
    loop all players:
        wipe loop-player's sidebar
        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.
 
Instead of doing a periodical event, which is known to cause lag, you could use a while loop.

code_language.skript:
on join:
    while player is online:
        wipe player's sidebar
        set score "%balance of player%" in sidebar of player to 9
        wait 1 second   #this is important and you should always add some kind of wait
 
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.
 
Instead of doing a periodical event, which is known to cause lag, you could use a while loop.

code_language.skript:
on join:
    while player is online:
        wipe player's sidebar
        set score "%balance of player%" in sidebar of player to 9
        wait 1 second   #this is important and you should always add some kind of wait

This is a nice solution. But also can cause laggs when many players are online :emoji_slight_smile:.
 
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.
I am just using essentials + vaults econemy system
 
I am just using essentials + vaults econemy system

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.
 
Instead of doing a periodical event, which is known to cause lag, you could use a while loop.

code_language.skript:
on join:
    while player is online:
        wipe player's sidebar
        set score "%balance of player%" in sidebar of player to 9
        wait 1 second   #this is important and you should always add some kind of wait
Thanks didn't see your answer at first :emoji_stuck_out_tongue:
 
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_language.skript:
function updatePlayerMoney(player: Player, newValue: Number):
    set {_player}'s money to {_newValue}
    wipe {_player}'s sidebar
    set score "%{_player}'s money%" in sidebar of {_player} to 9
 
I am now using this skript:
code_language.skript:
on join:
    while player is online:
        set {_c} to yaml value "Userdata.Faction" of file "plugins/Skript/scripts/Factions/Userdata/%uuid of player%.yml"
        set {_r} to yaml value "Userdata.Rank" of file "plugins/Skript/scripts/Factions/Userdata/%uuid of player%.yml"
        set {_t} to yaml value "GebiedOwnedBy" of file "plugins/Skript/scripts/Factions/Territories/%chunk of player%.yml"
        set {_a} to yaml list "Faction.Allies" of file "plugins/Skript/scripts/Factions/Factions/%{_c}%.yml"
        if {_c} is set:
            wipe player's sidebar
            set name of sidebar of player to "{@psc}"
            set score "&eGeld" in sidebar of player to 10
            set score "%balance of player%" in sidebar of player to 9
            set score " &1" in sidebar of player to 8
            set score "&e{@p}" in sidebar of player to 7
            set score "&f%{_c}%" in sidebar of player to 6
            set score "&1&l" in sidebar of player to 5
            set score "&e{@p} Rank" in sidebar of player to 4
            set score "&6%{_r}%" in sidebar of player to 3
            set score "&1 " in sidebar of player to 2
            set score "&eGebied" in sidebar of player to 1
            if {_t} is set:
                if {_t} is equal to "%{_c}%":
                    set score "&b%{_t}%" in sidebar of player to 0
                else:
                    if {_a::*} contains "%{_t}%":
                        set score "&a%{_t}%" in sidebar of player to 0
                    else:
                        if {_t} is equal to "(Safe) Spawn" or "(Safe) Shop":
                            set score "&b%{_t}%" in sidebar of player to 0
                        else:
                            set score "&6%{_t}%" in sidebar of player to 0
            else:
                set score "&7Wildernis" in sidebar of player to 0
        else:
            wipe player's sidebar
            set name of sidebar of player to "{@psc}"
            set score "&eGeld" in sidebar of player to 7
            set score "%balance of player%" in sidebar of player to 6
            set score " &1" in sidebar of player to 5
            set score "&e{@p}" in sidebar of player to 4
            set score "&cNo {@p}" in sidebar of player to 3
            set score "&1 " in sidebar of player to 2
            set score "&eGebied" in sidebar of player to 1
            if {_t} is set:
                if {_t} is equal to "(Safe) Spawn" or "(Safe) Shop":
                    set score "&b%{_t}%" in sidebar of player to 0
                else:
                    set score "&6%{_t}%" in sidebar of player to 0
            else:
                set score "&7Wildernis" in sidebar of player to 0
        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.
 
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.
 
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).
 
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).
I removed halve off the code but is it possible to remove an unknown object from the scoreboard with a value for exaple:
code_language.skript:
on join:
    set name of sidebar of player to "{@psc}"
    set score "&eMoney" in sidebar of player to 10
    set score "&1" in sidebar of player to 8
    set score "&eFaction" in sidebar of player to 7
    set score "&1" in sidebar of player to 5
    set score "&eFaction Rank" in sidebar of player to 4
    set score "&1" in sidebar of player to 2
    set score "&eLand" in sidebar of player to 1
    while player is online:
        set {_c} to yaml value "Userdata.Faction" of file "plugins/Skript/scripts/Factions/Userdata/%uuid of player%.yml"
        set {_r} to yaml value "Userdata.Rank" of file "plugins/Skript/scripts/Factions/Userdata/%uuid of player%.yml"
        set {_t} to yaml value "GebiedOwnedBy" of file "plugins/Skript/scripts/Factions/Territories/%chunk of player%.yml"
        set {_a} to yaml list "Faction.Allies" of file "plugins/Skript/scripts/Factions/Factions/%{_c}%.yml"
        if {_c} is set:
            set score "%balance of player%" in sidebar of player to 9
            set score "&f%{_c}%" in sidebar of player to 6
            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_language.skript:
    set name of sidebar of player to "{@psc}"
    set score "&eMoney" in sidebar of player to 10
    set score "&1" in sidebar of player to 8
    set score "&eFaction" in sidebar of player to 7
    set score "&1" in sidebar of player to 5
    set score "&eFaction Rank" in sidebar of player to 4
    set score "&1" in sidebar of player to 2
    set score "&eLand" in sidebar of player to 1
Every 1 second but the problem is that it gets doubled. So for example:
aa1cc5954bd6acf87d458b22890759df.png

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
[doublepost=1485623257,1485542693][/doublepost]bump
 
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
 
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
How would i do that for example?
 
Status
Not open for further replies.