[Modding Question] How to I get the current level of a demigod?

How do I get the current level of a demigod?  I am making a mod so that monks will heal based on a demigods level.  This is the relavent code from HighPriest01Abilities.lua.  If I define LvL as a number the mod works but I can not seem to figure out how to define LvL as a demigods current level.

Code: c++
  1. local Buff = import('/lua/sim/buff.lua')
  2. local HeroUnit = import('/lua/sim/HeroUnit.lua')
  3. local LvL = ?????
  4. BuffBlueprint {
  5.     Name = 'HighPriest01HeroHeal01',
  6.     Debuff = false,
  7.     DisplayName = 'Heal',
  8.     BuffType = 'HIGHPRIESTHEALTH',
  9.     Stacks = 'ALWAYS',
  10.     Duration = 0,
  11.     DamageFriendly = true,
  12.     DamageSelf = true,
  13.     Affects = {
  14.         Health = {Add = 100+30*LvL},
  15.     },
  16. }

2,355 views 8 replies
Reply #1 Top

Try looking into the lua/ui/game/HUD_xp.lua file, and see how the xp bar checks level.

Sorry I can't give any kind of specific help, DG has stopped working on my laptop, and I can't test any of the code ive got atm.

Reply #3 Top

 

AIbrain.lua has some globals you might be interested in:

      self.Score = {
            BonusPoints = 0,
            Damage = 0,
            Gold = 0,
            Grunts = 0,
            HeroAssists = 0,
            HeroFlags = 0,
            HeroDeaths = 0,
            HeroId = ScenarioInfo.ArmySetup[self.Name].Hero,
            HeroKills = 0,
            HeroKillStreak = 0,
            HeroLevel = 1,
            HeroPing = 0,
            HeroScore = 0,
            HeroSimSpeed = 0,
            LongestKillStreak = 0,
            Special = 0,
            Structures = 0,
            UnitCurrent = 0,
            UnitCap = 0,
            WarRank = 0,
            Upgrades = 0,
            Winner = false,
        }

 

Example to use the above would be self.Score.HeroLevel or if self is not a local variable unit usually is unit:GetAIBrain().Score.HeroLevel

Reply #4 Top

I figured it out I was able to use unit:GetLevel().  I used this in BuffAffects.lua to make the change.

Reply #5 Top

I'm trying to retrieve the Demigods level to give them the ability to crit on specific abilities after level 19 (I have a highly modified game that goes up to level 30).

#################################################################################################################
# Fireball
#################################################################################################################
function Fireball(abilityDef, unit, params)
    if unit:IsDead() or params.Targets[1]:IsDead() then
        return
    end
    local unitpos = unit:GetPosition()
    local bonepos = unit:GetPosition('sk_TorchBearer_Staff_Muzzle_REF')
    local targpos = params.Targets[1]:GetPosition()
    local direction = VNormal(targpos-bonepos)

    local projpos = VDiff(bonepos, unitpos)
    local proj = unit:CreateProjectile('/projectiles/Fireball03/Fireball03_proj.bp', projpos[1], projpos[2], projpos[3], direction[1], direction[2], direction[3])
   
    local damage = abilityDef.DamageAmt
    if Validate.HasAbility(unit,'HEMA01FireandIce') then
       damage = damage + unit.AbilityData.FireballDamage
    end
   
    local herolevel = unit:GetAIBrain().Score.HeroLevel
   
    if herolevel > 19 then
        Abil.AddAbility(unit, 'HEMA01FireballBuff', true)
    end

   
   
    local damageTable = {
            Radius = abilityDef.DamageRadius or 0,
            Type = 'SpellFire',
            DamageAction = abilityDef.Name,
            DamageFriendly = false,
            CollideFriendly = false,
            Amount = damage,
            CanCrit = true,
        CanCritFrom = {HEMA01FireballBuff = true},

            CanBackfire = false,
            CanDamageReturn = false,
            CanBeEvaded = false,
            IgnoreDamageRangePercent = true,
            CanMagicResist = true,
            ArmorImmune = true,
        }
          
    if proj and not proj:BeenDestroyed() then
        proj:PassDamageData(unit,damageTable)
    end
    proj:SetNewTarget(params.Targets[1])
    proj:SetVelocityVector(direction * 30)
    proj:TrackTarget(true)
   
    if herolevel > 19 then
        Abil.RemoveAbility(unit, 'HEMA01FireballBuff', true)
    end


end

AbilityBlueprint {
    Name = 'HEMA01FireballBuff',
    AbilityType = 'WeaponCrit',
    CritChance = 100,
    CritMult = 1.2,
}

 

But I'm having absolutely no luck. Any ideas?

Reply #6 Top

I see no reason for a cap at level 20. The leveling should be open end so you can still grow after 20, although slower.

Reply #7 Top

If I had to guess, I would say that what is happening is the standard fireball is calling the function, which will then activate the new ability for the crit fireball. However, because the new ability was not the 1 that called the function, the critfrom is false...therefore no crit. Then, you are removing the new fireball ability at the end.

Try either making it a buff which would stay on, or make it a full ability and find a better way to activate it.

However, I think the best way to do it...seeing as you have a 100 percent crit chance anyways, is something like:

damage = damage + unit.AbilityData.FireballDamage

if herolevel > 19

damage = damage * 1.2

This would probably be the simplest, atleast for a 100 percent crit rate.

Reply #8 Top

I think you're right about the fireball calling another function, and it was a bad ability to do my initial test (it was just random).

And the reason for the 100% crit rate was to make it easier to test quickly. :)

Cheers!