#how would i store created warps in dynamic properties?
1 messages · Page 1 of 1 (latest)
You can try this
function updateLocations() {
world.setDynamicProperty("warpData", JSON.stringify(warploc));
}
const [cmd, ...args] = msg.split(" ");
if (cmd === ".warp") {
eventData.cancel = true;
if (args.length === 0) {
system.runTimeout(() => {
player.sendMessage("§7§o.warp <location_name>\n.warp create <name>\n.warp locations - Returns a message of all available warp locations.\n.warp remove <name>");
player.playSound("random.orb");
}, 0.1);
} else {
const subCmd = args[0];
if (subCmd === "create" && args.length > 1) {
const cwarpname = args.slice(1).join(" ");
const wlocation = {
x: player.location.x,
y: player.location.y,
z: player.location.z
};
system.runTimeout(() => {
player.sendMessage(`New warp "${cwarpname}" at ${wlocation.x.toFixed(0)}, ${wlocation.y.toFixed(0)}, ${wlocation.z.toFixed(0)}`);
player.playSound("mob.wither.break_block");
}, 0.1);
warploc[cwarpname] = wlocation;
updateLocations();
console.log(`New warp created: ${cwarpname}`);
} else if (subCmd === "locations") {
system.run(() => {
player.playSound("random.orb");
});
system.runTimeout(() => {
player.sendMessage(Object.keys(warploc).join(", "));
}, 0.1);
} else if (warploc.hasOwnProperty(subCmd)) {
system.run(() => {
player.teleport(warploc[subCmd]);
});
} else if (subCmd === "remove" && args.length > 1) {
const rwarpname = args.slice(1).join(" ");
if (warploc.hasOwnProperty(rwarpname)) {
delete warploc[rwarpname];
system.runTimeout(() => {
player.sendMessage(`§aWarp location "${rwarpname}" has been removed.`);
player.playSound("mob.wither.break_block");
}, 0.1);
updateLocations();
} else {
system.runTimeout(() => {
player.sendMessage(`Warp location "${rwarpname}" does not exist.`);
player.playSound("note.bass");
}, 0.1);
}
} else {
system.runTimeout(() => {
player.sendMessage("Invalid warp location.");
}, 0.1);
}
}
}```
Yea basically
Only when you need to access it
Also why do you run timeout or system run whenever you need to send a message to player or do something else?
This is a much cleaner version.
const [cmd, ...args] = msg.split(" ");
if (cmd === ".warp") {
eventData.cancel = true;
if (args.length === 0) {
player.sendMessage("§7§o.warp <location_name>\n.warp create <name>\n.warp locations - Returns a message of all available warp locations.\n.warp remove <name>");
player.playSound("random.orb");
} else {
const subCmd = args[0];
if (subCmd === "create" && args.length > 1) {
const cwarpname = args.slice(1).join(" ");
const wlocation = {
x: player.location.x,
y: player.location.y,
z: player.location.z
};
player.sendMessage(`New warp "${cwarpname}" at ${wlocation.x.toFixed(0)}, ${wlocation.y.toFixed(0)}, ${wlocation.z.toFixed(0)}`);
player.playSound("mob.wither.break_block");
let warploc = world.getDynamicProperty("warploc") || {};
warploc[cwarpname] = wlocation;
world.setDynamicProperty("warploc", warploc);
console.log(`New warp created: ${cwarpname}`);
} else if (subCmd === "locations") {
player.playSound("random.orb");
let warploc = world.getDynamicProperty("warploc") || {};
player.sendMessage(Object.keys(warploc).join(", "));
} else {
let warploc = world.getDynamicProperty("warploc") || {};
if (warploc.hasOwnProperty(subCmd)) {
player.teleport(warploc[subCmd]);
} else if (subCmd === "remove" && args.length > 1) {
const rwarpname = args.slice(1).join(" ");
if (warploc.hasOwnProperty(rwarpname)) {
delete warploc[rwarpname];
player.sendMessage(`§aWarp location "${rwarpname}" has been removed.`);
player.playSound("mob.wither.break_block");
world.setDynamicProperty("warploc", warploc);
} else {
player.sendMessage(`Warp location "${rwarpname}" does not exist.`);
player.playSound("note.bass");
}
} else {
player.sendMessage("Invalid warp location.");
}
}
}
}```
Ah understandable
Just saves some performance to not use system run or intervals whenever possible