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

Anti chain lightning buff.

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
So the below is activated when the spell chain lightning is used on a human peasant unit. It applies a 60% chain buff after the first chain goes off. So basically first chain does full damage, and any other chain's do 60% less damage until the buff wears off.

It works sometimes, but for some reason later in the game it doesn't work, or if there's more players nearby(more peasants side by side)

This trigger seems to be running before the damage actually affects the player. So essentially it's making both chain lightning (even the first chain) do 60% less damage. Got any solution for me?
If I add some sort of wait command when the first chain goes off, I run the risk of two players using chain at the same time doing full damage.


JASS:
library chainOfDeath requires AbilityEvent, libMisc, libSetup {

private function vA() {
  timer t = GetExpiredTimer();
  UnitHandle uh = GetTimerData(t);  
 
  UnitRemoveAbility(uh.u, ID_BUFF_GROUNDED);

  uh.destroy();
  ReleaseTimer(t);
}

private function eA() {
    timer t = GetExpiredTimer();
    UnitHandle uh = GetTimerData(t);
   
    UnitRemoveAbility(uh.u, ID_ABILITY_GND_BUFFPLACER);
    UnitRemoveAbility(uh.u, ID_BUFF_GROUNDED);

    uh.destroy();
    ReleaseTimer(t);
}

private function OnChainEffect() {
  unit uT = GetSpellTargetUnit();
  boolean b;
  xedamage dmg;
  GroupEnumUnitsInRange(ENUM_GROUP, GetUnitX(uT), GetUnitY(uT), 256., null);
  for(ENUM_UNIT = EnumGroupInit(); EnumGroupCheck(); ENUM_UNIT = EnumGroupEnd()) {
    if (IsHuman(ENUM_UNIT)) {
      if (GetUnitAbilityLevel(ENUM_UNIT, ID_BUFF_GROUNDED) > 0) {
   
        UnitAddAbility(ENUM_UNIT, ID_ABILITY_GROUNDED);
        UnitMakeAbilityPermanent(ENUM_UNIT, true, ID_ABILITY_GROUNDED);
        TimerStart(NewTimerEx(UnitHandle.create(ENUM_UNIT)), 2.5, false, function vA);
      }
      else if (GetUnitAbilityLevel(ENUM_UNIT, ID_BUFF_GROUNDED) == 0) {
        UnitAddAbility(ENUM_UNIT, ID_ABILITY_GND_BUFFPLACER);
        UnitMakeAbilityPermanent(ENUM_UNIT, true, ID_ABILITY_GND_BUFFPLACER);
        TimerStart(NewTimerEx(UnitHandle.create(ENUM_UNIT)), 8, false, function eA);
      }
    }
    else if (GetUnitTypeId(ENUM_UNIT) == ID_ENGINEER) {
      b = false;
      GroupEnumUnitsInRange(ENUM_GROUP2, GetUnitX(ENUM_UNIT), GetUnitY(ENUM_UNIT), 256., null);
      for(ENUM_UNIT2 = EnumGroupInit2(); EnumGroupCheck2(); ENUM_UNIT2 = EnumGroupEnd2()) {
        if (IsWall(ENUM_UNIT2) && GetOwningPlayer(ENUM_UNIT2) != GetOwningPlayer(ENUM_UNIT)) {
          b = true;
        }
      }
      if (b) {
        dmg = xedamage.create();
        dmg.damageTargetForceValue(GetSpellAbilityUnit(), ENUM_UNIT, 2000); // increased from 1000 to insta kill engineers
        dmg.destroy();
      }
    }
  }

  uT = null;
}

private function onInit() {
  AddAbilityEffectEvent(ID_ABILITY_CHAIN, OnChainEffect);
}
}
 
Level 12
Joined
Dec 2, 2016
Messages
733
Use a DDS to add the buff after the damage caused by chain lightning is dealt.
What's happening is if it's just one player that uses chain of death the buff only applies after the damage is dealt. But if me and another player use chain at the same time it applies both buffs before the damage is dealt. What could be causing that?
 
Status
Not open for further replies.
Top