function onUse(cid, item, fromPosition, itemEx, toPosition)
doCreatureSay(cid,"Dont worry, i won't cause any lags",TALKTYPE_ORANGE_1)
end
If your server is a twenty-year computer it may have little problem with this.And someone spam clicking on that item to say that text. Will it cause any lags?
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
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])
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.
getSpectators(centerPos, rangex, rangey[, multifloor = false])
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
I still don't understand the 7, 5, but I guess it's the range from 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)
onThink scripts in players or npc, since they execute very quickly in a constant loop
reload npc twice or thrice and expect server crash
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.