#Make summoned entity do damage only to hostiles

7 messages · Page 1 of 1 (latest)

clear eagle
#

Hello again.

i have this custom script that spawns a entity of type irons_spellbooks:sunbeam and i its damage with nbt tag {Damage: damageformula}

but every time i use the item and the entity spawns it also damage the player.

ItemEvents.firstRightClicked("mobz:boss_sword", (event) => {
  let $MagicData = Java.loadClass("io.redspace.ironsspellbooks.api.magic.MagicData");
  const { entity, player } = event;
  let sunbeam = entity.level.createEntity("irons_spellbooks:sunbeam");
  let player_holy_power = player.getAttribute("irons_spellbooks:holy_spell_power").value;
  let player_spell_power = player.getAttribute("irons_spellbooks:spell_power").value;
  let player_attack_power = player.getAttribute("minecraft:generic.attack_damage").value;
  let magic_data = $MagicData.getPlayerMagicData(player);
  let current_mana = magic_data.getMana();
  let max_mana = player.getAttribute("irons_spellbooks:max_mana").value;
  let sunbeamDamageFormula = (player_holy_power + player_spell_power) * player_attack_power;
  if (entity.level.clientSide) return;


  sunbeam.mergeNbt(`{Owner: ${player.getUuid()}}`);
  sunbeam.mergeNbt(`{Damage: ${sunbeamDamageFormula}}`);
  sunbeam.x = entity.x;
  sunbeam.y = entity.y;
  sunbeam.z = entity.z;

  // if (current_mana >= 600 && current_mana == max_mana) {
    if (current_mana >= 0) {
    player.runCommandSilent("mana set @s 0");
    player.runCommandSilent("particle irons_spellbooks:wisp ~ ~ ~ .1 1.5 .1 .05 1000");
    player.runCommandSilent("effect give @s minecraft:glowing 30 0");
    player.runCommandSilent("effect give @s minecraft:strength 30 1");
    player.runCommandSilent("effect give @s irons_spellbooks:angel_wings 5 0");
    sunbeam.spawn();
    player.runCommandSilent("cast @s divine_smite 1");
  // }else if(current_mana != max_mana){
  //   player.tell("Sua mana precisa estar cheia.")
  // }else if(current_mana < 600){
  //   player.tell("Requer 600 de Mana.")
  // }else{
  //   player.tell("Erro desconhecido.")
  }
});

PS: ignore the commented lines, it is just for debug purposes

lilac wigeonBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

clear eagle
#

if it is not possible, i gladly accept workarounds like, making the player imune for a moment or something like that

bright marten
clear eagle
#

oh! thats really nice

#

thank you 😄

lilac wigeonBOT
#

Ticket closed!