Solved Can you help me optimise my skripts?

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

Fladsaw

Member
Jul 18, 2022
31
0
6
21
Hey everyone! I wrote three skripts and I am not sure if they are really optimised or not. I feel like events that are used on them can damage the performance of the server. Can you make them more performance friendly?




My first skript is this. It is a scope skript and when players sneak, they get a carved pumpkin with a sniper texture on their head.

Code:
on sneak toggle:
    if player is holding golden hoe:
        if player is not sneaking:
            set {scope::%player%} to true
            set {helmet::%player%} to player's helmet
            wait 1 tick
            equip player with carved pumpkin
            apply slowness of tier 255 without particles to player for 100000 seconds
            play sound "entity.bat.takeoff" at volume 1 at pitch 1 to player

on sneak toggle:
    if player is holding golden hoe:
        if player is sneaking:
            set {scope::%player%} to false
            remove slowness from player
            set player's helmet to {helmet::%player%}
            play sound "entity.bat.takeoff" at volume 1 at pitch 1 to player

on player's tool change:
    if {scope::%player%} is true:
        if player's tool is not golden hoe:
            cancel event




My second skript is a bleeding skript. When a players get hit, if damage is more that 2.5 hearts, they start to bleed and continue to bleed until they command /heal. I also added an "on join" event because without it, players don't bleed after they log off and log back on.

Code:
on damage:
    if damage cause is an attack:
        if {bleeding::%victim's uuid%} is false:
            set {_damage} to damage
            if {_damage} is more than 2.5:
                set {bleeding::%victim's uuid%} to true
                while victim is online:
                    wait 2 seconds
                    if {bleeding::%victim's uuid%} is true:
                        apply blindness of tier 1 without particles to victim for 2 seconds
                        send victim title "You're Bleeding!" for 2 seconds
                        damage the victim by 2
                        wait 13 seconds

on join:
    if {bleeding::%player's uuid%} is true:
        loop 1000 times:
            wait 2 seconds
            if player's health is more than 2:
                apply blindness of tier 1 without particles to player for 2 seconds
                send victim title "You're Bleeding!" for 2 seconds
                damage the player by 2
                wait 15 seconds
                if {hasta::%player's uuid%} is false:
                    exit loop

command /heal:
    trigger:
        set {bleeding::%victim's uuid%} to false




Now to the last skript. I have an action bar that is sent to the player every 2 seconds. I think this can load a lot of stress to the server. And I have a suggestion for this. If we can make it so that it is only sent to the player when it is updated (for example when player gets hit), we can reduce the stress of the server. But I don't know how to send action bar for a longer period of time with one line. Is that possible?

Code:
on join:
    while player is online:
        send action bar "Health: %player's health%/%player's max health% | Hunger: %player's hunger%/10" to player
        wait 2 seconds



Thank you in advance.
 
Last edited:
Well that won't stress ur server anyway, even if you do it every tick the impact would be unnoticable and maybe slightly noticable with hundreds of players
 
Well that won't stress ur server anyway, even if you do it every tick the impact would be unnoticable and maybe slightly noticable with hundreds of players
I know but my server is currently not that powerful and I have a lot of other things that will also stress my server. So I want things to be as optimized as possible.
 
I know but my server is currently not that powerful and I have a lot of other things that will also stress my server. So I want things to be as optimized as possible.
Even so, it still won’t stress your server
 
Hey everyone! I wrote three skripts and I am not sure if they are really optimised or not. I feel like events that are used on them can damage the performance of the server. Can you make them more performance friendly?




My first skript is this. It is a scope skript and when players sneak, they get a carved pumpkin with a sniper texture on their head.

Code:
on sneak toggle:
    if player is holding golden hoe:
        if player is not sneaking:
            set {scope::%player%} to true
            set {helmet::%player%} to player's helmet
            wait 1 tick
            equip player with carved pumpkin
            apply slowness of tier 255 without particles to player for 100000 seconds
            play sound "entity.bat.takeoff" at volume 1 at pitch 1 to player

on sneak toggle:
    if player is holding golden hoe:
        if player is sneaking:
            set {scope::%player%} to false
            remove slowness from player
            set player's helmet to {helmet::%player%}
            play sound "entity.bat.takeoff" at volume 1 at pitch 1 to player

on player's tool change:
    if {scope::%player%} is true:
        if player's tool is not golden hoe:
            cancel event




My second skript is a bleeding skript. When a players get hit, if damage is more that 2.5 hearts, they start to bleed and continue to bleed until they command /heal. I also added an "on join" event because without it, players don't bleed after they log off and log back on.

Code:
on damage:
    if damage cause is an attack:
        if {bleeding::%victim's uuid%} is false:
            set {_damage} to damage
            if {_damage} is more than 2.5:
                set {bleeding::%victim's uuid%} to true
                while victim is online:
                    wait 2 seconds
                    if {bleeding::%victim's uuid%} is true:
                        apply blindness of tier 1 without particles to victim for 2 seconds
                        send victim title "You're Bleeding!" for 2 seconds
                        damage the victim by 2
                        wait 13 seconds

on join:
    if {bleeding::%player's uuid%} is true:
        loop 1000 times:
            wait 2 seconds
            if player's health is more than 2:
                apply blindness of tier 1 without particles to player for 2 seconds
                send victim title "You're Bleeding!" for 2 seconds
                damage the player by 2
                wait 15 seconds
                if {hasta::%player's uuid%} is false:
                    exit loop

command /heal:
    trigger:
        set {bleeding::%victim's uuid%} to false




Now to the last skript. I have an action bar that is sent to the player every 2 seconds. I think this can load a lot of stress to the server. And I have a suggestion for this. If we can make it so that it is only sent to the player when it is updated (for example when player gets hit), we can reduce the stress of the server. But I don't know how to send action bar for a longer period of time with one line. Is that possible?

Code:
on join:
    while player is online:
        send action bar "Health: %player's health%/%player's max health% | Hunger: %player's hunger%/10" to player
        wait 2 seconds



Thank you in advance.
For your current Skripts, they likely won't stress your server. However, if your concerned about longer lines that could take longer to load/run, you can turn them into functions which can sometimes optimize code (not always)
 
I know but my server is currently not that powerful and I have a lot of other things that will also stress my server. So I want things to be as optimized as possible.
Many beginners believe that things like every tick, or every second will cause server lag. However, in reality, it's just the code that's implemented in those events that will affect their TPS. If your code is loading in a short amount of time, you should be fine.

I glanced at what you wrote and there might be a few inefficiencies in your code, but nothing game-breaking.