• 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] Trying to implement Bribe's Damage Engine in Lua

Level 7
Joined
Feb 8, 2015
Messages
123
New to working with LUA and, having gotten a lot of use of the old JASS-GUI of Bribe's Engine version, I wanted to use this new lua version.
But I get a slew of errors whenever the script is enabled in my map

WC3_LUA_damageEngine.png


(Output from debug utils whenever any damage is done)

I don't see any installation instructions besides just copy-pasting the Damage Engine folder into my map, along with the prerequisites lua systems. What am I missing?
 
Thanks - that solved the above issue.
Unfortunately, I'm now getting another error. And worst of all; it's inconsistent.

It's still "attempt to index a nil value (local 'd')" but this time the line number is different, and it only happens on some damage instances. I have a map with 3 Heroes and 15 different abilities. Only 2 of them pop the error.

I've looked through the debug log, and the issue seems to stem from this part of the damage engine;
Lua:
[...]
    t2 = CreateTrigger()
    TriggerRegisterAnyUnitEventBJ(t2, EVENT_PLAYER_UNIT_DAMAGED)
    TriggerAddCondition(t2, Filter(function()
        local r = GetDamage()
        local d = current
        --print("Second damage event running for " .. GetUnitName(GetTriggerUnit()))
        if prepped                              then prepped = nil
        elseif dreaming or d.prevAmt == 0.00    then return ----------------> NOTE this line causes error for Hellfury Strike and Omnislash
        elseif totem                            then totem = nil
        else
            afterDamage()
            d               = lastInstance
            current         = d
            lastInstance    = nil
            canKick         = true
        end
        setArmor(true)
        d.userAmt = d.damage
        d.damage = r
[...]

Initially I thought it was caused by using different damage or attack types, but even after standardizing everything to the same line of code, e.g.
Lua:
UnitDamageTarget(caster, target, damage, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, nil)
I still get the error... On just a couple of spells, with everything else working fine.
 
Last edited:
Some new info on the topic.

The error I get, "attempt to index a nil value (local 'd')", fires not on any actual damage dealt, but whenever a unit-target Channel is cast.

So to replicate this problem;
  • Install lua Debug Utils
  • Install Bribe's Damage Detection for lua, per his instructions
  • Make the corrections that @Insanity_AI linked
  • Create a (new) custom ability based on channel
    • Unit Target
    • (Visible, unique cast, etc.)
  • Cast it on some target
So it would seem the problem has something to do with "Damage events" with null damage values?
 
How about adding a return if current (d) is nil.
Lua:
if current == nil then return end
local d = current
But I'm pretty sure all unit-targeted abilities apply a 0.00 damage Event on cast. Also, there can't be a null damage value, a Real will default to 0.00.
 
How about adding a return if current (d) is nil.
Lua:
if current == nil then return end
local d = current

Well that got rid of the error!
Whether that'll cause some other problem down the line, I don't know. Fingers crossed for 'no'!

But I'm pretty sure all unit-targeted abilities apply a 0.00 damage Event on cast. Also, there can't be a null damage value, a Real will default to 0.00.
Right, my bad for confusing the terminology. I meant that unit-target abilities have a zero damage event, but the error in question clearly stems from a null (or "nil") setting of the d(amage) variable.



Now, rather embarassingly... since I ran into these errors, I've yet to actually implement anything with the lua damage engine.
Given the USE_GUI boolean option, I take it one should be able to run all its functions without using GUI interface or variables?
In the original version, you would do e.g.
Value of Real variable (udg_PreDamageEvent) becomes equal to (1.0) set udg_DamageEventAmount = (etc.etc.)

To do this in (pure) lua, would we do

Lua:
...
tr = CreateTrigger()
TriggerRegisterVariableEvent(tr, PreDamageEvent, EQUAL, 1.0)
...

and actions referring to the damage dealt and such through Damage.source, Damage.Target, Damage.Amount? or do you still have to refer back to the gui variables through udg_suchAndSuch?
 
Last edited:
Back
Top