Lag

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

Frux

Member
Apr 11, 2020
10
0
0
25
Hello I was wondering if there is any way to reduce the lag this skript causes
Code:
on any movement:
  loop all players in radius 1 of the player:             
    if loop-player is "&bGuard":
      if player has 1 sugar named "{@c}":
        teleport player to location at {@resetlocation} in world "world"
        remove all sugar named "&fCocaine" from player's inventory
        message "&cAll of your {@c} &chas been confiscated from your inventory!"
      if player has 1 nether wart named "{@m}":
        teleport player to location at {@resetlocation} in world "world"
        remove all nether wart named "{@m}" from player's inventory
        message "&cAll of your {@m} &chas been confiscated from your inventory!"
      if player has 1 wheat named "{@w}":
        teleport player to location at {@resetlocation} in world "world"
        remove all wheat named "{@w}" from player's inventory
        message "&cAll of your {@w} &chas been confiscated from your inventory!"
 
Hello I was wondering if there is any way to reduce the lag this skript causes
Code:
on any movement:
  loop all players in radius 1 of the player:            
    if loop-player is "&bGuard":
      if player has 1 sugar named "{@c}":
        teleport player to location at {@resetlocation} in world "world"
        remove all sugar named "&fCocaine" from player's inventory
        message "&cAll of your {@c} &chas been confiscated from your inventory!"
      if player has 1 nether wart named "{@m}":
        teleport player to location at {@resetlocation} in world "world"
        remove all nether wart named "{@m}" from player's inventory
        message "&cAll of your {@m} &chas been confiscated from your inventory!"
      if player has 1 wheat named "{@w}":
        teleport player to location at {@resetlocation} in world "world"
        remove all wheat named "{@w}" from player's inventory
        message "&cAll of your {@w} &chas been confiscated from your inventory!"

The player move event is one of the most laggy events in the game.

Use the move event wisely u have to think about the order of ur code so the instensive code gets less triggered.

so lets break down the elements:

Item removement (Effect)
Message (Effect)
Teleport (Effect)
Item Check (Condition)
IG Closeby Npc Check Named Guard (Condition)

Now we have 2 conditions:

Item Check (Condition)
IG Closeby Npc Check Named Guard (Condition)

What would be smarter?

Check guards for every player or check guards for only people with those items?

With those items!

So it would look like this:

Code:
On any movement:
    if player has 1 sugar named "{@c}":
        set {_y} to true
    if player has 1 nether wart named "{@m}"
        set {_y} to true
    if player has 1 wheat named "{@w}":
        set {_y} to true
    if {_y} is true:
        loop all players in radius 1 of the player:
               if loop-player is "&bGuard":
                teleport player to location at {@resetlocation} in world "world"
                ETC
                stop

There is a better way but i am out of time for now might get back to this
 
The player move event is one of the most laggy events in the game.

Use the move event wisely u have to think about the order of ur code so the instensive code gets less triggered.

so lets break down the elements:

Item removement (Effect)
Message (Effect)
Teleport (Effect)
Item Check (Condition)
IG Closeby Npc Check Named Guard (Condition)

Now we have 2 conditions:

Item Check (Condition)
IG Closeby Npc Check Named Guard (Condition)

What would be smarter?

Check guards for every player or check guards for only people with those items?

With those items!

So it would look like this:

Code:
On any movement:
    if player has 1 sugar named "{@c}":
        set {_y} to true
    if player has 1 nether wart named "{@m}"
        set {_y} to true
    if player has 1 wheat named "{@w}":
        set {_y} to true
    if {_y} is true:
        loop all players in radius 1 of the player:
               if loop-player is "&bGuard":
                teleport player to location at {@resetlocation} in world "world"
                ETC
                stop

There is a better way but i am out of time for now might get back to this
Epic! Will do.
 
Status
Not open for further replies.