Set hero and ability level

Hi, I just started modding.

How do I set the level of each ability individually at the start of the game?

Comments

  • edited August 2015 Posts: 77

    levels can be set in npc_heros

    "Level" "25"
    

    and add this your events.lua

    function GameMode:OnHeroInGame(hero)
        for i=0,15 do
            local ability = hero:GetAbilityByIndex(i)
            if ability then
                ability:SetLevel(ability:GetMaxLevel())
            end
        end
    end
    

    this automaticlly sets all abilities to max level.

  • edited August 2015 Posts: 10

    Setting the hero level in npc_heroes doesn't seem to work for me.

    What I've been trying for setting ability levels is similar to your method but it only seems to work for some heroes.

    function GameMode:OnHeroInGame(sven)
      sven:GetAbilityByIndex(0):SetLevel(0);
      sven:GetAbilityByIndex(1):SetLevel(2);
      sven:GetAbilityByIndex(2):SetLevel(3);
      sven:GetAbilityByIndex(3):SetLevel(1);
    end
    
  • Posts: 89

    What you can try is

    local ability = sven:FindAbilityByName("npc_ability_name")
    ability:SetLevel(4)
    

    TAKING IN SPELL REQUESTS (Not too advanced). PM ME if you need help. https://moddota.com/forums/profile/4159/Rubician

  • Yeah, that works better, thanks.

    The way I was doing it, every hero was getting the ability configuration of the last hero in my list, still not sure why.

  • This was the most reliable way I found to do it.

    function GameMode:OnHeroInGame(sven)
    for i=0,5 do
      sven:HeroLevelUp(true);
    end
      sven:UpgradeAbility(sven:FindAbilityByName("sven_gods_strength"));
      sven:UpgradeAbility(sven:FindAbilityByName("sven_great_cleave"));
      sven:UpgradeAbility(sven:FindAbilityByName("sven_great_cleave"));
      sven:UpgradeAbility(sven:FindAbilityByName("sven_great_cleave"));
      sven:UpgradeAbility(sven:FindAbilityByName("sven_warcry"));
      sven:UpgradeAbility(sven:FindAbilityByName("sven_warcry"));
    end
    
  • I use this:

    To set custom hero for all players (in activate function):

    GameRules:GetGameModeEntity():SetCustomGameForceHero( 'npc_hero.....' )
    

    Event

    ListenToGameEvent('npc_spawned', Dynamic_Wrap(LW, 'OnNPCSpawned'), self)
    

    Function:

    function LW:OnNPCSpawned( event )
      local npc = EntIndexToHScript(event.entindex)
    
      if npc:IsRealHero() then
        if npc:GetClassname() == 'npc_hero.....' then
          local team = npc:GetTeamNumber()
          local player = npc:GetPlayerOwner()
          local pID = player:GetPlayerID()
    
          UTIL_Remove( npc ) -- destroy selected hero
    
          PrecacheUnitByNameAsync("npc_dota_hero_rattletrap", --cache new hero
           function() 
              newHero = CreateHeroForPlayer("npc_dota_hero_rattletrap", player) --create new hero
    
              newHero:SetAbilityPoints(1) --set points to upgrade ability
              newHero:UpgradeAbility(newHero:FindAbilityByName("my_ultra_cool_custom_skill"))
    
              newHero:AddItemByName("item_my_ultra_custom") --add items
    
              newHero.spawnPosition = newHero:GetAbsOrigin()
    
              newHero:SetGold(START_GOLD, false)
           end, pID)
        end
      end
    end
    
  • edited September 2015 Posts: 14

    The above did not work so well for me.. Just add a hero:HeroLevelUp(true) line to your gamemode.lua under GameMode:OnHeroInGame for each level and use hero:SetGold(600, true) to aprox. set starting gold

    -Im using barebones as a base