From f22fa3c40aa89d39746a3e8bbdd9d9e70c5075ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fan=20AYDIN?= <79187578+Phoenix-rat@users.noreply.github.com> Date: Mon, 27 Jan 2025 23:11:52 +0300 Subject: [PATCH] + Super Duper Broadcast (#36) * + Super Duper Broadcast * Update sdb.ts ESLint Update --- src/command/cmds/sdb.ts | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/command/cmds/sdb.ts diff --git a/src/command/cmds/sdb.ts b/src/command/cmds/sdb.ts new file mode 100644 index 0000000..bb92966 --- /dev/null +++ b/src/command/cmds/sdb.ts @@ -0,0 +1,75 @@ +import { Command } from "../Command"; +import { Base } from "../../core/Base"; +import { Peer } from "../../core/Peer"; +import { ROLE } from "../../Constants"; +import { Variant, TextPacket, PacketTypes } from "growtopia.js"; +import { DialogBuilder } from "../../utils/builders/DialogBuilder"; + +export default class Sdb extends Command { + constructor( + public base: Base, + public peer: Peer, + public text: string, + public args: string[] + ) { + super(base, peer, text, args); + this.opt = { + command: ["sdb"], + description: "Send a global message to everyone via a dialog box", + cooldown: 5, + ratelimit: 1, + category: "`bDev", + usage: "/sdb ", + example: ["/sdb Hello everyone!"], + permission: [ROLE.DEVELOPER] + }; + } + + public async execute(): Promise { + if (!this.args.length) + return this.peer.send(Variant.from("Message is required.")); + + const message = this.args.join(" "); + const senderName = this.peer.name; + const world = this.peer.currentWorld(); + const jammed = world?.data.jammers?.find((v) => v.type === "signal")?.enabled; + + // Dialog box creation + const dialog = new DialogBuilder() + .defaultColor() + .addLabelWithIcon("Super Duper Broadcast", "2480", "big") + .addSpacer("small") + .addSmallText(`\`oMessage from: \`$${senderName}`); + + // If no jammer, show the world name + if (!jammed) { + dialog.addSmallText(`\`oWorld: \`o${this.peer.data.world}`); + } else { + dialog.addSmallText("`4JAMMED`"); + } + + dialog + .addSpacer("small") + .addSmallText(`\`5${message}`) + .addQuickExit() + .endDialog("ok", "Close", ""); + + // Send dialog box and play beep sound to all players + this.peer.every((player) => { + player.send( + Variant.from("OnDialogRequest", dialog.str()), + TextPacket.from( + PacketTypes.ACTION, + "action|play_sfx", + `file|audio/beep.wav`, + `delayMS|0` + ) + ); + }); + + // Confirmation to sender + this.peer.send( + Variant.from("OnConsoleMessage", `\`2Super Duper Broadcast sent to all players.`) + ); + } +}