| 08-07-2006, 02:59 AM | #1 |
Ok so im trying to trigger a "parry" spell and what I need to do is have it so whenever the unit is attacked it has a chance to deal the attacking unit's damage back to it and avoid all damage from the attack. I already have the part down where the unit deals the damage back to the attacking unit but i need a way for the attacked unit to avoid the damage to (without using any abilitys, it has to be entierly triggered). thanks! ![]() |
| 08-07-2006, 04:30 AM | #2 |
the problem with such an ability is that it is not possible to figure out whether the attack is physical or magical. Therefore, you were to use the "Unit Takes Any Damage" event, you may very well parry a spell. To fix this, you probably have to consider this: JASS:function remove_possible_attacker takes nothing returns nothing local timer t = GetExpiredTimer() local unit u = GetHandleUnit(t, "u") local group g = GetHandleGroup(t, "g") call FlushHandleLocals(t) call GroupRemoveUnit(g, u) call DestroyTimer(t) set t = null set u = null set g = null endfunction function unit_is_attacked takes nothing returns nothing local trigger t = GetTriggeringTrigger() local group g = GetHandleGroup(t, "g") local timer r = null if GetRandomInt(0,99) < Parry_Chance() then //Parry_Chance() is a constant function which returns the chance of it triggering set r = CreateTimer() call SetHandleHandle(r, "u", GetAttacker()) call SetHandleHandle(r, "g", g) call TimerStart(r, Get_Time_Damage_Point(), false, function remove_possible_attacker) //Get_Time_Damage_Point() is whichever number you feel is appropriate for any unit's damage point (the time of the animation at which damage is dealt) set r = null endif set t = null set g = null endfunction function unit_is_damaged takes nothing returns nothing local unit c = GetTriggerUnit() local group g = GetHandleGroup(GetExpiredTimer(), "g") local group p = CreateGroup() local unit k local real d = GetEventDamage() call GroupAddGroup(g, p) set k = FirstOfGroup(g) if k != null then loop exitwhen k == null if k == GetEventDamageSource() then call SetUnitState(c, UNIT_STATE_LIFE, d+GetUnitState(c, UNIT_STATE_LIFE)) call UnitDamageTargetBJ(c, k, d, ATTACK_TYPE_HERO, DAMAGE_TYPE_ENHANCED) call GroupRemoveUnit(g, k) endif call GroupRemoveUnit(p, k) set k = FirstOfGroup() endloop endif set k = null set c = null set g = null endfunction function unit_learns_parry takes nothing returns nothing local trigger t = CreateTrigger() local trigger q = CreateTrigger() local group g = CreateGroup() call SetHandleHandle(t, "g", g) call TriggerRegisterUnitEvent(t, GetTriggerUnit(), EVENT_UNIT_DAMAGED) call TriggerAddAction(t, function unit_is_damaged) call SetHandleHandle(q, "g", g) call TriggerRegisterUnitEvent(t, GetTriggerUnit(), EVENT_UNIT_ATTACKED) call TriggerAddAction(t, function unit_is_attacked) set t = null set r = null set g = null endfunction |
| 08-07-2006, 01:15 PM | #3 |
@EveningStar: You can detect if the damage is done by an attack, the frost orb ability adds a buff to the unit when its damaged. Add it to all units at map init. Once you detect the buff on the unit (in the unit damaged event) you know it was done by an attack, you then need to remove the buff to prevent false attack detects. To block the damage, you cant simply change the damaged' unit's HP to negate the damage, because the event fires before the damage is done, my DamageModify function will allow you to block damage without having to worry about that and other issues with blocking damage (read the description first). |
| 08-07-2006, 08:08 PM | #4 |
Unless you're starting from scratch, I feel that method makes things more complicated. Of course, it would depend on where this is to be used. If it's for Hero Arena, it might be too clumsy to add Frost Attack to every hero, not to mention it uses up the precious Orb Effect slot. |
| 08-07-2006, 09:41 PM | #5 | |
Quote:
|
| 08-18-2006, 03:52 AM | #6 |
Thanks guys! btw, sorry i havent responded in so long but ive been busy. |
