• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua How to check which scripts chewing server preformence?

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,780
Solutions
31
Reaction score
2,299
Location
Sweden?
Yo,

as the title says. I always wonder how to check it?
 
:o I will die then xD Its to many to disable and enable xD

Any other suggestions :D?
 
So if i example using this script:
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	doCreatureSay(cid,"Dont worry, i won't cause any lags",TALKTYPE_ORANGE_1)
end

And someone spam clicking on that item to say that text. Will it cause any lags?
 
And someone spam clicking on that item to say that text. Will it cause any lags?
If your server is a twenty-year computer it may have little problem with this.
But for the present machine query is a fraction of a second.
 
I will use this thread if it is okay. I wonder if checking an area each 10 second is considered to be chewing server performance? I am using it as a part for a last-man-standing event (credits to teckman for the loops)
The area is not wide (total of 2240 tiles)

Here is the part of the script that checks:

LUA:
	cfg = {
		[1] = {x = 32109, y = 32552, z = 11},
		[2] = {x = 32164, y = 32591, z = 11}
	}
	
	player = {}
	
	for x = cfg.area[1].x, cfg.area[2].x do
		for y = cfg.area[1].y, cfg.area[2].y do
			for z = cfg.area[1].z, cfg.area[2].z do
				if(isPlayer(getTopCreature({x=x, y=y, z=z}).uid) == 1) then
					table.insert(player, getTopCreature({x=x, y=y, z=z}).uid)
				end
			end
		end
	end
 
I will use this thread if it is okay. I wonder if checking an area each 10 second is considered to be chewing server performance? I am using it as a part for a last-man-standing event (credits to teckman for the loops)
The area is not wide (total of 2240 tiles)

Here is the part of the script that checks:

LUA:
	cfg = {
		[1] = {x = 32109, y = 32552, z = 11},
		[2] = {x = 32164, y = 32591, z = 11}
	}
	
	player = {}
	
	for x = cfg.area[1].x, cfg.area[2].x do
		for y = cfg.area[1].y, cfg.area[2].y do
			for z = cfg.area[1].z, cfg.area[2].z do
				if(isPlayer(getTopCreature({x=x, y=y, z=z}).uid) == 1) then
					table.insert(player, getTopCreature({x=x, y=y, z=z}).uid)
				end
			end
		end
	end


Depends on how big the area is in this case a little bit of performance Ed but not enough to matter and this is only checked when players are in or event is activated so it will only use that bit when it's on
 
I will use this thread if it is okay. I wonder if checking an area each 10 second is considered to be chewing server performance? I am using it as a part for a last-man-standing event (credits to teckman for the loops)
The area is not wide (total of 2240 tiles)

Here is the part of the script that checks:

LUA:
	cfg = {
		[1] = {x = 32109, y = 32552, z = 11},
		[2] = {x = 32164, y = 32591, z = 11}
	}
	
	player = {}
	
	for x = cfg.area[1].x, cfg.area[2].x do
		for y = cfg.area[1].y, cfg.area[2].y do
			for z = cfg.area[1].z, cfg.area[2].z do
				if(isPlayer(getTopCreature({x=x, y=y, z=z}).uid) == 1) then
					table.insert(player, getTopCreature({x=x, y=y, z=z}).uid)
				end
			end
		end
	end

I know it's offtopic, but use instead this: getSpectators(centerPos, rangex, rangey[, multifloor = false])
 
I use two different scripts, one that sends them in, checking if there are more than 4 people online, problem is that I don't run that script as frequently as it has to be, I need to check for a winner, so this script (the second one a.k.a the checker) is making checks each 10th second, even though the event is each 3rd hour or what ever it may be.

I looked on the memory usage on the server exe when the script was checking, and when it wasn't and there difference was small.

Really looking for a better solution to "check for a winner", at the moment it's very basic, it checks the are if there is only one Player in it (which obviously then would be the winner of the event), but I cannot use the same script as the one sending them in because the interval is too high.

If I would use one script for the event (and not checking frequently)
Example: Script initiate each 3rd hour, sending people in and checking if enough players online, they war until there is one guy left, when there only is one guy left, he has to wait the remaining time for the script to initiate again

Hopefully I explained well enough. I know this is not a support thread but if anyone got some suggestions on how to do it better, I'd be glad to hear!
 
You could add in a function into each script that calculates how much time it takes each script to run, then have it save that information in a file.
I would also add in a counter for how many times each script is run (just make a global storage value for each script, and make it add 1 each time the script runs)

Then what you do is, check the scripts that are run the most times, then check how long they take to run. Tada, you now know the scripts that cause the most lag.

I think I am going to script this on my servers today... it is actually a really decent idea.
 
I know it's offtopic, but use instead this: getSpectators(centerPos, rangex, rangey[, multifloor = false])

Unfamiliar with this function, can you give me an example on how to use it?

You could add in a function into each script that calculates how much time it takes each script to run, then have it save that information in a file.
I would also add in a counter for how many times each script is run (just make a global storage value for each script, and make it add 1 each time the script runs)

Then what you do is, check the scripts that are run the most times, then check how long they take to run. Tada, you now know the scripts that cause the most lag.

I think I am going to script this on my servers today... it is actually a really decent idea.

I will try your method, thanks for the help
 
LUA:
 getSpectators(centerPos, rangex, rangey[, multifloor = false])
Easy to use:
For example:
LUA:
local spectators = getSpectators(getCreaturePosition(cid), 7, 5, 0)
for _, tid in ipairs(spectators) do
     if isPlayer(tid) then
          doCreatureSay(tid, "I am a player", 1)
     elseif isMonster(tid) then 
          doCreatureSay(tid, "I am a creature", 1)
     elseif isSummon(tid) then
          doCreatureSay(tid, "I am a summon", 1)
     elseif isNpc(tid) then
          doCreatureSay(tid, "I am a NPC", 1)
     end
end

The above script grabs all characters on your screen and makes them identify themselves.
 
onThink scripts in players or npc, since they execute very quickly in a constant loop
reload npc twice or thrice and expect server crash
 
I still don't understand the 7, 5, but I guess it's the range from center position?

Look at the function at the top of his post, you can see the parameters.
Yes, it is the range in x-axis and y-axis from the center position.
 
I still don't understand the 7, 5, but I guess it's the range from center position?

7 is the range in the x-axis
5 is the range in the y-axis
then u have the rectangle with corners

A(centerpos.x-7, centerpos.y-5)
B(centerpos.x+7, centerpos.y+5)
 
Last edited:
7 is the range in the x-axis
5 is the range in the y-axis
then u have the rectangle with corners

A(centerpos.x-7, centerpos.y-5)
B(centerpos.x+7, centerpos.y+5)

Thank you for explaining it for me, now I understand and others will learn from this thread.

onThink scripts in players or npc, since they execute very quickly in a constant loop
reload npc twice or thrice and expect server crash

About the checks, I solved it temporarily by checking for globalStorageValue

LUA:
function onThink(...)
	if globalStorage == 1 then
		runScript
		return 1
	end
return 0
end

Look at the function at the top of his post, you can see the parameters.
Yes, it is the range in x-axis and y-axis from the center position.

I got confused by the getPlayerPosition(cid)
 
Last edited:
Back
Top