system.runInterval(() => {
for (const player of world.getAllPlayers()) {
world.events.entityHurt.subscribe(async (events) => {
var source = events.damageSource.damagingEntity;
var target = events.hurtEntity;
await source.runCommandAsync('function hitting');
await target.runCommandAsync('function gotHit');
if (source.typeId === "minecraft:player") {
const viewDir = source.getViewDirection();
target.applyKnockback(viewDir.x, viewDir.z, .005, 0.35);
target.addEffect(MinecraftEffectTypes.slowFalling, 5, 0, false)
target.addEffect(MinecraftEffectTypes.levitation, 2, 0, false)
target.addTag('incombat')
}
});```
#How do i make a tick delay between running commands in a script
1 messages · Page 1 of 1 (latest)
Use runTimeout
how?
system.runTimeout(() => {
source.removeTag("incombat")
}, 60 /* 3 sec */);
and put that after the target in tag
Also, why you need system.runInterval then run an event? What?
Yes
Why you subscribe an event every tick, that's make the game laggy
takes advantage and places a condition to remove the tag
i have it bc i skipped the lines that are irrelevent to the situation
I hadn't read his code
world.events.entityHurt.subscribe(async (events) => {
var source = events.damageSource.damagingEntity;
var target = events.hurtEntity;
await source.runCommandAsync('function hitting');
await target.runCommandAsync('function gotHit');
if (source.typeId === "minecraft:player") {
const viewDir = source.getViewDirection();
target.applyKnockback(viewDir.x, viewDir.z, .005, 0.35);
target.addEffect(MinecraftEffectTypes.slowFalling, 5, 0, false)
target.addEffect(MinecraftEffectTypes.levitation, 2, 0, false)
target.addTag('incombat')
}
});```
yo ty
Done, you doesn't need runInterval
yes i do
Why?
look
The event will always run everytime any entity get hit, using the runInterval will run the event SOOO many times
Just add if statement there and return it
This way it is much better and still reduces the lag
wait now how do i get the time to display it?
Ik, but subscribe event every tick and every player will overflow the game and cause the server/world shutdown because of Watchdog
Likely you didn't understand how event works
That can make your player has 1000 tags
Your function command run 1000 times or more
brooooooo
Speaking of which, do you know what the tag limit is?
can u pay attention
Fine, it's up to you
I'm just saying that you doesn't need runInterval to run an event
What time?
like the ticks
of the this
sleep function perhaps