make this more efficient?

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

FallingCatus

Member
Jun 29, 2017
38
0
6
33
Hey all so i wrote this skript to handle effects on a server i am building but i have noticed over time the server is lagging a little and when this skript is enabled some players timeout when joining but when disabled it is fine.

I have no where mastered skirpt yet and will still class myself as basic. sorry.
anyone know how i can make this more efficient?


Code:
on left click:
    player is holding glass or white stained glass or orange stained glass or magenta stained glass or light blue stained glass or yellow stained glass or lime stained glass or pink stained glass or gray stained glass or light gray stained glass or cyan stained glass or purple stained glass or blue stained glass or brown stained glass or green stained glass or red stained glass or black stained glass:
        player is sneaking
        if player is wearing a helmet or glass or white stained glass or orange stained glass or magenta stained glass or light blue stained glass or yellow stained glass or lime stained glass or pink stained glass or gray stained glass or light gray stained glass or cyan stained glass or purple stained glass or blue stained glass or brown stained glass or green stained glass or red stained glass or black stained glass:
            send "&dCosmic &8» &7please remove your current helmet and try again."
        if player is not wearing a helmet or glass or white stained glass or orange stained glass or magenta stained glass or light blue stained glass or yellow stained glass or lime stained glass or pink stained glass or gray stained glass or light gray stained glass or cyan stained glass or purple stained glass or blue stained glass or brown stained glass or green stained glass or red stained glass or black stained glass:
            equip player with tool
            remove 1 of tool from tool


#--- Main world ---#

on player world change:
    wait 2 seconds
    player is in "world":
        remove slow falling from player
        remove jump boost from player
        remove wither effect from player
        wait 1 seconds
        apply potion of slow falling of tier 1 without any particles to the player for 1 day
        apply potion of jump boost of tier 2 without any particles to the player for 1 day

every 5 seconds in world "world":
    loop all players in world "world":
        if loop-player doesn't have slow falling:
            apply potion of slow falling of tier 1 without any particles to the loop-player for 1 day
        if loop-player doesn't have jump boost:
            apply potion of jump boost of tier 2 without any particles to the loop-player for 1 day

#----------------------#

#--- The Moon ---#

on player world change:
    wait 2 seconds
    player is in "Moon":
        remove slow falling from player
        remove jump boost from player
        remove wither effect from player
        wait 1 seconds
        apply potion of slow falling of tier 4 without any particles to the player for 1 day
        apply potion of jump boost of tier 4 without any particles to the player for 1 day

every 5 seconds in world "Moon":
    loop all players in world "Moon":
        if loop-player doesn't have slow falling:
            apply potion of slow falling of tier 4 without any particles to the loop-player for 1 day
        if loop-player doesn't have jump boost:
            apply potion of jump boost of tier 4 without any particles to the loop-player for 1 day
        if loop-player is not wearing glass or white stained glass or orange stained glass or magenta stained glass or light blue stained glass or yellow stained glass or lime stained glass or pink stained glass or gray stained glass or light gray stained glass or cyan stained glass or purple stained glass or blue stained glass or brown stained glass or green stained glass or red stained glass or black stained glass:
            execute console command "/tm msg %loop-player% &d&lSuit Up!\n&7&lGlass Helmet, Chest, Legs and Boots!"
            apply potion of wither of tier 1 without any particles to the loop-player for 5 seconds
        if loop-player is not wearing a chestplate:
            execute console command "/tm msg %loop-player% &d&lSuit Up!\n&7&lGlass Helmet, Chest, Legs and Boots!"
            apply potion of wither of tier 1 without any particles to the loop-player for 5 seconds
        if loop-player is not wearing a leggings:
            execute console command "/tm msg %loop-player% &d&lSuit Up!\n&7&lGlass Helmet, Chest, Legs and Boots!"
            apply potion of wither of tier 1 without any particles to the loop-player for 5 seconds
        if loop-player is not wearing a boots:
            execute console command "/tm msg %loop-player% &d&lSuit Up!\n&7&lGlass Helmet, Chest, Legs and Boots!"
            apply potion of wither of tier 1 without any particles to the loop-player for 5 seconds



#---------------------#

#--- The Core ---#

on player world change:
    wait 2 seconds
    player is in "world_nether":
        remove slow falling from player
        remove jump boost from player
        remove wither effect from player
        wait 1 seconds
        apply potion of slow falling of tier 1 without any particles to the player for 1 day
        apply potion of jump boost of tier 2 without any particles to the player for 1 day

every 5 seconds in world "world_nether":
    loop all players in world "world_nether":
        if loop-player doesn't have slow falling:
            apply potion of slow falling of tier 1 without any particles to the loop-player for 1 day
        if loop-player doesn't have jump boost:
            apply potion of jump boost of tier 2 without any particles to the loop-player for 1 day
        if loop-player is not wearing glass or white stained glass or orange stained glass or magenta stained glass or light blue stained glass or yellow stained glass or lime stained glass or pink stained glass or gray stained glass or light gray stained glass or cyan stained glass or purple stained glass or blue stained glass or brown stained glass or green stained glass or red stained glass or black stained glass:
            execute console command "/tm msg %loop-player% &c&lSuit Up!\n&7&lGlass Helmet, Chest, Legs and Boots!"
            set loop-player on fire
        if loop-player is not wearing a chestplate:
            execute console command "/tm msg %loop-player% &c&lSuit Up!\n&7&lGlass Helmet, Chest, Legs and Boots!"
            set loop-player on fire
        if loop-player is not wearing a leggings:
            execute console command "/tm msg %loop-player% &c&lSuit Up!\n&7&lGlass Helmet, Chest, Legs and Boots!"
            set loop-player on fire
        if loop-player is not wearing a boots:
            execute console command "/tm msg %loop-player% &c&lSuit Up!\n&7&lGlass Helmet, Chest, Legs and Boots!"
            set loop-player on fire


#---------------------#

#--- k2 ---#

on player world change:
    wait 2 seconds
    player is in "k2":
        remove slow falling from player
        remove jump boost from player
        remove wither effect from player
        wait 1 seconds
        apply potion of slow falling of tier 1 without any particles to the player for 1 day
        apply potion of jump boost of tier 1 without any particles to the player for 1 day

every 5 seconds in world "k2":
    loop all players in world "k2":
        if loop-player doesn't have slow falling:
            apply potion of slow falling of tier 1 without any particles to the loop-player for 1 day
        if loop-player doesn't have jump boost:
            apply potion of jump boost of tier 2 without any particles to the loop-player for 1 day

#----------------------#
 
The problem with your code

you use many loop unnecessarily (Every X seconds, loop all player, While ETC)

you should avoid using it unnecessarily! use only when it is extremely necessary
 
Status
Not open for further replies.