HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Shield Spells?

01-24-2010, 06:12 PM#1
Raydude
Someone asked and I got it to work this far for him, but it doesn't work for aoe spells in MUI(or just MPI) and I know it's cause two units are using the trigger at the same instance, but I'm not sure if there's a definite easy solution for it... in gui...helps!


Initialization

Initialization:
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Inner Fire
Collapse Actions
Hashtable - Save Handle OfShieldEffect <gen> as (Key Trigger) of (Key (Target unit of ability being cast)) in (Last created hashtable)
Set Unit = (Target unit of ability being cast)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Unit is in UnitGroup) Not equal to True
Collapse Then - Actions
Trigger - Add to (Load (Key Trigger) of (Key (Target unit of ability being cast)) in (Last created hashtable)) the event (Unit - Unit Takes damage)
Unit Group - Add Unit to UnitGroup
Else - Actions
Set ShieldLife = 400.00
Hashtable - Save ShieldLife as (Key Shieldlife) of (Key (Target unit of ability being cast)) in Hashtable


ShieldEffect

ShieldEffect:
Events
Collapse Conditions
((Attacked unit) has buff Inner Fire) Equal to True
Collapse Actions
Set ShieldLife = (Load (Key Shieldlife) of (Key (Attacked unit)) from Hashtable)
Set Damage = (Damage taken)
Set Unit = (Attacked unit)
Game - Display to (All players) the text: (Damage taken : + (String(Damage)))
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Damage Greater than ShieldLife) or ((Damage Greater than or equal to (Life of Unit)) or ((Percentage life of Unit) Equal to 100.00))
Collapse Then - Actions
If (Damage Greater than or equal to (Life of Unit)) then do (Set Boolean = True) else do (Do nothing)
Game - Display to (All players) the text: (Initial Shieldlife + (String(ShieldLife)))
Unit - Add LifeBonus (Greater) to Unit
Unit - Set life of Unit to ((Life of Unit) + Damage)
Countdown Timer - Start Timer as a One-shot timer that will expire in 0.00 seconds
Wait 0.00 seconds
Hashtable - Save ShieldLife as (Key Shieldlife) of (Key (Attacked unit)) in Hashtable
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
ShieldLife Less than or equal to 0.00
Collapse Then - Actions
Unit - Set life of Unit to ((Life of Unit) + ShieldLife)
Unit - Remove Inner Fire buff from Unit
Game - Display to (All players) the text: OFF!!
Hashtable - Clear all child hashtables of child (Key Shieldlife) in Hashtable
Else - Actions
Collapse Else - Actions
Game - Display to (All players) the text: (Initial Shieldlife + (String(ShieldLife)))
Unit - Set life of Unit to ((Life of Unit) + Damage)
Set ShieldLife = (ShieldLife - Damage)
Hashtable - Save ShieldLife as (Key Shieldlife) of (Key (Attacked unit)) in Hashtable
Game - Display to (All players) the text: (Final Shieldlife + (String(ShieldLife)))
Set Boolean = False


ShieldEffectTimer

Trigger:
Collapse Events
Time - Timer expires
Conditions
Collapse Actions
Unit - Remove LifeBonus (Greater) from Unit
Set ShieldLife = (ShieldLife - Damage)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Boolean Equal to False
Collapse Then - Actions
Unit - Set life of Unit to ((Life of Unit) + ShieldLife)
Else - Actions
Game - Display to (All players) the text: (Final Shieldlife + (String(ShieldLife)))

01-24-2010, 07:44 PM#2
Anitarf
Why would you store a static trigger (OfShieldEffect <gen>) into the hashtable for every unit?

The "Attacked unit" is meant to be used in triggers with an attack event and as far as I know does not do anything in triggers that run on the damage event.

In the timer callback, you never update the shield life stored in the hashtable. Also, you increase the unit's life by the amount of shield life remaining rather than the amount of damage blocked.

There must be at least half a dozen cases in which this code makes an error or just downright fails. Why not use a system that actually works instead, like DamageModifiers?
01-24-2010, 09:56 PM#3
Raydude
I stored the trigger in hopes that it'll not conflict and I don't have to create a trigger for ever unit that casts, but that sort of was a dumb idea, forgot to take it back out.
The Attacked unit works though, oddly.
I updated the hashtable after I called the timer, and I called the timer to heal the shield life remaining because that timer only runs whenever damage > shield, I subtracted shield from damage and shieldlife would be negative, that's the leftover damage not blocked so I added the unit by that.
This code actually doesn't make an error at all except the case of two units getting damaged in one instance =/ but I do admit it's a fail
01-24-2010, 10:04 PM#4
Anitarf
Quote:
Originally Posted by Raydude
because that timer only runs whenever damage > shield
That is not what your condition says:

(Damage Greater than ShieldLife) or ((Damage Greater than or equal to (Life of Unit)) or ((Percentage life of Unit) Equal to 100.00))

What happens for example if a unit with 10/100 hp and a shield with 100 hp takes 20 damage?
01-25-2010, 12:06 AM#5
Raydude
Well when damage > life of the unit, the trigger gives lifebonus, adds the damage as life, remove the lifebonus, set shieldlife = (shieldlife-damage), and unit stays alive with 80 shield life.
When damage > shield life, it does the same thing as when damage > life, but also adds the lifeshield at the end, which should be a negative number as it was set to (shieldlife - damage).

e: oh wow I'm confused myself now, I don't get how come the trigger works perfectly during a lot of my tests anymore, there seems to be conflicts =/