#Increase monster max Health for more difficulty
24 messages · Page 1 of 1 (latest)
Is this a better way to typing it ?
yep
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.
Ooooh thank you for that !
you could also swap if (entity.monster) { for a guard clause
if (!entity.monster) return
EntityEvents.checkSpawn((event) => {
const { entity } = event;
if (!entity.monster) return;
entity.maxHealth = entity.maxHealth * 5;
entity.health = entity.maxHealth;
})
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
personally i think setter methods are prettier than just setting them with =
Hey, there is a way to make it with bosses ? Like change "monster" in "bosses" or something else ?
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)
try using EntityEvents.spawned instead
well, lowercase S but ye
Yeah lowercase S ^^