• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

making damage increase with ability level

Status
Not open for further replies.
Level 9
Joined
Jun 10, 2013
Messages
473
hey all and happy new year, can anyone show me how to make the damage of 50 increase by 50 every time the hero levels up the ability. btw I copied this from here http://www.hiveworkshop.com/forums/...-line-between-blink-start-destination-213321/
and made it deal damage but that's my full extent of JASS knowledge which I do want to improve upon


JASS:
//! zinc
library DamageBlink {
      constant integer ABILITY ='A01L';
      constant real SQUARE_WIDTH = 5625.;//75^2
      constant real DAMAGE = 50.;
      constant group G = CreateGroup();

      function onInit() {
          trigger trig = CreateTrigger();
          integer i = 0;
          do {
              TriggerRegisterPlayerUnitEvent(trig, Player(i),
                  EVENT_PLAYER_UNIT_SPELL_EFFECT, null);
              i += 1;
          } while (i < 16);
          TriggerAddCondition(trig,
              function() -> boolean {
                  return GetSpellAbilityId() == ABILITY;
              }
          );
          TriggerAddAction(trig,
              function() {
                  unit u = GetTriggerUnit(), u2;
                  player p = GetOwningPlayer(u);
                  real x = GetWidgetX(u), y = GetWidgetY(u),
                      tx = GetSpellTargetX(), ty = GetSpellTargetY(),
                      k = (y - ty) / (x - tx), b = y - k * x,
                      k1 = -1. / k, b1;
                  GroupEnumUnitsInRange(G, (x + tx) * .5, (y + ty) * .5,
                      SquareRoot((x - tx) * (x - tx) + (y - ty) * (y - ty)) * .5, null);
                  while (true) {
                      u2 = FirstOfGroup(G);
                      if (u2 == null) { break; }
                      GroupRemoveUnit(G, u2);
                      if (IsUnitEnemy(u2, p)) {
                          tx = GetWidgetX(u2);
                          ty = GetWidgetY(u2);
                          b1 = ty - k1 * tx;
                          x = (b1 - b) / (k - k1);
                          y = k * x + b;
                          if ((x - tx) * (x - tx) + (y - ty) * (y - ty) <= SQUARE_WIDTH) {
                              SetWidgetLife(u2, GetWidgetLife(u2) - DAMAGE);
                          }
                      }
                  }
                  u = null; p = null;
              }
          );
          trig = null;
      }
}
//! endzinc
 
Level 29
Joined
Sep 26, 2009
Messages
2,596
You could try something like this:
First, where you have "unit u", "player p", etc. add also:
real dmg = 0; (not sure if it has to be initialized or not)

Then in the IF part, change the part where you do:
SetWidgetLife(u2, GetWidgetLife(u2) - DAMAGE);
into this:
JASS:
dmg = DAMAGE * GetUnitAbilityLevel(u, ABILITY)
SetWidgetLife(u2, GetWidgetLife(u2) - dmg);

Basically the function GetUnitAbilityLevel returns the level of ability for specific unit (u is TriggeringUnit and ABILITY is the ability that fires the spell) and you multiply that value by DAMAGE amount.
 
Level 9
Joined
Jun 10, 2013
Messages
473
You could try something like this:
First, where you have "unit u", "player p", etc. add also:
real dmg = 0; (not sure if it has to be initialized or not)

Then in the IF part, change the part where you do:
SetWidgetLife(u2, GetWidgetLife(u2) - DAMAGE);
into this:
JASS:
dmg = DAMAGE * GetUnitAbilityLevel(u, ABILITY)
SetWidgetLife(u2, GetWidgetLife(u2) - dmg);

Basically the function GetUnitAbilityLevel returns the level of ability for specific unit (u is TriggeringUnit and ABILITY is the ability that fires the spell) and you multiply that value by DAMAGE amount.

it would appear that real damage = 0 has to be initialized first since I get an error about it;

Screenshot (270).png

Screenshot (271).png


///////////////////////////EDIT///////////////////////////////////

I've edited the code to this and I know longer get errors from WE, however I am yet to test it in game;

JASS:
library DamageBlink {
      constant integer ABILITY ='A01L';
      constant real SQUARE_WIDTH = 5625.;//75^2
      constant real DAMAGE = 50.;
      constant real dmg = 0.;
      constant group G = CreateGroup();
      
      function onInit() {
          trigger trig = CreateTrigger();
          integer i = 0;
          do {
              TriggerRegisterPlayerUnitEvent(trig, Player(i),
                  EVENT_PLAYER_UNIT_SPELL_EFFECT, null);
              i += 1;
          } while (i < 16);
          TriggerAddCondition(trig,
              function() -> boolean {
                  return GetSpellAbilityId() == ABILITY;
              
              }
        
        
          );
          TriggerAddAction(trig,
              function() {
                  unit u = GetTriggerUnit(), u2;
                  player p = GetOwningPlayer(u);
                  real dmg = 0; 
                  real x = GetWidgetX(u), y = GetWidgetY(u),
                      tx = GetSpellTargetX(), ty = GetSpellTargetY(),
                      k = (y - ty) / (x - tx), b = y - k * x,
                      k1 = -1. / k, b1;
                  GroupEnumUnitsInRange(G, (x + tx) * .5, (y + ty) * .5,
                      SquareRoot((x - tx) * (x - tx) + (y - ty) * (y - ty)) * .5, null);
                  while (true) {
                      u2 = FirstOfGroup(G);
                      if (u2 == null) { break; }
                      GroupRemoveUnit(G, u2);
                      if (IsUnitEnemy(u2, p)) {
                          tx = GetWidgetX(u2);
                          ty = GetWidgetY(u2);
                          b1 = ty - k1 * tx;
                          x = (b1 - b) / (k - k1);
                          y = k * x + b;
                          if ((x - tx) * (x - tx) + (y - ty) * (y - ty) <= SQUARE_WIDTH) {
                              dmg = DAMAGE * GetUnitAbilityLevel(u, ABILITY);
                              SetWidgetLife(u2, GetWidgetLife(u2) - dmg);
                          }
                      }
                  }
                  u = null; p = null;
              }
          );
          trig = null;
      }
}
//! endzinc
 
Last edited:
Level 9
Joined
Jun 10, 2013
Messages
473
Use
JASS:
constant real damage
then.

Also, dont use set widget life, but:
JASS:
call UnitDamageTarget takes(u, u2, dmg, true, false, ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)

Replace
JASS:
ATTACK_TYPE_NORMAL
and
JASS:
DAMAGE_TYPE_NORMAL
with whatever attack and damage type you want.

On it and thanks guys

///////////////edit///////////////////////

I get this error after making your changes Silent;

Screenshot (274).png

Screenshot (275).png
 
On it and thanks guys

///////////////edit///////////////////////

I get this error after making your changes Silent;

View attachment 151394

View attachment 151395

Yeah, sorry it is:

JASS:
call UnitDamageTarget(u, u2, dmg, true, false, ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
'

Copied too much over.
The other part I cannot help you with, as far as I can see it is just supposed to be a comment, and can therefore be deleted.
 
Status
Not open for further replies.
Top