• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Buff Detection

Status
Not open for further replies.
Level 4
Joined
Nov 24, 2007
Messages
55
I have a question concerning Buff Detection with JASS (I assume this could also be a problem with GUI...)

I had noticed that Blizz simply did it with the following code

JASS:
function UnitHasBuffBJ takes unit whichUnit, integer buffcode returns boolean
    return (GetUnitAbilityLevel(whichUnit, buffcode) > 0)
endfunction

Since then, I have always, when needing to do buff detection in a trigger, checked to see if my target unit (which had always been not the caster) responded properly with the "GetUnitAbilityLevel" call...

However, I realized this could pose a problem.

To explain a sample problem, let me give an example.

I have a Hero who has two debuffs (one based on Soul Burn and another based on Curse...so a silence and a miss) he can cast on units. A third ability he has is a Direct Damage (based on chain lightning), but I want to trigger it such that if he uses this DD move on a unit that has been Silenced, it does an additional Manaburn. Or, if the unit had been Cursed, it would do a small AoE (a la Frost Nova). Coding this was fine, and fun and happy, until I realized,

"What if my target is a unit of the same type? And the target hero has learned both of these abilities (which would then logically return true for both queries)? Will it then do both the mana burn and AoE?"

I have not tested yet (as I cannot at the moment) and am geniunely curious as to what would happen, and if said scenario did happen, how can I prevent it from happening.

Here is the code I am/was working with in case you want to directly inject an answer in JASS:

JASS:
function Trig_Blast_of_Light_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer lvl = GetUnitAbilityLevel( u, 'A05O' )
    local unit t = GetSpellTargetUnit()
    local unit dummy
    if( ( GetUnitAbilityLevel(t, 'A023' ) > 0 ) )then
        // has holy fire...
    endif
    if( ( GetUnitAbilityLevel(t, 'A024' ) > 0 ) ) then
        // has blinding light...
    endif
    set t = null
    set dummy = null
    set u = null
endfunction
 
Status
Not open for further replies.
Top