#when i add effects to the player it doesn't work
1 messages · Page 1 of 1 (latest)
the duration is in ticks, not seconds
[Scripting][error]-ReferenceError: Native function [Entity::addEffect] does not have required privileges. at <anonymous> (interact_items/sword fighter.js:8)
this is the error
you need to use system.run to take it out of the readonly state
?
do:
console.warn('')
import { world, system } from "@minecraft/server"
world.beforeEvents.itemUse.subscribe(data => {
let player = data.source
const Cooldown = world.scoreboard.getObjective("Cooldown")
if (data.itemStack.typeId == "anlos_rpg:sword" && player.getTags().includes('fighter') && Cooldown.getScore(player) == 0) {
system.run(() => {
player.addEffect('strength', 10, 5)
}
}
})
btw thats why you need to use system.run??
the third argument to addEffect is wrong
console.warn('')
import { world, system } from "@minecraft/server"
world.beforeEvents.itemUse.subscribe(data => {
let player = data.source
const Cooldown = world.scoreboard.getObjective("Cooldown")
if (data.itemStack.typeId == "anlos_rpg:sword" && player.getTags().includes('fighter') && Cooldown.getScore(player) == 0) {
system.run(() => {
player.addEffect('strength', 200, 5)
})
}
}
)
5 -> { amplifier: 5 }
can you give an example to what i should look like
if you're in a before event, the execution gets set to a readonly state, so anything that changes the world can't be done. You use system.run to queue your function to run at the end of the tick when it's safe to do so
i have this error [Scripting][error]-TypeError: Native optional type conversion failed. Function argument [2] expected type: EntityEffectOptions | undefined at <anonymous> (interact_items/sword fighter.js:9)
player.addEffect('strength', 200, 5) -> player.addEffect('strength', 200, { amplifier: 5 })
then just decrease it by one
it worked