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);
}
}```
#Script not working
1 messages · Page 1 of 1 (latest)
with the amount of comments, it looks like ai made it.
my friend gave it to me so proabs
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}`);
}
}
Debug result for [code](#1348478783669407795 message)
Compiler Result
Compiler found 1 errors:
[36m<REPL0>.js[0m:[33m11[0m:[33m36[0m - [31merror[0m[30m TS2551: [0mProperty 'currentTime' does not exist on type 'System'. Did you mean 'currentTick'?
[7m11[0m const currentTime = system.currentTime;
[7m [0m [31m ~~~~~~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m16417[0m:[33m14[0m
[7m16417[0m readonly currentTick: number;
[7m [0m [36m ~~~~~~~~~~~[0m
'currentTick' is declared here.
Lint Result
There are no errors from ESLint.
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}`);
}
}```
No Errors
No errors in [code](#1348478783669407795 message)
And it still doesn't work