Hello
wondering which scripts can eat the cpu ?
wondering which scripts can eat the cpu ?
Hello
wondering which scripts can eat the cpu ?
I know it is depending on how i script, and ofc no one can magically tell me which script causes the lags. I just wanted to do more focus on which scripts maybe can make lags ( global events or creature events ).This is too broad of a question. It all depends on how you script and what exactly you have, nobody is going to be able to magically tell you what you need to look for. Scripts shouldn't even be the problem anyways, if you're having issues with cpu usage you should probably upgrade your host. If anything, parts of the source code are to blame for most of the cpu usage, getSpectators and path matching take the most resources out of anything else in the sources.
Can you explain more ?Typically you will want to look at any scripts that contain loops.
I tried to disable what i have added lately but the cpu usage still high.Maybe backtracking in what you have added lately and when did this start to happen?
I saw this solution before and inside the post delusion saying add it to any lib.This is a good way to check it out
![]()
[ANY TFS] Catch scripts that freeze server
put this code in a lib file (global.lua if tfs 1.x): local start = os.time() local linecount = 0 debug.sethook(function(event, line) linecount = linecount + 1 if os.time() - start >= 1 then if linecount >= 30000 then print(string.format("possible infinite loop in...otland.net
Well i added a new lib with this code.This is a good way to check it out
![]()
[ANY TFS] Catch scripts that freeze server
put this code in a lib file (global.lua if tfs 1.x): local start = os.time() local linecount = 0 debug.sethook(function(event, line) linecount = linecount + 1 if os.time() - start >= 1 then if linecount >= 30000 then print(string.format("possible infinite loop in...otland.net
possible infinite loop in file @data/npc/scripts/upgrading man.lua near line 6
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
-- OTServ event handling functions end
function creatureSayCallback(cid, type, msg)
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
if(not npcHandler:isFocused(cid)) then
return false
end
if msgcontains(msg, 'offer') then
selfSay('{Equipments Upgrading Gem} for 25 uber tokens and {Weapons Upgrading Gem} for 30 uber tokens.', cid)
elseif msgcontains(msg, 'Equipments Upgrading Gem') then
if getPlayerItemCount(cid,302) >= 25 then
selfSay('Did you bring me the {25} uber tokens ?', cid)
talk_state = 1
else
selfSay('I need {25} uber tokens, to give you the {Equipments Upgrading Gem}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
if getPlayerItemCount(cid,302) >= 25 then
if doPlayerRemoveItem(cid,302, 25) == TRUE then
selfSay('Take your {Equipments Upgrading Gem}.', cid)
doPlayerAddItem(cid, 7761, 1)
end
else
selfSay(item, cid)
end
elseif msgcontains(msg, 'Weapons Upgrading Gem') then
if getPlayerItemCount(cid,302) >= 30 then
selfSay('Did you bring me the {30} uber tokens ?', cid)
talk_state = 2
else
selfSay('I need {30} uber tokens, to give you the {Weapons Upgrading Gem}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 2 then
talk_state = 0
if getPlayerItemCount(cid,302) >= 30 then
if doPlayerRemoveItem(cid,302, 30) == TRUE then
selfSay('Take your {Weapons Upgrading Gem}.', cid)
doPlayerAddItem(cid, 7760, 1)
end
else
selfSay(item, cid)
end
elseif msgcontains(msg, 'weapons upgrading gem') then
if getPlayerItemCount(cid,302) >= 30 then
selfSay('Did you bring me the {30} uber tokens ?', cid)
talk_state = 3
else
selfSay('I need {30} uber tokens, to give you the {Weapons Upgrading Gem}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 3 then
talk_state = 0
if getPlayerItemCount(cid,302) >= 30 then
if doPlayerRemoveItem(cid,302, 30) == TRUE then
selfSay('Take your {Weapons Upgrading Gem}.', cid)
doPlayerAddItem(cid, 7760, 1)
end
else
selfSay(item, cid)
end
elseif msgcontains(msg, 'equipments upgrading gem') then
if getPlayerItemCount(cid,302) >= 25 then
selfSay('Did you bring me the {25} uber tokens ?', cid)
talk_state = 4
else
selfSay('I need {25} uber tokens, to give you the {Equipments Upgrading Gem}. Come back when you have them.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 4 then
talk_state = 0
if getPlayerItemCount(cid,302) >= 25 then
if doPlayerRemoveItem(cid,302, 25) == TRUE then
selfSay('Take your {Equipments Upgrading Gem}.', cid)
doPlayerAddItem(cid, 7761, 1)
end
else
selfSay(item, cid)
end
elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 4) then
selfSay('Ok then.', cid)
talk_state = 0
end
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())