• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

[JASS] Spell only damaging

Status
Not open for further replies.
Level 12
Joined
Mar 23, 2008
Messages
942
I tried doing a custom holy light, but it only deals damage o.o

JASS:
function Trig_Heal_Conditions takes nothing returns boolean
    if (GetSpellAbilityId() == 'A02E') then
        return true
    endif
    return false
endfunction

function Trig_Heal_Actions takes nothing returns nothing
    // (Level * 2) + (SkillLevel * 40) + (Int / 2)
    if ( IsUnitType(GetSpellTargetUnit(), UNIT_TYPE_UNDEAD) == true ) then
    call UnitDamageTargetBJ( GetTriggerUnit(), GetSpellTargetUnit(), (-(I2R(GetUnitLevel(GetTriggerUnit())) * 2.00 ) + (I2R(GetUnitAbilityLevelSwapped('A02E', GetTriggerUnit())) * 40.00) + (I2R(GetHeroStatBJ(bj_HEROSTAT_INT, GetTriggerUnit(), true)) / 2.00)), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DIVINE )
        else
             call UnitDamageTargetBJ( GetTriggerUnit(), GetSpellTargetUnit(), ((I2R(GetUnitLevel(GetTriggerUnit())) * 2.00 ) + (I2R(GetUnitAbilityLevelSwapped('A02E', GetTriggerUnit())) * 40.00) + (I2R(GetHeroStatBJ(bj_HEROSTAT_INT, GetTriggerUnit(), true)) / 2.00)/2), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DIVINE )
    endif
endfunction

//===========================================================================
function InitTrig_Heal takes nothing returns nothing
    set gg_trg_Heal = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Heal, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Heal, Condition( function Trig_Heal_Conditions ) )
    call TriggerAddAction( gg_trg_Heal, function Trig_Heal_Actions )
endfunction

Edit: Only to check, Holy Light heals living unit and deals half of the heal as damage to undead.
 
You should study a bit more JASS to get rid of BJ calls...

And if the idea is to damage, then the third parameter in the function UnitDamageTargetBJ should be positive. By the way, I imagine negative damage will be ignored.

Some more notes:

Your huge and inefficient condition can be reduced to
JASS:
function Trig_Heal_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A02E'
endfunction

Make a local unit variable and set it to GetSpellTargetUnit() rather than repeating it several times. Might increase spell speed. Same for GetTriggerUnit().

Create a local real variable to store that huge calculation of damage. Makes code more readable.

Change every GetUnitAbilityLevelSwapped( ability, unit ) to GetUnitAbilityLevel( unit, ability ). That's a BJ that will just call the second function, swapping the parameters.

You ought to use I2R( All the conversions here ) instead of I2R( one ) + I2R( two ) + I2R( three ) ...
 
Level 6
Joined
Sep 5, 2007
Messages
264
Instead of using negative damage, which obviously Wc3 doesn't like, you could just use:
JASS:
function Trig_Heal_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()

    local integer abil_lvl = GetUnitAbilityLevel(caster, 'A02E')
    local integer caster_lvl = GetUnitLevel(caster)
    local integer intel_lvl = GetHeroInt(caster, true)

    local real heal_amount = I2R((caster_lvl * 2.00 ) + (abil_lvl * 40.00) + (intel_lvl / 2.00))
    local real life = GetUnitState(target, UNIT_STATE_LIFE)

    set life = life + heal_amount
    call SetUnitState(target, UNIT_STATE_LIFE, life)

    set caster = null
    set target = null
endfunction

This also assigns everything to local variables & gets rid of the BJ calls, which as Marcelo Hossomi said, is much more efficient.

Hope this is helpful. :thumbs_up:
 
Level 12
Joined
Mar 23, 2008
Messages
942
JASS:
function Trig_Heal_Conditions takes nothing returns boolean
    if (GetSpellAbilityId() == 'A02E') then
        return true
    endif
    return false
endfunction

function Trig_Heal_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local integer abil_lvl = GetUnitAbilityLevel(caster, 'A02E')
    local integer caster_lvl = GetUnitLevel(caster)
    local integer intel_lvl = GetHeroInt(caster, true)
    local real heal_amount = (caster_lvl * 2.00 ) + (abil_lvl * 40.00) + (intel_lvl / 2.00)
    local real life = GetUnitState(target, UNIT_STATE_LIFE)

    // (Level * 2) + (SkillLevel * 40) + (Int / 2)
    if (IsUnitType(GetSpellTargetUnit(), UNIT_TYPE_UNDEAD) == false) then
      set life = life + heal_amount
      call SetUnitState(target, UNIT_STATE_LIFE, life)
    else
        call UnitDamageTargetBJ( GetTriggerUnit(), GetSpellTargetUnit(), ((caster_lvl * 2.00 ) + (abil_lvl * 40.00) + (intel_lvl / 2.00))/2, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DIVINE )
    endif
    set caster = null
    set target = null
endfunction

//===========================================================================
function InitTrig_Heal takes nothing returns nothing
    set gg_trg_Heal = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Heal, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Heal, Condition( function Trig_Heal_Conditions ) )
    call TriggerAddAction( gg_trg_Heal, function Trig_Heal_Actions )
endfunction
Working... Thanks ^^

(But my other trigger uses negative damage and heals...)mi~mi~mi~mi~
 
Level 6
Joined
Sep 5, 2007
Messages
264
Just some spring cleaning :p

JASS:
function Trig_Heal_Conditions takes nothing returns boolean
    return (GetSpellAbilityId() == 'A02E')
endfunction

function Trig_Heal_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local integer abil_lvl = GetUnitAbilityLevel(caster, 'A02E')
    local integer caster_lvl = GetUnitLevel(caster)
    local integer intel_lvl = GetHeroInt(caster, true)
    local real heal_amount = (caster_lvl * 2.00 ) + (abil_lvl * 40.00) + (intel_lvl / 2.00)
    local real life

    // (Level * 2) + (SkillLevel * 40) + (Int / 2)
    if (IsUnitType(target, UNIT_TYPE_UNDEAD) == false) then
      set life = GetUnitState(target, UNIT_STATE_LIFE) + heal_amount
      call SetUnitState(target, UNIT_STATE_LIFE, life)
    else
        call UnitDamageTarget(caster, target, heal_amount, true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DIVINE, WEAPON_TYPE_WHOKNOWS)
    endif
    set caster = null
    set target = null
endfunction

:eekani: You still had those damn BJ functions in there... Get yourself JassCraft you can look them up, UnitDamageTargetBJ() just calls UnitDamageTarget(), so it's MUCH better to just do it yourself.

:fp: Don't forget to use variables...
JASS:
call UnitDamageTargetBJ( GetTriggerUnit(), GetSpellTargetUnit(), ((caster_lvl * 2.00 ) + (abil_lvl * 40.00) + (intel_lvl / 2.00))/2, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DIVINE )
Even using that evil BJ should have been:
JASS:
call UnitDamageTargetBJ(caster, target, heal_amount, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DIVINE )
Variables are there for speed and readability...

I also slightly altered my own coding in there, I move the "life = GetUnitState()" down into the actual healing section, otherwise it just wastes CPU cycles.

BTW: Just noticed... Thanx for the +REP

Hope I've helped... :thumbs_up:
 
Level 6
Joined
Sep 5, 2007
Messages
264
I wasn't picking, sorry if it came across that way :hohum:

I was just trying to make sure your spell runs fast, so that it won't cause lag problems later on down the track. Also, it's good practice.

Anyways, hope it works exactly the way you planned...
Let me know if you need any help. :thumbs_up:
 
Status
Not open for further replies.
Top