system.runInterval(() => {
let player = event.source
player.runCommandAsync("effect @s night_vision 99 99")
}
, 40
)
})``` I've got this little snippet of code, everything that needs importing has been done already as well, but when I join the world, it says cannot read property runCommandAsync. It's porbably a small oversite but I am to tired to think straight.
#Constantly running a command
1 messages · Page 1 of 1 (latest)
The properties on PlayerJoinAfterEvent are 'playerId' and 'playerName'. There isn't a 'source' property, like you are trying to access, so the player variable is undefined
With world.getEntity() you could acquire the player, then access the runCommandAsync() method on that. But is there a need to subscribe to playerJoin to start with?
Would this not work perfectly fine on its own being independent? By looping over all players and doing runCommandAsync on each in turn
I attempted to, this was my last ditch effort to get this to work before I slept
Something like this:
system.runInterval(function() {
world.getAllPlayers().forEach(function applyNightVision(player) {
player.runCommandAsync("effect @s night_vision 99 99")
})
}, 40)
Although in this case there is an addEffect() method you could use:
player.addEffect('night_vision', 99, {amplifier: 99})
Heh, you're welcome
system.runInterval(()=>{
world.getAllPlayers().forEach(player=>player.addEffect('night_vision', 99, {amplifier: 99}))
})```
I like this one better
@night talon do this one instead^
This is identical to what I suggested though.
tick.json doesn't seem to work with the damage command as far as I can tell
I just need commands in general, not just effects
Oh i see, but usually you can do the same with the apis
yeah, and I probably will at some point, but my knowledge of commands far surpasses my knowledge of js with mcbe integration
What command/function did you use specifically? It seems arbitrary that some commands would work and others do not.
/damage, although I tested some others as well, they would work when I manually typed the function, they just wouldn’t in the tick.json
I get that, I moreso meant sharing your files specifically. To see if there were any typos, or if someone could reproduce it
I tested this in 1.20.80, so they may work now
I already changed them, sorry