• 🏆 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] Loop Not Firing

Status
Not open for further replies.
Level 4
Joined
Apr 20, 2009
Messages
106
I've been attempting to learn JASS, but I've run into something which has gone wrong. From my placing BJDebugMsg's around in the code, I've decided that the loop in my code isn't firing for some reason. I'll show you the code, and maybe you can see what I'm missing
JASS:
function DPulse_Conditions takes nothing returns boolean    
    return GetSpellAbilityId() == 'A001'
endfunction

function DPulse_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local unit target = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(caster, 'A001')
    local real damage = (I2R(level)*75)
    local real life = GetWidgetLife(target)
    local real spill 
    local group enemies
    local unit temp // Variable set-up. Meh.
    
    call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Undead\\DeathPact\\DeathPactTarget.mdl", GetUnitLoc(caster))) 
    
    if damage>life then // If the damage would kill the unit...
        set spill = ((damage-life)*2) // Calculate the explosion damage, which is the leftover damage times two
        call UnitDamageTarget(caster, target, damage, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null) // Damage the unit
        call GroupEnumUnitsInRangeOfLoc(enemies, GetUnitLoc(target), 300, null) // Get the nearby units for explosion
        
        loop  //Start damaging
            call BJDebugMsg("Damage")
            set temp = FirstOfGroup(enemies)
            exitwhen temp == null
            if IsUnitEnemy(temp, GetOwningPlayer(caster)) then // If the unit is an enemy, we're going to do spill damage to it
                call UnitDamageTarget(caster, temp, spill, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null)
            endif
            call GroupRemoveUnit(enemies, temp)
        endloop   
    
    elseif life>damage then // If the damage won't kill the target, apply normally
        call BJDebugMsg("Nope")
        call UnitDamageTarget(caster, target, damage, true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null)     
    endif
    
    call DestroyGroup(enemies)
    set temp = null
    set enemies = null
    set caster = null
    set target = null          
endfunction                                                                        

function InitTrig_DPulse takes nothing returns nothing
    set gg_trg_DPulse = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_DPulse, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(gg_trg_DPulse, Condition(function DPulse_Conditions))
    call TriggerAddAction(gg_trg_DPulse, function DPulse_Actions)
endfunction

I've seen all of my Debug messages (including some I deleted once I decided that they were working), but I have never seen:
JASS:
            call BJDebugMsg("Damage")

The Damage is fired, and the unit will take it, but it won't do damage to any of the nearby units. Hopefully, your experienced eye can see what I'm missing here.

Also, is there a better way to do damage to units? With what I'm using, it will deal 55 damage to a peasant, and not 75. When it's fully upgraded and should be doing 225, it does about 170 damage.
 
Level 4
Joined
Apr 20, 2009
Messages
106
Yep, that was it. Thank you for that. You also were correct on the Damage==life, and I fixed that, too. +Rep :p

Thanks for the quick answer :]
 
Status
Not open for further replies.
Top