• 🏆 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!

If unit has mana at all - condition

Level 9
Joined
May 24, 2016
Messages
298
I do actually know how to check unit_state_mana, but the things is, when I try to check target unit if he has mana at all (meaning that he has no mp by default object editor value), to deal him additional damage,

JASS:
set tr = GetSpellTargetUnit()

set I = GetUnitAbilityLevel(c,'A032')
set r = GetUnitState(tr,UNIT_STATE_MANA)


if I == 1 then
set R = 100 // damage
set r2 = 100 // mp burn

elseif I == 2 then
set R = 200 // damage
set r2 = 200 // mp burn

elseif I == 3 then
set R = 300 // damage
set r2 = 300 // mp burn

endif
set bl = false // local boolean bl
if r <= r2 then
set r = r2-r

set bl = true
call SetUnitState(tr,UNIT_STATE_MANA,0)
else
call SetUnitState(tr,UNIT_STATE_MANA,r-r2)
endif


if bl == false then

call UnitDamageTarget(c,tr,R,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS)
else

call UnitDamageTarget(c,tr,R+r,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS)
endif

There's no actual respond at it, the condition returns bl as false. You know, it's like game thinks HE HAS MP and is not shown on the game. So how can I handle it, please?..
 
Level 9
Joined
May 24, 2016
Messages
298
I think I just need to debugg it one more time instead of writing a question topic on hiveworkshop. I debugged values on the script once and made it working. But since it's not working again, I better just dig into it once again.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,552
Just some example code of what you might be looking to do (I was bored). Maybe useful:
vJASS:
function Example takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local integer lvl = GetUnitAbilityLevel(u, GetSpellAbilityId())
    local real mana = GetUnitState(t, UNIT_STATE_MANA)
    local real maxMana = GetUnitState(t, UNIT_STATE_MAX_MANA)
    local real dmg = 100 * lvl
    local real burn = dmg

    // Reduce target's current mana
    call SetUnitState(t, UNIT_STATE_MANA, mana - burn)

    // Deal damage to target
    if maxMana > 0 then
        // Normal damage
        call UnitDamageTarget(u, t, dmg, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
    else
        // Bonus damage
        call UnitDamageTarget(u, t, dmg * 2, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
    endif

    set u = null
    set t = null
endfunction
 
Level 9
Joined
May 24, 2016
Messages
298
Just some example code of what you might be looking to do (I was bored). Maybe useful:
vJASS:
function Example takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local integer lvl = GetUnitAbilityLevel(u, GetSpellAbilityId())
    local real mana = GetUnitState(t, UNIT_STATE_MANA)
    local real maxMana = GetUnitState(t, UNIT_STATE_MAX_MANA)
    local real dmg = 100 * lvl
    local real burn = dmg

    // Reduce target's current mana
    call SetUnitState(t, UNIT_STATE_MANA, mana - burn)

    // Deal damage to target
    if maxMana > 0 then
        // Normal damage
        call UnitDamageTarget(u, t, dmg, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
    else
        // Bonus damage
        call UnitDamageTarget(u, t, dmg * 2, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
    endif

    set u = null
    set t = null
endfunction
My trigger skill deal damage to target and burns his mp (as seen above)
All the mana that is not getting burned (since unit supposedly lacks of that values) goes into +damage.

I fixed it already. I think I needed your UNIT_STATE_MAX_MANA value to check condition. Thx you

JASS:
elseif spellid == 'A032' then
set tr = GetSpellTargetUnit()

set I = GetUnitAbilityLevel(c,'A032')
set r = 0
set r = GetUnitState(tr,UNIT_STATE_MANA)
set R2 = GetUnitState(tr,UNIT_STATE_MAX_MANA)
if I == 1 then
set R = 100 // damage
set r2 = 100 // mp burn
//call SetUnitAbilityLevel(c,'A00J',1)
elseif I == 2 then
set R = 200 // damage
set r2 = 200 // mp burn
//call SetUnitAbilityLevel(c,'A00J',3)
elseif I == 3 then
set R = 300 // damage
set r2 = 300 // mp burn
//call SetUnitAbilityLevel(c,'A00J',5)
endif


if R2 > 0 then // maximum mana 

if r >= r2 
call SetUnitState(tr,UNIT_STATE_MANA,r-r2)

elseif r < r2
set R = R +(r-r2)
endif

else
set R = R + r2
endif

call UnitDamageTarget(c,tr,R,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS)
endif
 
Top