How to make this script 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.

xultraalphax

New Member
Jul 3, 2020
6
0
0
23
Hello! I want to make this skript more optimized because it laggs my server so much.
Code:
command /grass [<text>]:
  aliases: /fű, /fu, /weed
  trigger:
    if arg-1 is not set:
      if {grass.%player%} is false:
        set {grass.%player%} to true
        send "&6MN &8»&7 Sikeresen &ebekapcsoltad&7 a növények eltűntetését!"
      else:
        set {grass.%player%} to false
        send "&6MN &8»&7 Sikeresen &ekikapcsoltad&7 növények eltűntetését!"
        if {%player%.list::*} is set:
          loop {%player%.list::*}:
            make player see block at loop-value as block at loop-value
            remove loop-value from {%player%.list::*}
    else if arg-1 is set:
      if arg-1 is "reload" or "rl":
        execute player command "sk reload MoszkvaGrass"
        send "&6MN &8»&7 Plugin sikeresen újratöltve!"
      else if arg-1 is "size":
        send "%size of {%player%.list::*}%"
      else:
        send "&6MN &8»&7 Helyes használat: &c/grass"

on click:
  send "%player's targeted block%" to player

on quit:
  if {grass.%player%} is true:
    set {grass.%player%} to false

on any movement:
  if {grass.%player%} is true:
    if {at.%player%} is not set:
      set {at.%player%} to location of block at player
    else if distance between block at player and {at.%player%} is higher than 1:
      set {at.%player%} to location of block at player
      loop all blocks in radius 6 around {at.%player%}:
        if {%player%.list::*} does not contain location of loop-block:
          if loop-block is double tall grass or long fern or sunflower or lilac or rose bush or peony:
            make player see loop-block as air
            add location of loop-block to {%player%.list::*}

on command "/grass":
  wait 1 tick
  while {grass.%player%} is true:
    if {%player%.list::*} is set:
      loop {%player%.list::*}:
        if distance between {at.%player%} and block at loop-value is higher than 6:
          remove loop-value from {%player%.list::*}
          make player see block at loop-value as block at loop-value
      wait 5 tick
    wait 5 tick
 
Hello! I want to make this skript more optimized because it laggs my server so much.
Code:
command /grass [<text>]:
  aliases: /fű, /fu, /weed
  trigger:
    if arg-1 is not set:
      if {grass.%player%} is false:
        set {grass.%player%} to true
        send "&6MN &8»&7 Sikeresen &ebekapcsoltad&7 a növények eltűntetését!"
      else:
        set {grass.%player%} to false
        send "&6MN &8»&7 Sikeresen &ekikapcsoltad&7 növények eltűntetését!"
        if {%player%.list::*} is set:
          loop {%player%.list::*}:
            make player see block at loop-value as block at loop-value
            remove loop-value from {%player%.list::*}
    else if arg-1 is set:
      if arg-1 is "reload" or "rl":
        execute player command "sk reload MoszkvaGrass"
        send "&6MN &8»&7 Plugin sikeresen újratöltve!"
      else if arg-1 is "size":
        send "%size of {%player%.list::*}%"
      else:
        send "&6MN &8»&7 Helyes használat: &c/grass"

on click:
  send "%player's targeted block%" to player

on quit:
  if {grass.%player%} is true:
    set {grass.%player%} to false

on any movement:
  if {grass.%player%} is true:
    if {at.%player%} is not set:
      set {at.%player%} to location of block at player
    else if distance between block at player and {at.%player%} is higher than 1:
      set {at.%player%} to location of block at player
      loop all blocks in radius 6 around {at.%player%}:
        if {%player%.list::*} does not contain location of loop-block:
          if loop-block is double tall grass or long fern or sunflower or lilac or rose bush or peony:
            make player see loop-block as air
            add location of loop-block to {%player%.list::*}

on command "/grass":
  wait 1 tick
  while {grass.%player%} is true:
    if {%player%.list::*} is set:
      loop {%player%.list::*}:
        if distance between {at.%player%} and block at loop-value is higher than 6:
          remove loop-value from {%player%.list::*}
          make player see block at loop-value as block at loop-value
      wait 5 tick
    wait 5 tick
You're using ''on any movement'' event, no one would recommend u to use that, it decrease ur server performance

use while instead of on any movement

Code:
on join:
    wait 1 second
    while {grass.%player%} is true:
        if {at.%player%} is not set:
            set {at.%player%} to location of block at player
        else if distance between block at player and {at.%player%} is higher than 1:
            set {at.%player%} to location of block at player
            loop all blocks in radius 6 around {at.%player%}:
                if {%player%.list::*} does not contain location of loop-block:
                    if loop-block is double tall grass or long fern or sunflower or lilac or rose bush or peony:
                        make player see loop-block as air
                        add location of loop-block to {%player%.list::*}
        wait 1 second
 
Last edited:
This is the code currently, any suggestions to make it more efficient?

Code:
command /grass [<text>]:
  aliases: /fű, /fu, /weed
  trigger:
    if arg-1 is not set:
      if {grass.%player%} is false:
        set {grass.%player%} to true
        send "&6MN &8»&7 Sikeresen &ebekapcsoltad&7 a növények eltűntetését!"
      else:
        set {grass.%player%} to false
        send "&6MN &8»&7 Sikeresen &ekikapcsoltad&7 növények eltűntetését!"
        if {%player%.list::*} is set:
          loop {%player%.list::*}:
            make player see block at loop-value as block at loop-value
            remove loop-value from {%player%.list::*}
    else if arg-1 is set:
      if arg-1 is "reload" or "rl":
        execute player command "sk reload MoszkvaGrass"
        send "&6MN &8»&7 Plugin sikeresen újratöltve!"
      else if arg-1 is "size":
        send "%size of {%player%.list::*}%"
      else:
        send "&6MN &8»&7 Helyes használat: &c/grass"

on quit:
  if {grass.%player%} is true:
    set {grass.%player%} to false

on command "/grass":
  wait 1 second
  while {grass.%player%} is true:
    if {at.%player%} is not set:
      set {at.%player%} to location of block at player
    else if distance between block at player and {at.%player%} is higher than 1:
      set {at.%player%} to location of block at player
      loop all blocks in radius 6 around {at.%player%}:
        if {%player%.list::*} does not contain location of loop-block:
          if loop-block is double tall grass or long fern or sunflower or lilac or rose bush or peony:
            make player see loop-block as air
            add location of loop-block to {%player%.list::*}
    wait 5 tick

on command "/grass":
  wait 1 tick
  while {grass.%player%} is true:
    if {%player%.list::*} is set:
      loop {%player%.list::*}:
        if distance between {at.%player%} and block at loop-value is higher than 6:
          remove loop-value from {%player%.list::*}
          make player see block at loop-value as block at loop-value
      wait 5 tick
    wait 5 tick
 
Status
Not open for further replies.