#How do i make a tick delay between running commands in a script

1 messages · Page 1 of 1 (latest)

sturdy jetty
#
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')
        }
    });```
#

trying to remove the tag incombat after a few seconds

warped latch
#

Use runTimeout

sturdy jetty
#

how?

warped latch
#
system.runTimeout(() => {
  source.removeTag("incombat")
}, 60 /* 3 sec */);
sturdy jetty
#

and put that after the target in tag

warped latch
#

Also, why you need system.runInterval then run an event? What?

warped latch
#

Why you subscribe an event every tick, that's make the game laggy

pallid jacinth
sturdy jetty
#

i have it bc i skipped the lines that are irrelevent to the situation

warped latch
#

That makes the event run infinite time

#

Just run the event once

pallid jacinth
#

I hadn't read his code

warped latch
#
     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')
        }
    });```
sturdy jetty
#

yo ty

warped latch
#

Done, you doesn't need runInterval

sturdy jetty
#

yes i do

warped latch
#

Why?

warped latch
#

The event will always run everytime any entity get hit, using the runInterval will run the event SOOO many times

sturdy jetty
#

bro are u reading the msg

#

wait now how do i get the time to display it

warped latch
#

Just add if statement there and return it

pallid jacinth
sturdy jetty
warped latch
#

Likely you didn't understand how event works

sturdy jetty
#

bro im not woried abt that

#

i have other code that needs it

#

ok?

warped latch
#

That can make your player has 1000 tags

#

Your function command run 1000 times or more

sturdy jetty
#

brooooooo

pallid jacinth
sturdy jetty
#

can u pay attention

warped latch
#

Fine, it's up to you

#

I'm just saying that you doesn't need runInterval to run an event

sturdy jetty
#

thats the full code

#

ok?

warped latch
#

Oh, i thought the event on the runInterval, mb

#

Sorry for that

sturdy jetty
#

i was telling u

#

the whole time

#

how is the time gonna help

#

its time of day

warped latch
sturdy jetty
#

like the ticks

drifting rapids
#

sleep function perhaps