#Increase monster max Health for more difficulty

24 messages · Page 1 of 1 (latest)

sharp cradle
#
EntityEvents.checkSpawn((event) => {
  const { entity } = event;
  if (entity.monster) {
    entity.maxHealth = entity.maxHealth * 5;
    entity.health = entity.maxHealth;
  }
})
humble seal
#

Is this a better way to typing it ?

sharp cradle
#

yep

vernal lindenBOT
#

Kubejs has a feature known as beans which allows you to make scripts a tad more readable.
Anything getXy() can be gotten with xy, anything setXy(value) can be set with xy = value and anything isXy() can be checked with just xy.

This allows us to shorten our code! For example, to get a list of all online players you can do: event.getServer().getPlayers(). With beans this can be shortened to event.server.players!

Note that get and is beans only work if the method has no parameters. This means a method like getHeldItem(InteractionHand hand) cannot be shortened to heldItem.
For set the method needs to have a single parameter.

humble seal
#

Ooooh thank you for that !

formal flicker
#

you could also swap if (entity.monster) { for a guard clause
if (!entity.monster) return

sharp cradle
#
EntityEvents.checkSpawn((event) => {
  const { entity } = event;
  if (!entity.monster) return;

  entity.maxHealth = entity.maxHealth * 5;
  entity.health = entity.maxHealth;
})
sinful goblet
#
EntityEvents.checkSpawn((event) => {
  const { entity } = event;
  if (!entity.monster) return;

  entity.health = entity.maxHealth = entity.maxHealth * 5;
})
#

should work unless some Rhino thing breaks it

magic brook
#

personally i think setter methods are prettier than just setting them with =

humble seal
#

Hey, there is a way to make it with bosses ? Like change "monster" in "bosses" or something else ?

humble seal
#

Anyway, it work with bosses but not with bosses spawned by structure like wither with soulsand, so if someone can help me how can i integrate that in my code that's cool
Sorry for my English and being a newbie in code x)

formal flicker
magic brook
#

well, lowercase S but ye

humble seal
#

Yeah lowercase S ^^

formal flicker
#

:D

#

too much C# lately

humble seal
#

It work 😄

#

Thank you

cosmic grail
#

do I need to change every "entity" typing to my entity ID?

#

@humble seal

#

or it does apply for every monster entity?

#

oh

#

how can I apply this to specific mob?