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

Spell Reflection

Status
Not open for further replies.
Level 5
Joined
Mar 27, 2008
Messages
107
Heya, this is the spell I want:

A unit (unit1)casts a spell which lasts for a certain amount of time, if another unit (unit2) casts a harmful spell on this unit it will be reflected towards the casting unit.
Only some of the spells should be reflected, not all of them. (not melee abilities for example, only magic spells)
By reflected, I mean that the exact same spell that unit2 cast should be cast again from the location of unit1 against unit2. Unit1 should not be damaged at all from this spell.
Missiles/special effects should work properly btw.
I'd prefer a GUI answer, I only know the very basics of JASS.
Thanks! :)

+ rep for any helpfull answers, thanks!
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
I guess only unit unit target spells are reflected,like the ones that are blocked by amulet of spell shield.
Hold on,i'll make a test map. Just to mention that reflection of spells depends on spells' nature,so some spells might require a bit more functions for reflecting.
 
Make a unit based off Blood Mage: that will be your dummy unit.
Scroll to its fields:
Stats - Hero - Hide Hero Death Message: True
Stats - Hide Minimap Display: True
Stats - Hero - Hide Hero Interface Icon: True
Stats - Hero - Hide Hero Minimap Display: True
Abilities - Normal :Locust, Invulnerable (Neutral)
Stats - Food Cost: 0
Combat - Attacks Enabled: None
Art - Model File: None
Art - Shadow Image: None
Stats - Mana Initial Amount: 1000000000 ||Press Shift + Enter to type such a value.
Stats - Mana Maximum: 1000000000

Implement the following trigger:

  • Protego
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • ((Target unit of ability being cast) has buff Protego ) Equal to True
      • ((Triggering unit) belongs to an enemy of (Owner of (Target unit of ability being cast))) Equal to True
      • (Unit-type of (Triggering unit)) Not equal to Dummy
    • Actions
      • Set P_Point1 = (Position of (Target unit of ability being cast))
      • Unit - Create 1 Dummy for (Owner of (Target unit of ability being cast)) at P_Point1 facing Default building facing degrees
      • Unit - Add (Ability being cast) to (Last created unit)
      • Unit - Set level of (Ability being cast) for (Last created unit) to (Level of (Ability being cast) for (Triggering unit))
      • Set P_Order = (String((Current order of (Triggering unit))))
      • Custom script: call IssueTargetOrder (GetLastCreatedUnit(), udg_P_Order, GetTriggerUnit())
      • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation (udg_P_Point1)
This will redirect any spell you receive. In order to make it work for certain abilities only, use this instead:
  • Zero
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Abilities Setup --------
      • Set P_Abilities[1] = Faerie Fire
      • Set P_Abilities[2] = Unholy Frenzy
      • Set P_Abilities[3] = Curse
      • Set P_Abilities[4] = Cyclone
      • Set P_Abilities[5] = Death Coil
      • Set P_Abilities[6] = Frost Nova
      • Set P_Abilities[7] = Banish
      • Set P_Abilities[8] = Chain Lightning
      • Set P_Abilities[9] = Hex
      • Set P_Abilities[10] = Sleep
      • -------- 0----------0 --------
  • Two
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • ((Target unit of ability being cast) has buff Protego ) Equal to True
      • ((Triggering unit) belongs to an enemy of (Owner of (Target unit of ability being cast))) Equal to True
      • (Unit-type of (Triggering unit)) Not equal to Dummy
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Ability being cast) Equal to P_Abilities[(Integer A)]
            • Then - Actions
              • Set P_Point1 = (Position of (Target unit of ability being cast))
              • Unit - Create 1 Dummy for (Owner of (Target unit of ability being cast)) at P_Point1 facing Default building facing degrees
              • Unit - Add (Ability being cast) to (Last created unit)
              • Set P_Order = (String((Current order of (Triggering unit))))
              • Custom script: call IssueTargetOrder (GetLastCreatedUnit(), udg_P_Order, GetTriggerUnit())
              • Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
              • Custom script: call RemoveLocation (udg_P_Point1)
            • Else - Actions
Test Map:
View attachment Spell Reflection.w3x

Note: Unfortunately, spells with missile won't be redirected, because the missile damages/debuffs, way after the current order of the unit, so the dummy cannot imitate the order. That is not hard to do, but it would require a timer in Jass and you don't want any, so :p

Note2: The Protego spell (the one that you use as the reflecting shield) is based off Cripple. If you cast another cripple on your unit, it will make the effect go away, so, make sure there is no spell based off Cripple in your map or base the Protego spell off another one, that provides a buff.
 
Level 5
Joined
Mar 27, 2008
Messages
107
Perfect! :)
I'm learning jass slowly but steady, so I'm sure I can fix the details later, the important thing is that it works.
Thanks alot, ur the best pharao!
 
Status
Not open for further replies.
Top