Skript

Skript

743k Downloads

Eating away TPS

Blizzmond opened this issue ยท 4 comments

commented

Skript/Server Version

skript 2.8.3
server 1.20.4 git-paper-485

Bug Description

When running the code TPS drops down massively, around -0.5 tps per 1 sec, and becomes worse and worse

Expected Behavior

Not lag because its just looping a table and a very small one

Steps to Reproduce

execute admin_addbooster Username magicfind 1000 and enable the every 1 second loop

arg 1 - player
arg 2 - booster (text, can be anything)
arg 3 - time (number, in seconds)

Errors or Screenshots

No response

Other

function checkGlobalBooster(booster: text):
	set {_amtActive} to 0
	loop {globalBoosters::%{_booster}%::*}:
		broadcast "&c&l[DEBUG]&f 1" # only broadcasts per 1 second
		set {_p} to loop-index parsed as offline player
		### CHECK FOR ACTIVE BOOSTER
		if {globalBoosters::%{_booster}%::%{_p}'s uuid%::active} is true:
			add 1 to {_amtActive}
			remove 1 from {globalBoosters::%{_booster}%::%{_p}'s uuid%::duration}
			if {globalBoosters::%{_booster}%::%{_p}'s uuid%::duration} <= 0:
				remove {_p}'s uuid from {globalBoosters::%{_booster}%::*}
		if {_amtActive} > 0:
			stop
		###
		if {_amtActive} is 0:
			if {globalBoosters::%{_booster}%::%{_p}'s uuid%::active} is false:
				set {globalBoosters::%{_booster}%::%{_p}'s uuid%::active} to true
				set {_prefix} to {CHAT::%{_p}'s uuid%::PREFIX}
				if {_booster} is "magicfind":
					if {profile::%{_p}'s uuid%::staffrank} is "owner":
						send "%nl%%{_prefix}%%{_p}%&a's &d&lMAGIC FIND GLOBAL BOOSTER&a has been activated! &d(+100%%) %nl%" to {_p}

function addPlayerGlobalBooster(p: player,booster: text,time: num):
	add {_p}'s uuid to {globalBoosters::%{_booster}%::*}
	set {globalBoosters::%{_booster}%::%{_p}'s uuid%::duration} to {_time}
	set {globalBoosters::%{_booster}%::%{_p}'s uuid%::active} to false

every 1 second:
	checkGlobalBooster("magicfind")

command admin_addbooster [<offline player>] [<text>] [<num>]:
	permission: "*"
	trigger:
		set {_p} to arg-1
		set {_booster} to arg-2
		set {_time} to arg-3
		if {_p} is set:
			if {_booster} is set:
				if {_time} is set:
					addPlayerGlobalBooster({_p},{_booster},{_time})

Agreement

  • I have read the guidelines above and affirm I am following them with this report.
commented

Thanks for the information, but if the player is not online woudnt it return as none?

Yes. Looking more closely, you don't even need to parse online players. You already have their uuid, just use it.

commented

Parsing offline players is not something we can speed up. It requires your server to go look through the player data files to find the right player data file. This will always be slow.

To fix your issues, don't parse offline players. Just parse as player, and only online players will be successfully parsed. You can handle the offline players without parsing them.

commented

Thanks for the information, but if the player is not online woudnt it return as none?

commented

Thank you so much, apologies for making this post