• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Starting actions, when a unit is killed by a spell

Status
Not open for further replies.
Level 2
Joined
Jun 4, 2013
Messages
11
Hey there, world editor experts. I'm new to this forum, but I have a little more than basic knowledge with triggers. However I just couldn't get this one right.

Currently I'm making a dungeon type map, with many hero choices, and I don't know how to make a trigger, that activates when the target unit of ability being cast dies.

For example: "Soulslayer" has the ability "Devour Soul", a basic drain life/mana spell, that removes the targeted unit and spawns a special effect in it's place, when it kills a it.

Thanks for your help.
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
Use Dark arrow and trigger the life/mana drain effect + hp/mana loss and gain?

EDIT: errr upon looking at what you said again, this would make it so if the unit died to something else it would also spawn which is maybe not what you want.
 
oh yeah... so you need to check throughout the duration if the damage would then be killing the unit or not... so that you can detect if the killing damage came from the drain or not...

using my system you could utilize an onUpdate method to do the check... and then the onUpdate would also actually run the functions for summoning if the damage will kill the unit... but of course you still need to take into account damage reductions and such, assuming you dont use a "pure" damage type...
 
Level 2
Joined
Jun 4, 2013
Messages
11
I tried the autocasting ability way (with bash) and it worked. Since the original concept was an autocast spell, I'll stick with it.

Thanks for all the help!

Edit: Nevermind, it didn't work properly afterall. It activated without the ability being casted.
 
Last edited:
Level 2
Joined
Jun 4, 2013
Messages
11
The working ability

The working ability
  • Spike Storm
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to SpikeStorm
    • Actions
      • Set SpikeStormCasLoc = (Position of (Casting unit))
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Spike Storm Dummy for (Owner of (Casting unit)) at SpikeStormCasLoc facing Default building facing degrees
          • Set SpikeStormLocOffset = (SpikeStormCasLoc offset by 360.00 towards SpikeStormReal degrees)
          • Unit - Order (Last created unit) to Undead Crypt Lord - Impale SpikeStormLocOffset
          • Set SpikeStormReal = (SpikeStormReal + (360.00 / 8.00))
          • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
]


It's a nova spell, so it's a bit different.

not working spell

  • Devour Soul Test
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Devour Soul
    • Actions
      • Unit - Create 1 Devour Soul Dummy for (Owner of (Casting unit)) at (Position of (Casting unit)) facing Default building facing degrees
      • Unit - Order (Last created unit) to Neutral - Hurl Boulder (Target unit of ability being cast)
I realize it's too simple, but it seemed the obvious way.
 
Last edited:
Level 30
Joined
Nov 29, 2012
Messages
6,637
SO your Soul Devour is not working. Some questions you should answer, does your Devour Soul Dummy has the spell? If not, give it the ability either triggers or in the OE (Object Editor). Because as long as a unit is ordered to cast something but it doesnt have that ability, the trigger will keep on failing and second, did you order the Last Created Unit to cast the correct Base ID (what I mean by Base ID is the ID used for a spell so through triggers when it is ordered, it will cast the spell?)

Now some for my suggestions. I suggest use maybe a variables to the Last Created Unit and Position of Last Created Unit because there is possibility for units to the be the last created unit.
 
Level 2
Joined
Jun 4, 2013
Messages
11
The dummy has the ability (hurl boulder for testing) and the trigger has the correct ID. (hurl boulder) How will the position variable help, and what should I do with it?
 
Level 30
Joined
Nov 29, 2012
Messages
6,637
Using variables make it more efficient I guess and also it stores the information it it. For the dummy unit, make sure it has mana to cast the ability because if without it..... it cannot cast it.

Also set a variable for Owner of Casting Unit
 
Level 2
Joined
Jun 4, 2013
Messages
11
Tired me forgot about the mana cost.

Reverting the spell back to a drain spell made it possible to trigger. Everything's working, except one thing. It supposed to give the Soulslayer the full hit points of the drained unit. How do I do that with a dummy caster? At least the drain effect.
 
Level 20
Joined
Apr 14, 2012
Messages
2,901
@JesterofDestiny when the spell is cast, store the original casting unit (Soulslayer) into a variable, then use that unit variable to transfer HP.

@Maker but how come at almost all (I'm not sure if everything uses it) tutorials here tells us to use Triggering Unit instead of Casting Unit? I'm little confused.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
I have tested it.

JASS:
library leakTest1 initializer onInit
    globals
        private timer t = CreateTimer()
        private constant integer dummies = 1
        private constant integer events = 2000
        private integer c = 0
        private trigger acquire = CreateTrigger()
    endglobals
    
    private function acquireItem takes nothing returns boolean
        local unit u
        local integer i = events
        loop
            /*
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            set u = GetDyingUnit()
            */
            
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            set u = GetTriggerUnit()
            
            
            exitwhen i == 0
            set i = i - 1
        endloop
        set u = null
        return false
    endfunction

    private function leaks takes nothing returns nothing
        local integer i = dummies
        
        loop
            exitwhen i == 0
            call KillUnit(CreateUnit(Player(0), 'hfoo', 0, 0, 0))
            set c = c + 1
            set i = i - 1
        endloop
    endfunction
    
    private function pauseResume takes nothing returns nothing
        if ModuloInteger(GetTriggerExecCount(GetTriggeringTrigger()) , 2) == 1 then
            call BJDebugMsg("started")
            call TimerStart(t, 0.01, true, function leaks)
        else
            call BJDebugMsg("paused, " + "dummies created: " + I2S(c))
            call PauseTimer(t)
        endif
    endfunction

    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(t, function pauseResume)
        call TriggerRegisterAnyUnitEventBJ(acquire, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddCondition(acquire, function acquireItem)
    endfunction
endlibrary
 
Level 2
Joined
Jun 4, 2013
Messages
11
Found the solution:

-Create spell that the hero will cast - make it totally uneffective

-Create trigger that activates when the hero casts the "dummy" spell

-Create dummy unit, give it the actual spell. - dummy unit's appearance is triggered to the hero casting the dummy spell

-Create variable, with the type "unit" - In the casting trigger, set this variable to the casting/triggering hero.

-Add new trigger - activates when dummy unit kills it's target

In pictures

  • Devour Soul Casting
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Devour Soul
    • Actions
      • Set DevourSoulActualCaster = (Casting unit)
      • Unit - Create 1 Devour Soul Dummy for (Owner of (Casting unit)) at (Position of (Casting unit)) facing Default building facing degrees
      • Unit - Set life of (Last created unit) to 10.00
      • Unit - Set level of Devour Soul - Dummy for (Last created unit) to (Level of Devour Soul for (Casting unit))
      • Unit - Order (Last created unit) to Neutral Dark Ranger - Life Drain (Target unit of ability being cast)
      • Unit - Add a 60.00 second Generic expiration timer to (Last created unit)
  • Devour Soul Success
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Killing unit)) Equal to Devour Soul Dummy
    • Actions
      • Unit - Remove (Dying unit) from the game
      • Special Effect - Create a special effect at (Position of (Dying unit)) using Abilities\Spells\Undead\DeathCoil\DeathCoilSpecialArt.mdl
      • Unit - Remove (Killing unit) from the game
      • Unit - Set life of DevourSoulActualCaster to ((Life of DevourSoulActualCaster) + (Max life of (Dying unit)))
      • Unit - Set mana of DevourSoulActualCaster to ((Mana of DevourSoulActualCaster) + (Max mana of (Dying unit)))
Thanks for all the help!
 
Level 20
Joined
Apr 14, 2012
Messages
2,901
You're leaking:
  • Unit - Create 1 Devour Soul Dummy for (Owner of (Casting unit)) at (Position of (Casting unit)) facing Default building facing degrees
  • Special Effect - Create a special effect at (Position of (Dying unit)) using Abilities\Spells\Undead\DeathCoil\DeathCoilSpecialArt.mdl
Store those locations into variables then remove those locations after use.
 
Status
Not open for further replies.
Top