#Damage doubled after n attacks

6 messages · Page 1 of 1 (latest)

drifting fiber
#
function doubleDamagePerAttacks(amount, event) {
  const {
    source: { player },
    entity,
    damage,
  } = event;

  if (!player) return;

  const { data } = player;
  data.HitCount = data.HitCount || 0;
  data.HitCount++;

  if (data.HitCount > amount) {
    player.runCommandSilent('title @s actionbar "§6Double Damage!"');
    data.HitCount = 0;
    entity.attack(damage * 2);
  }
}
crude leaf
#

you should just store it in persistent data no? and then it won't be single player only

drifting fiber
#

Damage doubled after n attacks

gleaming scaffold
#

Just a small design tip for making readable code.
You can invert your logic to reduce the amount of indentation you have in your code

#

So rather than

if(player) {
  // Logic…
}

Instead you do:

if(!player) {
  return;
}
// Logic…

On a small scale it won’t cause many problems, but the habit of doing this will make larger code much easier to follow along and read.