Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Here is some code to get your started.
- // Edit your new script and click Update when done.
- // Learn more about scripts by clicking the ?-icon at the top.
- const exitId: String = "d22ns869gbrkc3bg3670";
- export function onActivate(): void {
- const roomBool: boolean = Room.listenExit(exitId);
- if (roomBool === false) {
- console.error(`Room ID "${exitId}" could not have been listened to.`)
- } else {
- // Store.deleteKey("dragonWhitelist");
- Room.addCommand("whitelistAdd", new Command("permit give <Char>", "Hands out a permit to go past the guards.")
- .field("Char", new Field.Char("The character to recieve a permit.")));
- Room.addCommand("whitelistRemove", new Command("permit take <Char>", "Remove the permit.")
- .field("Char", new Field.Char("The character to take the permit from.")));
- Room.listenCharEvent();
- }
- if (Store.getString("dragonWhitelist") === null) {
- const a: String[] = [];
- Store.setString("dragonWhitelist", JSON.stringify(a));
- } else {
- console.log(Store.getString("dragonWhitelist") as String);
- }
- if (Store.getString("adminCount") === null) {
- const b: number = parseInt("0",10);
- Store.setString("adminCount", b.toString());
- }
- }
- // Prevent anyone not on the whitelist from using the guarded passage.
- export function onExitUse(
- addr: string, // Address of this script instance receiving the event.
- exitAction: ExitAction, // Exit action object.
- ): void {
- const wString = Store.getString("dragonWhitelist") as String;
- const dragonWhitelist = JSON.parse<String[]>(wString);
- if (dragonWhitelist.includes(exitAction.charId)) {
- exitAction.useExit();
- } else {
- exitAction.useExit("d22ol169gbrkc3bg469g");
- }
- }
- @json
- class sendArgs {
- @alias("Char") // Name of the field
- character: FieldValue.Char = new FieldValue.Char();
- }
- export function onCommand(
- addr: string, // Address of this script instance receiving the action.
- cmdAction: CmdAction, // Command action object.
- ): void {
- if (!Room.canEdit(cmdAction.char.id)) {
- cmdAction.error("You are not allowed to use this command!");
- return;
- }
- const wString = Store.getString("dragonWhitelist") as String;
- const dragonWhitelist = JSON.parse<String[]>(wString);
- switch (cmdAction.keyword) {
- case "whitelistAdd":
- const data = JSON.parse<sendArgs>(cmdAction.data);
- console.log(cmdAction.char.id + " " + cmdAction.data);
- if (dragonWhitelist.includes(data.character.id)) {
- cmdAction.error(`${data.character.name} ${data.character.surname} \(${data.character.id}\) is already whitelisted.`);
- } else {
- dragonWhitelist.push(data.character.id);
- Store.setString("dragonWhitelist", JSON.stringify(dragonWhitelist));
- cmdAction.info(`${data.character.name} ${data.character.surname} \(${data.character.id}\) has been added to the whitelist.`)
- }
- break;
- case "whitelistRemove":
- const data = JSON.parse<sendArgs>(cmdAction.data);
- const index = dragonWhitelist.indexOf(data.character.id);
- if (index > -1) {
- dragonWhitelist.splice(index, 1);
- Store.setString("dragonWhitelist", JSON.stringify(dragonWhitelist));
- cmdAction.info(`${data.character.name} ${data.character.surname} \(${data.character.id}\) has been removed from the whitelist.`);
- } else {
- cmdAction.error(`${data.character.name} ${data.character.surname} \(${data.character.id}\) isn't on the whitelist.`);
- }
- break;
- default:
- cmdAction.error("Unkown command");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment