#Script not working

1 messages · Page 1 of 1 (latest)

rain quartz
#
import { system, world } from "@minecraft/server";

const isSneaking = new Map();

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        const playerId = player.id;
        const sneakingNow = player.isSneaking;  // Check if player is sneaking

        if (sneakingNow && !isSneaking.get(playerId)) {
            handleSneak(player);  // Trigger lightning effect
        }

        isSneaking.set(playerId, sneakingNow);
    }
}, 1);

function handleSneak(player) {
    if (player.hasTag("lightning")) {
        createLightningEffect(player);  // Trigger the lightning effect
    }
}

// Function to create the lightning effect
function createLightningEffect(player) {
    let position = player.location;
    let direction = player.getViewDirection(); // Get the direction the player is facing

    // Spawn multiple particles to simulate lightning
    for (let i = 0; i < 8; i++) { // 8 particles for the effect
        let offsetX = (Math.random() - 0.5) * 2; // Horizontal random spread
        let offsetY = (Math.random() - 0.2) * 1.5; // Vertical variation for effect
        let offsetZ = (Math.random() - 0.5) * 2; // Horizontal random spread

        // Calculate the final particle position
        let particleLocation = {
            x: position.x + direction.x * 2 + offsetX, // Position in front of the player
            y: position.y + 1 + direction.y * 2 + offsetY, // Vertical height offset
            z: position.z + direction.z * 2 + offsetZ // Position in front of the player
        };

        // Spawn the "spell" particle to simulate a lightning-like effect
        player.dimension.spawnParticle("minecraft:spell", particleLocation);
    }
}```
#

This script doesn't seem to be working at all

velvet flare
#

with the amount of comments, it looks like ai made it.

rain quartz
#

my friend gave it to me so proabs

velvet flare
#
import { system, world } from "@minecraft/server";

const isSneaking = new Map();
const LIGHTNING_COOLDOWN = 1000; // 1 second
const lastLightningTime = new Map();

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        const playerId = player.id;
        const sneakingNow = player.isSneaking;
        const currentTime = system.currentTime;
        const canTriggerLightning = 
            !lastLightningTime.has(playerId) || 
            (currentTime - (lastLightningTime.get(playerId) || 0) > LIGHTNING_COOLDOWN);

        if (sneakingNow && !isSneaking.get(playerId) && canTriggerLightning) {
            handleSneak(player);
            lastLightningTime.set(playerId, currentTime);
        }

        isSneaking.set(playerId, sneakingNow);
    }
}, 10);

function handleSneak(player) {
    if (player.hasTag("lightning")) {
        createLightningEffect(player);
    }
}

function createLightningEffect(player) {
    try {
        const position = player.location;
        const direction = player.getViewDirection();

        for (let i = 0; i < 8; i++) {
            const offsetX = (Math.random() - 0.5) * 2;
            const offsetY = (Math.random() - 0.2) * 1.5;
            const offsetZ = (Math.random() - 0.5) * 2;

            const particleLocation = {
                x: position.x + direction.x * 2 + offsetX,
                y: position.y + 1 + direction.y * 2 + offsetY,
                z: position.z + direction.z * 2 + offsetZ
            };

            player.dimension.spawnParticle("minecraft:spell", particleLocation);
        }
    } catch (error) {
        console.error(`Lightning effect error: ${error}`);
    }
}
frank vortexBOT
# velvet flare ```js import { system, world } from "@minecraft/server"; const isSneaking = new...

Debug result for [code](#1348478783669407795 message)

Compiler Result

Compiler found 1 errors:

<REPL0>.js:11:36 - error TS2551: Property 'currentTime' does not exist on type 'System'. Did you mean 'currentTick'?

11         const currentTime = system.currentTime;
                                      ~~~~~~~~~~~

  @minecraft/server.d.ts:16417:14
    16417     readonly currentTick: number;
                       ~~~~~~~~~~~
    'currentTick' is declared here.

Lint Result

There are no errors from ESLint.

rain quartz
#
import { system, world } from "@minecraft/server";

const isSneaking = new Map();
const LIGHTNING_COOLDOWN = 20;
const lastLightningTime = new Map();

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        const playerId = player.id;
        const sneakingNow = player.isSneaking;
        const currentTick = system.currentTick;
        const canTriggerLightning = 
            !lastLightningTime.has(playerId) || 
            (currentTick - (lastLightningTime.get(playerId) || 0) > LIGHTNING_COOLDOWN);

        if (sneakingNow && !isSneaking.get(playerId) && canTriggerLightning) {
            handleSneak(player);
            lastLightningTime.set(playerId, currentTick);
        }

        isSneaking.set(playerId, sneakingNow);
    }
}, 1);

function handleSneak(player) {
    if (player.hasTag("lightning")) {
        createLightningEffect(player);
    }
}

function createLightningEffect(player) {
    try {
        const position = player.location;
        const direction = player.getViewDirection();

        for (let i = 0; i < 8; i++) {
            const offsetX = (Math.random() - 0.5) * 2;
            const offsetY = (Math.random() - 0.2) * 1.5;
            const offsetZ = (Math.random() - 0.5) * 2;

            const particleLocation = {
                x: position.x + direction.x * 2 + offsetX,
                y: position.y + 1 + direction.y * 2 + offsetY,
                z: position.z + direction.z * 2 + offsetZ
            };

            player.dimension.spawnParticle("minecraft:electric_spark", particleLocation);
        }
    } catch (error) {
        console.error(`Lightning effect error: ${error}`);
    }
}```
frank vortexBOT
rain quartz
#

And it still doesn't work