Spell Rememberance

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Version 1.2. - Further leak cleaning.

A very simple spell, the hero casts the spell on a target enemy, once it does all damage it will deal to the hero will be stored. Once the caster casts the spell on himself he will teleport to the unit's current location and deal it 75 / 150 / 215 percent of the damage it dealt to him.

Almost everything in the ability can be modified easily so it would fit your needs the best. Requires NewGen pack. Completely MUI, no leaks, no bugs, etc. Importing instructions in the map.

The ability uses the hero's custom value, keep that in mind.

Rememberance.jpg


The code is short and simple, makes it easy for people who are just learning vJass to understand it and learn from it. Everything is stored on a sturct which is stored on a unit. It is stored in it's User Data (custom value), so no special systems are needed.

JASS:
// ********
// * V1.2 *
// ********

scope Rememberance

struct PS
    unit target
    real damage = 0.
    integer lvl = 0
    trigger ex
endstruct

globals
    private integer spellId = 'A000' // The spell's Id in your map. MODIFY THIS
    private real multi = .75 // multi * level will return the percentage of the damage that will be dealt to the target
    private string animation = "spell" // Unit's animation when casting the spell
    private string effectInSource = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl" // Effect in the source location
    private string effectInDes = "Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl" // Effect on the target's location
    private string effectOnTarget = "Abilities\\Spells\\Human\\Polymorph\\PolyMorphDoneGround.mdl" // Effect casted on the target
endglobals

private function ex_Conditions takes nothing returns boolean
    local PS data = GetUnitUserData(GetTriggerUnit())
    if GetEventDamageSource() == data.target then
        call ExecuteFunc(SCOPE_PRIVATE +"ex_Actions")
    endif
    return false
endfunction

private function ex_Actions takes nothing returns nothing
    local PS data = GetUnitUserData(GetTriggerUnit())
    local integer lvl = data.lvl
    local trigger ex = data.ex
    local real damage = GetEventDamage() + data.damage

    call data.destroy()
    set data = PS.create()
    
    set data.damage = damage
    set data.target = GetEventDamageSource()
    set data.lvl = lvl
    set data.ex = ex
    
    call SetUnitUserData(GetTriggerUnit(),data)
    
    set ex = null
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == spellId
endfunction

private function Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit tar = GetSpellTargetUnit()
    local trigger ex
    local integer lvl = GetUnitAbilityLevel(c,spellId)
    local PS data
    local real x
    local real y
    local integer ud = GetUnitUserData(c)
    
    if tar != c then
        if ud != 0 then
            call PS.destroy(GetUnitUserData(c))
        endif

        set ex = CreateTrigger()
        set data = PS.create()
        set data.target = tar
        set data.lvl = lvl
        set data.ex = ex
        call SetUnitUserData(c,data)
        call TriggerRegisterUnitEvent(ex,c, EVENT_UNIT_DAMAGED)
        call TriggerAddCondition(ex,Condition(function ex_Conditions))

        set c = null
        set tar = null
        set ex = null
        return
    endif
    
    if ud != 0 then
        set data = GetUnitUserData(c)
        call DisableTrigger(data.ex)
        call DestroyTrigger(data.ex)
        set x = GetUnitX(c)
        set y = GetUnitY(c)
        call DestroyEffect(AddSpecialEffect(effectInSource,x,y))
        set x = GetUnitX(data.target)
        set y = GetUnitY(data.target)
        call SetUnitPosition(c,x,y)
        call DestroyEffect(AddSpecialEffect(effectInDes,x,y))
        call DestroyEffect(AddSpecialEffectTarget(effectOnTarget,data.target,"chest"))
        call SetUnitAnimation(c,animation)
        call UnitDamageTarget(c,data.target,data.damage * multi * data.lvl,true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_MAGIC,WEAPON_TYPE_WHOKNOWS)
        call data.destroy()
    endif
    
    set c = null
    set tar = null
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    set gg_trg_Rememberance = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Rememberance, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Rememberance, Condition( function Conditions ) )
    call TriggerAddAction( gg_trg_Rememberance, function Actions )
endfunction

endscope


Have fun with it. :)
 

Attachments

  • Rememberance1.2.w3x
    21.3 KB · Views: 209

Tinki3

Special Member
Reaction score
418
Cool, nice idea.

Found 2 leaks:

call TriggerAddCondition(ex,Condition(function ex_Conditions))
call TriggerAddAction(ex,function ex_Actions)

Use a boolexpr for the cond and destroy/null it after use and for the triggeraction
leak, store a triggeraction via the struct and destroy it when the spell ends.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Thanks for spotting it!
I'll start working on fixing it as soon as possible.
By the way, as far as I know boolexprs don't leak, only the triggeraction leaks here.
 

Cohadar

master of fugue
Reaction score
209
Yes you can forget about boolexprs,
and instead of using unit's custom value directly you better use PUI or your spell will be incompatible with ... everything else that uses custom values or PUI
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Ok Cohadar, I'll take a look at PUI. Thanks for suggesting it.
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
nice spell Rheias +Rep

Edit: nvm i can't rep you yet - oh well you got enough anyway :p
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
When does that happen? I always clean PS structs, so I don't see how it can happen.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top