Spell Energy Shield

the Immortal

I know, I know...
Reaction score
51
Energy Shield:

picturelh0.jpg

So ... this is the first spell I post somewhere.
It basically creates a shield around the caster that absorbs damage with its "energy". When the shield ends (currently after 20 sec.) the unit is healed for amount equal to the shield's remaining "energy".

Simple, isn't it?

Here are the things you can config:
- the raw codes of the ability & the buff
- max duration of the spell
- is the spell insta-cast or unit-cast
- the formula for the max "energy" the shield has

Known bugs:
- NONE

Please post any leaks, bugs or typos that you find. I will try to remove them as fast as I can :p

EDIT (12.11.06)
- Fixed the triggeraction leak
- Added a new shield-effect (by Tinki3's idea)
- Added picture

EDIT (14.11.06)
- Fixed the full health bug
- I hope there aren't any bugs/leaks now :)
 

Attachments

  • Energy Shield.w3x
    21.9 KB · Views: 752

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Hmmm, when I tested it, the shield didn't absorb any damage at all and the shield didn't end, when it was supposed to absorb the max damage.
 

Tinki3

Special Member
Reaction score
418
You should try and fix the leaks/bugs before you release the spell map, otherwise it doesn't get accepted for a while (I know from experience) :)

Testing out spell now.

EDIT:

Bad news. The shield did nothing except show a buff, and create an animation around the caster =(

EDIT 2:

Tested the updated version. Works perfectly. Good work +rep =)
 

Tinki3

Special Member
Reaction score
418
You could've also based the spell of mana shield, with a trigger that goes after after the mana shield has been activated that constantly sets the mana of the caster to its current mana. And if the caster happened to cast another spell, you could single the spells which the caster could cast out using conditions, then subtract mana from the caster after he uses that particular spell ;)

For this idea, you could include all that other stuff that the trigger does as well (at least I think).
 

the Immortal

I know, I know...
Reaction score
51
@ Chocobo:
I made originally the "-lvl" command in such way, but I decided to make it more specific, because the player can type something like "-lvl sdf"
For the Handle Vars - In the importing guide I wrote that you must paste the custom script in your map's header.
For the channel-spell you can see that I first based it off Channel (I didn't delete the old ability), but Channel has no buff and Effect

@Tinki3 - If I base it off Mana Shield, how I will know what damage is dealt x)? The units has mana reg. so I can't set it to constant value. Also when you import it in your map, you'll have to select the abilities the hero has & their mana cost ... and that's annoying.
 

SFilip

Gone but not forgotten
Reaction score
634
Nice one, GJ.
There is a small leak you should probably know about...triggeraction. You need to destroy it before you destroy the actual trigger.
You also need to Flush the game cache after use.
And perhaps its a better idea to use the actual Handle Vars system, makes it easier to understand and implement.

Code:
function take_dmg takes nothing returns nothing
    local trigger trg = GetTriggeringTrigger()
    local real h = GetEventDamage()
    local real absorb = GetHandleReal(trg, "absorb" )
    if GetEventDamage() > absorb then
        call SetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE, ( GetUnitState( GetTriggerUnit(), UNIT_STATE_LIFE ) + h ) )
        [b]call TriggerRemoveAction(trg, GetHandleTA(trg, "ta"))
        call FlushHandleLocals(trg)[/b]
        call DestroyTrigger( trg )
        call UnitRemoveAbility(GetTriggerUnit(), BuffID())
    else
        call SetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE, ( GetUnitState( GetTriggerUnit(), UNIT_STATE_LIFE ) + h ) )
        set absorb = absorb - GetEventDamage()
        call SetHandleReal(trg, "absorb", absorb)
    endif
    set trg = null
        
endfunction

function Action takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local unit targ
    local real absorb = BaseAbsorb() + LvlAbsorb() * I2R( GetUnitAbilityLevel(cast, GetSpellAbilityId()) )
    local trigger trg = CreateTrigger()
    [b]local triggeraction ta[/b]
    if not( IsCastable() ) then
        set targ = GetTriggerUnit()
    else
        set targ = GetSpellTargetUnit()
    endif
    call SetHandleReal(trg, "absorb", absorb)
    call TriggerRegisterUnitEvent( trg, targ, EVENT_UNIT_DAMAGED )
    [b]set ta =[/b] TriggerAddAction( trg, function take_dmg )
    [b]call SetHandleHandle(trg, "ta", ta)[/b]
    call PolledWait( Duration() )
    if not(trg == null)  then
        set absorb = GetHandleReal(trg, "absorb")
        call SetUnitState(targ, UNIT_STATE_LIFE, ( GetUnitState( GetTriggerUnit(), UNIT_STATE_LIFE ) + absorb ) )
    endif
    [b]call FlushHandleLocals(trg)
    call TriggerRemoveAction(trg, ta)[/b]
    call DestroyTrigger( trg )
    set trg = null
    set cast = null
    set targ = null
    [b]set ta = null[/b]
endfunction
bold=stuff I added

And add this to the handle vars system.
Code:
function GetHandleTA takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

Edit: Oh and you might wanna add a picture, these things usually promote your spell. ;)
 

SFilip

Gone but not forgotten
Reaction score
634
Before I approve this there is a bug you should fix...
When the spell is casted and you have full hp you will take the first damage and it doesn't get absorbed from some reason.
 

the Immortal

I know, I know...
Reaction score
51
Ok, fixed this bug (note that now the custom script is more hard-to-understand than before). The problem was that the event occurs before the damage is taken from the unit.
I think I fixed any bugs and leaks and the spell is ready for use.
 

emjlr3

Change can be a good thing
Reaction score
395
what is the purpose of the dmgrestore method u r using?

also, i recommend changing the functions action and cond to something that may not interfere with others in a map

and i did not see credit to the author

other then that good, and welcome to the club
 

the Immortal

I know, I know...
Reaction score
51
As I said the event occurs before the actual dmg-taking. So if the unit is on full HP, the shield won't actually heal the unit. I decided adding timer and when he expires (after 0.01 seconds) to heal the unit. I tried it and it worked. After that I tried to heal the unit after 0.00 sec. and it worked too :rolleyes:
 

emjlr3

Change can be a good thing
Reaction score
395
As I said the event occurs before the actual dmg-taking. So if the unit is on full HP, the shield won't actually heal the unit. I decided adding timer and when he expires (after 0.01 seconds) to heal the unit. I tried it and it worked. After that I tried to heal the unit after 0.00 sec. and it worked too :rolleyes:

ive made shield spells before and never had to use that method, to me it is uneeded
 
S

Shin

Guest
This spell works perfectly fine when I run it in your map, but I'm having trouble implementing this into my map, as I'm bad with JASS, so if someone could please help me out it would be greatly appreciated. The issues are as follows:

When I copy the Ability, Buff and Trigger into my map and try to save it, it shows me numerous errors in the script.

I've done everything it says in the script, replaced the raw code of the Ability, the raw code of the Buff, and created the variable "cache" of type Game Cache. Then I go to Save Map... and it returns a lot of errors, I don't want to list them all, but here are a few of them:

  • Expected a name: local real absorb = GetStoredReal( LocalVars(), I2S(H2I(trg)), "absorb" )
  • Expected a name: if GetEventDamage() > absorb then
  • Expected a function name: call DmgRestore(GetTriggerUnit(), absorb)
  • Expected a name: call TriggerRemoveAction(trg, GetHandleTA(trg, "ta"))

Since I don't understand much about JASS, it would be great if someone could explain to me what is wrong, what needs to be changed, and how to avoid this problem in the future.

I would also appreciate it if you would explain how to remove the Healing effect the target receives after the duration is over, and how to change it so it is able to cast on Ally Units as well as the caster.

This is a great spell, it works perfectly, and if I could get it to work on my own map, it would be even greater.
Thanks in advance for any help that is given.
 

Tinki3

Special Member
Reaction score
418
Code:
function LocalVars takes nothing returns gamecache
    if udg_cache==null then
        call FlushGameCache(InitGameCache("cache.w3v"))
        set udg_cache=InitGameCache("cache.w3v")
    endif
    return udg_cache
endfunction

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function GetHandleTA takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction

function DmgAftTime takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "unit")
    local real dmg = GetStoredReal(LocalVars(), I2S(H2I(t)), "dmg")
    call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE) + dmg)
    set u = null
    call DestroyTimer(t)
    set t = null
endfunction

function DmgAfterTime takes unit u, real dam returns nothing
    local timer t = CreateTimer()
    call StoreInteger( LocalVars(), I2S(H2I(t)), "unit", H2I(u))
    call StoreReal( LocalVars(), I2S(H2I(t)), "dmg", dam)
    call TimerStart(t, 0, false, function DmgAftTime)
    set t = null
    set u = null
endfunction

function DmgRestore takes unit u, real d returns nothing
    local real CurLife = GetUnitState(u,UNIT_STATE_LIFE)
    local real MaxLife = GetUnitState(u,UNIT_STATE_MAX_LIFE)
    if d > (MaxLife-CurLife) then
        if d>CurLife then
            call SetUnitState (u, UNIT_STATE_LIFE, MaxLife)
            call DmgAfterTime (u, (d-(MaxLife-CurLife)))
        else
            call DmgAfterTime(u, d)
        endif
    else
        call SetUnitState(u,UNIT_STATE_LIFE,GetUnitState(u,UNIT_STATE_LIFE)+d)
    endif
    set u = null
endfunction

Did you copy and paste that system into your map's trigger header?

The trigger header looks like TFT map icon, located at the top of the trigger list.
 
S

Shin

Guest
Code:
function LocalVars takes nothing returns gamecache
    if udg_cache==null then
        call FlushGameCache(InitGameCache("cache.w3v"))
        set udg_cache=InitGameCache("cache.w3v")
    endif
    return udg_cache
endfunction

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function GetHandleTA takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction

function DmgAftTime takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "unit")
    local real dmg = GetStoredReal(LocalVars(), I2S(H2I(t)), "dmg")
    call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE) + dmg)
    set u = null
    call DestroyTimer(t)
    set t = null
endfunction

function DmgAfterTime takes unit u, real dam returns nothing
    local timer t = CreateTimer()
    call StoreInteger( LocalVars(), I2S(H2I(t)), "unit", H2I(u))
    call StoreReal( LocalVars(), I2S(H2I(t)), "dmg", dam)
    call TimerStart(t, 0, false, function DmgAftTime)
    set t = null
    set u = null
endfunction

function DmgRestore takes unit u, real d returns nothing
    local real CurLife = GetUnitState(u,UNIT_STATE_LIFE)
    local real MaxLife = GetUnitState(u,UNIT_STATE_MAX_LIFE)
    if d > (MaxLife-CurLife) then
        if d>CurLife then
            call SetUnitState (u, UNIT_STATE_LIFE, MaxLife)
            call DmgAfterTime (u, (d-(MaxLife-CurLife)))
        else
            call DmgAfterTime(u, d)
        endif
    else
        call SetUnitState(u,UNIT_STATE_LIFE,GetUnitState(u,UNIT_STATE_LIFE)+d)
    endif
    set u = null
endfunction

Did you copy and paste that system into your map's trigger header?

The trigger header looks like TFT map icon, located at the top of the trigger list.

Ah, I hadn't noticed that little icon up there, or rather, I didn't know it was click-able... Thanks a lot for your help. I'll be trying to understand all this JASS stuff and figuring out how to make it so I can cast on ally units as well as self.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top