Skip to main content

Using Hashes

Problem

In LS we prefer using hashes where we can instead of string comparisons. This is what the game does too, number comparison is faster and more reliable.

In our case Hash is unsigned int number built from certain string. There are several hash methods available:

Solution

  • Use appropriate hash methods where you can.
  • Avoid calculating hashes in your loop. Instead define them once on script initialization.
  • Avoid hardcoding hashes. For better readability of your code just get hash from string using appropriate hash method.

Examples

Game.fnvhash(str)

Used in buffs, DrawEffectCircle, other production ready Renderer functions, SpellData, etc.

Check for Annie passive buff
local hash_AnniePassivePrimed = Game.fnvhash("anniepassiveprimed")
local buff = Game.localPlayer:FindBuff(hash_AnniePassivePrimed)

Game.HashStringSDBM(str)

Used in AIBaseClient.hash, etc.

This condition is true
local match = Game.HashStringSDBM(Game.localPlayer.charName) == Game.localPlayer.hash
Get Lulu's Faerie
local function GetFaerie()
local hash_LuluFaerie = Game.HashStringSDBM("lulufaerie")
for _, obj in ObjectManager.allAIBaseClients:pairs() do
if obj:IsValid() and obj.team == caster.team and obj.hash == LuluFaerieHash then
return obj
end
end
end

Game.spelldataHash(str)

Used in DamageLib maps.

Get Irelia Q Damage
local hash_IreliaQ = Game.spelldataHash("IreliaQ")
local function GetQDamage(target)
return DamageLib.GetSpellDamage(hash_IreliaQ, Game.localPlayer, target, false, 0, SpellSlot.Q)
end