• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Lua] Solved

Hello hive,

I have the following function:

Lua:
function SetSpellBookAbilitesLevels(u, spellbookcode, lvl)
  local spelllist = BlzGetAbilityStringLevelField(BlzGetUnitAbility(u, spellbookcode), ABILITY_SLF_SPELL_LIST, GetUnitAbilityLevel(u, spellbookcode - 1))
  local startIndex = 0
  local skillcode = nil
  if spelllist ~= nil then
    while true do
      if startIndex + 3 >= StringLength(spelllist) then
        break
      end
      skillcode = FourCC(SubString(spelllist, startIndex, startIndex + 4))
      SetUnitAbilityLevel(u, skillcode, lvl)
      startIndex = startIndex + 5
    end
  end
end

Lua:
function Level_Up_Spellbook_Conditions()
  if (not (GetUnitAbilityLevelSwapped(FourCC("A0YI"), GetTriggerUnit()) > 0)) then
    return false
  end
  if (not (GetHeroLevel(GetTriggerUnit()) >= 12)) then
    return false
  end
  if (not (ModuloInteger(GetHeroLevel(GetTriggerUnit()), 6) == 0)) then
    return false
  end
  return true
end

The only 2 previous lines in the trigger actions are enabling 2 triggers, though they will be enabled already once the spellbook levels should go to 2+, and then
Lua:
 SetSpellBookAbilitesLevels(GetTriggerUnit(), FourCC("A0YI"), (GetHeroLevel(GetTriggerUnit()) // 6) - 1)

The event is EVENT_PLAYER_HERO_LEVEL

The issue is that sometimes it fails to update the levels of the spells in the spell book. If it fails at level 18, it fails to update the levels for the rest of that session even if the conditions are met again at lvl24 and so on. However this only happens in live games and even when I try to re-create it in a test map it I can't. It has happened multiple times though.
 
Last edited:
The correct code is

Lua:
function SetSpellBookAbilitesLevels(u, spellbookcode, lvl)
local spelllist = BlzGetAbilityStringLevelField(BlzGetUnitAbility(u, spellbookcode), ABILITY_SLF_SPELL_LIST, GetUnitAbilityLevel(u, spellbookcode ) - 1)
local startIndex = 0
local skillcode = nil
if spelllist ~= nil then
while true do
if startIndex + 3 >= StringLength(spelllist) then
break
end
skillcode = FourCC(SubString(spelllist, startIndex, startIndex + 4))
SetUnitAbilityLevel(u, skillcode, lvl)
startIndex = startIndex + 5
end
end
end
 
Back
Top