#apply knockback from entity
1 messages · Page 1 of 1 (latest)
i haven't tested if this works
but it should
world.afterEvents.itemUse.subscribe((data) => {
const item = data.itemStack
const player = data.source
if (data.itemStack.typeId == 'minecraft:stick') {
const entityarray = world.getDimension(player.dimension.id).getEntities({type:'minecraft:pig', closest: 1})
if (entityarray != []) {
const entity = entityarray[0]
player.applyKnockback(player.location.x - entity.location.x, player.location.z - entity.location.z, 1, 1)
}
}
})
waiti forgor smt
world.afterEvents.itemUse.subscribe((data) => {
const item = data.itemStack
const player = data.source
if (data.itemStack.typeId == 'minecraft:stick') {
const entityarray = world.getDimension(player.dimension.id).getEntities({location: player.location ,type:'minecraft:pig', closest: 1})
if (entityarray != []) {
const entity = entityarray[0]
player.applyKnockback(player.location.x - entity.location.x, player.location.z - entity.location.z, 1, 1)
}
}
})
ok lemme check it out
@steady pollen this works! is this something i can have run constantly?
and without using an item
just constantly checking if a player has a tag
like if i have the tag doExplode i get knockbacked from the closest pig
system.runInterval(() => {
const players = world.getAllPlayers()
players.forEach((player) => {
if (player.hasTag('test')) {
const entityarray = world.getDimension(player.dimension.id).getEntities({location: player.location ,type:'minecraft:pig', closest: 1})
if (entityarray != []) {
const entity = entityarray[0]
player.applyKnockback(player.location.x - entity.location.x, player.location.z - entity.location.z, 1, 1)
}
}
})
})
that does it every tick
or it should atleast
i'd lower it
yeah
np
thank you @steady pollen !!
coolio
it like
just
dawned on me in your pfp
you can barely see it but its there
IT BROKEE
LMFAO WHAT DID I DO
is there a pig
instead of entityarray != []
do entityarray[0] != undefined
and see if that fixes it
did that fix it?
?
did you get the error to go away
this should if you didn't fix it already
nice
what does it say in game
no error
just will not work
cause i was gonna make a smaller boom
lets seee
you have to put a } on the line after player.runCommandAsync('kill @e[name=nadeboom]')
system.runInterval(() => {
const players = world.getAllPlayers()
players.forEach((player) => {
if (player.hasTag('c4explode')) {
const entityarray = world.getDimension(player.dimension.id).getEntities({location: player.location ,type:'minecraft:armor_stand', closest: 1})
if (entityarray != []) {
const entity = entityarray[0]
player.applyKnockback(player.location.x - entity.location.x, player.location.z - entity.location.z, 10, 1.2)
player.removeTag('c4explode')
player.runCommandAsync('kill @e[name=c4explode]')
}
if (player.hasTag('c4explode2')) {
const entityarray = world.getDimension(player.dimension.id).getEntities({location: player.location ,type:'minecraft:armor_stand', closest: 1})
if (entityarray != []) {
const entity = entityarray[0]
player.applyKnockback(player.location.x - entity.location.x, player.location.z - entity.location.z, 10, 1.2)
player.removeTag('c4explode2')
player.runCommandAsync('kill @e[name=c4explode]')
}
}
}
})
})
i have this rn
is it working?
no
what isn't working exactly
figured it out i think
holup
yeahh
i had everything inside the first if statement
yeah that's what i meant earlier
wit dis
oh yeah i see it now
nvm i was being dumb earlier
mb