Skip to content

Best Practices

Avoiding Bugsplats

Variables must be properly purged, attempting to access certain obj properties after the obj has been deleted by the LoL client will result in LoL bugsplatting.

lua
local ex_obj

local function on_tick()
	if ex_obj and ex_obj.isDead then
		ex_obj = nil
	end
	--continue rest of your code
end

local function on_create_minion(obj)
	if not ex_obj then
		ex_obj = obj
	end
end

local function on_delete_minion(obj)
	if ex_obj and ex_obj.ptr==obj.ptr then
		ex_obj = nil
	end
end

cb.add(cb.tick, on_tick)
cb.add(cb.create_minion, on_create_minion)
cb.add(cb.delete_minion, on_delete_minion)

Do not use spell.obj outside of the spell callback.

lua
local wrong
local correct

local function on_process_spell(spell)
	if not wrong then
		wrong = spell
	end
	if not correct then
		correct = {
			windUpTime = spell.windUpTime,
			startPos = vec3(spell.startPos),
		}
	end
end

local function on_tick()
	if wrong then
		--DO NOT DO THIS, this is very likely to lead to bugsplats!
		print(wrong.windUpTime)
	end
	
	if correct then
		--Instead, do this
		print(correct.windUpTime)
	end
end

cb.add(cb.spell, on_process_spell)
cb.add(cb.tick, on_tick)

Do not attempt to access obj properties other than ptr in cb.delete_minion, cb.delete_particle or cb.delete_missile.

lua
local function on_delete_minion(obj)
	--wrong
	if obj.charName=='dontdothis' then
		--this is likely to lead to bugsplats
	end
	
	--correct, only check ptrs here
	if obj.ptr==someobj.ptr then
		someobj = nil
	end
end

local function on_delete_particle(obj)
	--wrong
	if obj.charName=='dontdothis' then
		--this is likely to lead to bugsplats
	end
	
	--correct, only check ptrs here
	if obj.ptr==someobj.ptr then
		someobj = nil
	end
end

local function on_delete_missile(obj)
	--wrong
	if obj.charName=='dontdothis' then
		--this is likely to lead to bugsplats
	end
	
	--correct, only check ptrs here
	if obj.ptr==someobj.ptr then
		someobj = nil
	end
end

cb.add(cb.create_minion, on_create_minion)
cb.add(cb.delete_particlee, on_delete_particle)
cb.add(cb.delete_missile, on_delete_missile)

Do not use the buffManager, use obj.buff instead.

Performance Tips

  • The cb.on_draw will cause lots performance, Dont loop objManager or do lots calulation in it.
  • Use objManager.minions['xxx'] to get the type of minions needed.
  • Some other tips for lua: using local variable
  • DONT use any NYI: The JIT Compiler's Drawback: Why Avoid NYI?
lua
-- normal
for i=0, objManager.minions[TEAM_ENEMY].size-1 do
	local obj = objManager.minions[TEAM_ENEMY][i]
end

-- use, local variable, better
local enemyMinions = objManager.minions[TEAM_ENEMY]
local enemyMinionsSize = enemyMinions.size
for i=0, enemyMinionsSize-1 do
	local obj = enemyMinions[i]
end

Internal Profiler Tools

  • Start game and click "Open Performance Monitor" in "Hanbot Settings"
  • In "Settings" tab, Check "Enable LuaJIT Profiler"
  • Press [-] to start record performance data and press [+] to stop
  • Download this profiler_tool and start profiler_gui
  • Open "profile.prof" (in the same directory with core.dll) and analyze performance (It is recommended to display the "Stats" window as "Aggregate Stats")