[Question] How can I get player stages from entity.attack event? #181
Answered
by
MaxNeedsSnacks
moniq-e
asked this question in
Script-related questions
-
I'm trying to block the player to attack any entity with an specific sword behind a stage. |
Beta Was this translation helpful? Give feedback.
Answered by
MaxNeedsSnacks
Aug 12, 2021
Replies: 1 comment 1 reply
-
So first off, since you can't get the game stage of a damage source, you should use To access a player's stages, you can use onEvent('entity.attack', event => {
const player = event.source.player;
if(player) {
if(!player.stages.has('cacador') && player.mainHandItem == 'tconstruct:cleaver') {
// do your thing
event.cancel() // don't use return here, cancel is a void method
}
}
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
moniq-e
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So first off, since you can't get the game stage of a damage source, you should use
event.source.player
instead and also check whether that is null, since damage sources can also be for example lightning bolts etc. (which obviously cannot have gamestages)To access a player's stages, you can use
player.stages
and then for example check usingstages.has
or add a new stage usingstages.add
, so in total, you'd have something like