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

How do I make the shield to absorb damage based on casting hero's current mana?

Status
Not open for further replies.
Level 14
Joined
Jul 19, 2007
Messages
772
I have problem with an item-ability on my map that should cast a magic shield on a target friendly unit or self and it's meant to absorb damage equal to 20% of the casting hero's current mana but it seems like it doesn't absorb any damage at all, the shield is destroyed immediately...

The triggers.
  • Nature ProtectionIni
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • -------- Set this to true if you want three of the orbit dummies for an effect, otherwise set it to false for an effect above the unit. --------
      • Set VariableSet SP_Effect_Boolean = False
      • -------- Set this to true if you want three of the orbit dummies for an effect, otherwise set it to false for an effect above the unit. --------
      • -------- --------
      • -------- This denotes whether or not the shield displays remaining life when struck or damage spill when destroyed.. --------
      • Set VariableSet SP_Display_Boolean = True
      • -------- This denotes whether or not the shield displays remaining life when struck or damage spill when destroyed.. --------
      • -------- --------
      • -------- This denotes whether or not the shield life stacks on subsequent casts --------
      • Set VariableSet SP_Stack_Boolean = False
      • -------- This denotes whether or not the shield life stacks on subsequent casts --------
      • -------- --------
      • -------- This is the Life of the shield per level. NOTE: the shield life is calculated as SP_Life + (SP_Life x lvl) --------
      • Set VariableSet SP_Life = (Mana of (Triggering unit))
      • -------- This is the Life of the shield per level. NOTE: the shield life is calculated as SP_Life + (SP_Life x lvl) --------
      • -------- --------
      • -------- This is the duration of the shield --------
      • Set VariableSet SP_Duration = 15.00
      • -------- This is the duration of the shield --------
      • -------- --------
      • Set VariableSet SP_Ability = Nature Protection
      • Set VariableSet SP_Buff = Nature Protection
      • Set VariableSet SP_LifeBonus = Protection Life Bonus
      • Hashtable - Create a hashtable
      • Set VariableSet SP_Hashtabe = (Last created hashtable)
  • Nature ProtectionCast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to SP_Ability
    • Actions
      • -------- Shield Life --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SP_Stack_Boolean Equal to True
        • Then - Actions
          • Set VariableSet SP_Real = (Load 0 of (Key (Target unit of ability being cast).) from SP_Hashtabe.)
          • Hashtable - Save (0.00 + (0.00 + (SP_Life x 0.20))) as 0 of (Key (Target unit of ability being cast).) in SP_Hashtabe.
          • Hashtable - Save (0.00 + (0.00 + (SP_Life x 0.20))) as (Key Maxlife.) of (Key (Target unit of ability being cast).) in SP_Hashtabe.
        • Else - Actions
          • Hashtable - Save (0.00 + (0.00 + (SP_Life x 0.20))) as 0 of (Key (Target unit of ability being cast).) in SP_Hashtabe.
          • Hashtable - Save (0.00 + (0.00 + (SP_Life x 0.20))) as (Key Maxlife.) of (Key (Target unit of ability being cast).) in SP_Hashtabe.
      • -------- Shield Life --------
      • -------- --------
      • -------- Duration --------
      • Hashtable - Save SP_Duration as 1 of (Key (Target unit of ability being cast).) in SP_Hashtabe.
      • -------- Duration --------
      • -------- --------
      • -------- Shield effect --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SP_Effect_Boolean Equal to True
        • Then - Actions
          • Special Effect - Create a special effect attached to the origin of (Target unit of ability being cast) using Spells\NatureBlessing\GaiaShield.mdx
          • Special Effect - Destroy (Last created special effect)
          • Hashtable - Save 0 as (Key Distance.) of (Key (Target unit of ability being cast).) in SP_Hashtabe.
          • Set VariableSet SP_T_Point = (Position of (Target unit of ability being cast))
          • For each (Integer A) from 1 to 3, do (Actions)
            • Loop - Actions
              • Set VariableSet SP_T_Point_2 = (SP_T_Point offset by 50.00 towards (120.00 x (Real((Integer A)))) degrees.)
              • Unit - Create 1 Watch Tower for (Owner of (Target unit of ability being cast)) at SP_T_Point_2 facing Default building facing degrees
              • Hashtable - Save Handle Of(Last created unit) as (Key (Buff + (String((Integer A)))).) of (Key (Target unit of ability being cast).) in SP_Hashtabe.
              • Custom script: call RemoveLocation(udg_SP_T_Point_2)
          • Custom script: call RemoveLocation(udg_SP_T_Point)
        • Else - Actions
          • Special Effect - Destroy (Load 0 of (Key (Target unit of ability being cast).) in SP_Hashtabe.)
          • Special Effect - Create a special effect attached to the origin of (Target unit of ability being cast) using Spells\NatureBlessing\GaiaShield.mdx
          • Hashtable - Save Handle Of(Last created special effect) as 0 of (Key (Target unit of ability being cast).) in SP_Hashtabe.
      • -------- Shield effect --------
      • Unit Group - Add (Target unit of ability being cast) to SP_Group
      • Trigger - Turn on Nature ProtectionLoop <gen>
      • Trigger - Turn on Nature ProtectionBlock <gen>
  • Nature ProtectionLoop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in SP_Group) Greater than 0
        • Then - Actions
          • Unit Group - Pick every unit in SP_Group and do (Actions)
            • Loop - Actions
              • Set VariableSet SP_Real = ((Load 1 of (Key (Picked unit).) from SP_Hashtabe.) - 0.05)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (((Picked unit) has buff SP_Buff) Equal to False) or (SP_Real Less than or equal to 0.00)
                • Then - Actions
                  • Set VariableSet SP_T_Point = (Position of (Picked unit))
                  • Unit - Remove SP_Buff buff from (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • SP_Effect_Boolean Equal to True
                    • Then - Actions
                      • For each (Integer A) from 1 to 3, do (Actions)
                        • Loop - Actions
                          • Unit - Kill (Load (Key (Buff + (String((Integer A)))).) of (Key (Picked unit).) in SP_Hashtabe.)
                    • Else - Actions
                      • Special Effect - Destroy (Load 0 of (Key (Picked unit).) in SP_Hashtabe.)
                      • -------- This is the effect when the shield is destroyed. --------
                      • Special Effect - Create a special effect attached to the chest of (Picked unit) using Abilities\Weapons\KeeperGroveMissile\KeeperGroveMissile.mdl
                      • -------- This is the effect when the shield is destroyed. --------
                      • Special Effect - Destroy (Last created special effect)
                  • Unit Group - Remove (Picked unit) from SP_Group.
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit).) in SP_Hashtabe.
                  • If ((SP_Group is empty) Equal to True) then do (Trigger - Turn off (This trigger)) else do (-------- Do Nothing --------)
                  • Trigger - Turn off Nature ProtectionBlock <gen>
                  • Custom script: call RemoveLocation(udg_SP_T_Point)
                • Else - Actions
                  • Hashtable - Save SP_Real as 1 of (Key (Picked unit).) in SP_Hashtabe.
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • SP_Effect_Boolean Equal to True
                    • Then - Actions
                      • Set VariableSet Distance = ((Load (Key Distance.) of (Key (Picked unit).) from SP_Hashtabe.) + 12.50)
                      • Hashtable - Save Distance as (Key Distance.) of (Key (Picked unit).) in SP_Hashtabe.
                      • For each (Integer A) from 1 to 3, do (Actions)
                        • Loop - Actions
                          • Set VariableSet SP_T_Point = (Position of (Picked unit))
                          • Set VariableSet SP_T_Point_2 = (SP_T_Point offset by 50.00 towards ((120.00 x (Real((Integer A)))) + Distance) degrees.)
                          • Unit - Make (Load (Key (Buff + (String((Integer A)))).) of (Key (Picked unit).) in SP_Hashtabe.) face SP_T_Point_2 over 0.01 seconds
                          • Unit - Move (Load (Key (Buff + (String((Integer A)))).) of (Key (Picked unit).) in SP_Hashtabe.) instantly to SP_T_Point_2
                          • Custom script: call RemoveLocation(udg_SP_T_Point)
                          • Custom script: call RemoveLocation(udg_SP_T_Point_2)
                    • Else - Actions
        • Else - Actions
  • Nature ProtectionBlock
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (GDD_DamagedUnit has buff SP_Buff) Equal to True
    • Actions
      • Custom script: set udg_SP_UnitID = GetHandleId(udg_GDD_DamagedUnit)
      • Set VariableSet SP_Real = (Load 0 of SP_UnitID from SP_Hashtabe.)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SP_Real Greater than 0.00
        • Then - Actions
          • If (SP_Target Not equal to No unit) then do (Trigger - Run Nature ProtectionHeal <gen> (ignoring conditions)) else do (-------- Do Nothing --------)
          • Set VariableSet SP_Damage = GDD_Damage
          • Set VariableSet SP_Real = (SP_Real - SP_Damage)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SP_Effect_Boolean Equal to True
            • Then - Actions
              • For each (Integer A) from 1 to 3, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • SP_Real Less than or equal to ((Load (Key Maxlife.) of SP_UnitID from SP_Hashtabe.) - (((Load (Key Maxlife.) of SP_UnitID from (Last created hashtable).) / 3.00) x (Real((Integer A)))))
                    • Then - Actions
                      • Unit - Kill (Load (Key (Buff + (String((Integer A)))).) of SP_UnitID in SP_Hashtabe.)
                    • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SP_Real Less than or equal to 0.00
            • Then - Actions
              • Unit - Remove SP_Buff buff from GDD_DamagedUnit
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SP_Real Less than 0.00
                • Then - Actions
                  • Set VariableSet SP_T_Point = (Position of GDD_DamagedUnit)
                  • Unit - Cause GDD_DamageSource to damage GDD_DamagedUnit, dealing (SP_Real x -1.00) damage of attack type Hero and damage type Divine
                  • Custom script: call RemoveLocation(udg_SP_T_Point)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • SP_Display_Boolean Equal to True
                    • Then - Actions
                      • Floating Text - Create floating text that reads (String((Integer(SP_Real)))) above GDD_DamagedUnit with Z offset 0.00, using font size 10.00, color (80.00%, 0.00%, 0.00%), and 20.00% transparency
                      • Set VariableSet SP_FText = (Last created floating text)
                      • Set VariableSet SP_PlayerGroup = (Player group((Owner of GDD_DamagedUnit)))
                      • Floating Text - Hide SP_FText for (All players)
                      • Floating Text - Show SP_FText for SP_PlayerGroup
                      • Floating Text - Set the velocity of SP_FText to 90.00 towards 90.00 degrees
                      • Floating Text - Change SP_FText: Disable permanence
                      • Floating Text - Change the lifespan of SP_FText to 2.00 seconds
                      • Floating Text - Change the fading age of SP_FText to 1.00 seconds
                      • Custom script: call DestroyForce(udg_SP_PlayerGroup)
                    • Else - Actions
                • Else - Actions
              • Set VariableSet SP_Damage = SP_Real
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SP_Effect_Boolean Equal to True
                • Then - Actions
                  • For each (Integer A) from 1 to 3, do (Actions)
                    • Loop - Actions
                      • Unit - Kill (Load (Key (Buff + (String((Integer A)))).) of SP_UnitID in SP_Hashtabe.)
                • Else - Actions
                  • Special Effect - Destroy (Load 0 of SP_UnitID in SP_Hashtabe.)
                  • -------- This is the effect when the shield is destroyed. --------
                  • Special Effect - Create a special effect attached to the chest of GDD_DamagedUnit using Abilities\Weapons\KeeperGroveMissile\KeeperGroveMissile.mdl
                  • -------- This is the effect when the shield is destroyed. --------
                  • Special Effect - Destroy (Last created special effect)
              • Unit Group - Remove GDD_DamagedUnit from SP_Group.
              • Hashtable - Clear all child hashtables of child SP_UnitID in SP_Hashtabe.
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SP_Display_Boolean Equal to True
                  • SP_Damage Greater than 0.99
                • Then - Actions
                  • Set VariableSet SP_T_Point = (Position of GDD_DamagedUnit)
                  • Floating Text - Create floating text that reads (String((Integer(SP_Real)))) at (SP_T_Point offset by (Random real number between 0.00 and 50.00) towards (Random angle) degrees.) with Z offset 0.00, using font size 9.00, color (0.00%, 100.00%, 100.00%), and 20.00% transparency
                  • Set VariableSet SP_FText = (Last created floating text)
                  • Set VariableSet SP_PlayerGroup = (Player group((Owner of GDD_DamagedUnit)))
                  • Floating Text - Hide SP_FText for (All players)
                  • Floating Text - Show SP_FText for SP_PlayerGroup
                  • Floating Text - Set the velocity of SP_FText to 90.00 towards 90.00 degrees
                  • Floating Text - Change SP_FText: Disable suspend state
                  • Floating Text - Change SP_FText: Disable permanence
                  • Floating Text - Change the lifespan of SP_FText to 1.00 seconds
                  • Floating Text - Change the fading age of SP_FText to 0.25 seconds
                  • Custom script: call RemoveLocation(udg_SP_T_Point)
                  • Custom script: call DestroyForce(udg_SP_PlayerGroup)
                • Else - Actions
              • Hashtable - Save SP_Real as 0 of SP_UnitID in SP_Hashtabe.
          • Set VariableSet SP_Target = GDD_DamagedUnit
          • -------- Using big life bonus to prevent death if damage>=max hp --------
          • Unit - Add SP_LifeBonus to SP_Target
          • Countdown Timer - Start SP_Timer as a One-shot timer that will expire in 0.00 seconds
        • Else - Actions
          • Unit - Remove SP_Buff buff from GDD_DamagedUnit
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SP_Effect_Boolean Equal to True
            • Then - Actions
              • For each (Integer A) from 1 to 3, do (Actions)
                • Loop - Actions
                  • Unit - Kill (Load (Key (Buff + (String((Integer A)))).) of SP_UnitID in SP_Hashtabe.)
            • Else - Actions
              • Special Effect - Destroy (Load 0 of SP_UnitID in SP_Hashtabe.)
              • -------- This is the effect when the shield is destroyed. --------
              • Special Effect - Create a special effect attached to the chest of GDD_DamagedUnit using Abilities\Weapons\KeeperGroveMissile\KeeperGroveMissile.mdl
              • -------- This is the effect when the shield is destroyed. --------
              • Special Effect - Destroy (Last created special effect)
          • Unit Group - Remove GDD_DamagedUnit from SP_Group.
          • Hashtable - Clear all child hashtables of child SP_UnitID in SP_Hashtabe.
  • Nature ProtectionHeal
    • Events
      • Time - SP_Timer expires
    • Conditions
    • Actions
      • Unit - Set life of SP_Target to ((Life of SP_Target) + SP_Damage)
      • Unit - Remove SP_LifeBonus from SP_Target
      • Set VariableSet SP_Target = No unit
 
Level 39
Joined
Feb 27, 2007
Messages
5,050
  • Set VariableSet SP_Life = (Mana of (Triggering unit))
You cannot do this in an init trigger. It has a value of 0. This is an actual real value not an expression that is evaluated whenever it’s needed. You need to compute this value when the spell is cast….
 
Last edited:
Status
Not open for further replies.
Top