Guest User

Untitled

a guest
Jul 27th, 2025
13
0
330 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Here is some code to get your started.
  2. // Edit your new script and click Update when done.
  3.  
  4. // Learn more about scripts by clicking the ?-icon at the top.
  5. const exitId: String = "d22ns869gbrkc3bg3670";
  6.  
  7. export function onActivate(): void {
  8.     const roomBool: boolean = Room.listenExit(exitId);
  9.     if (roomBool === false) {
  10.         console.error(`Room ID "${exitId}" could not have been listened to.`)
  11.     } else {
  12.         // Store.deleteKey("dragonWhitelist");
  13.         Room.addCommand("whitelistAdd", new Command("permit give <Char>", "Hands out a permit to go past the guards.")
  14.                         .field("Char", new Field.Char("The character to recieve a permit.")));
  15.         Room.addCommand("whitelistRemove", new Command("permit take <Char>", "Remove the permit.")
  16.                         .field("Char", new Field.Char("The character to take the permit from.")));
  17.         Room.listenCharEvent();
  18.     }
  19.     if (Store.getString("dragonWhitelist") === null) {
  20.         const a: String[] = [];
  21.         Store.setString("dragonWhitelist", JSON.stringify(a));
  22.     } else {
  23.         console.log(Store.getString("dragonWhitelist") as String);
  24.     }
  25.     if (Store.getString("adminCount") === null) {
  26.         const b: number = parseInt("0",10);
  27.         Store.setString("adminCount", b.toString());
  28.     }
  29. }
  30.  
  31. // Prevent anyone not on the whitelist from using the guarded passage.
  32. export function onExitUse(
  33.     addr: string,           // Address of this script instance receiving the event.
  34.     exitAction: ExitAction, // Exit action object.
  35. ): void {
  36.     const wString = Store.getString("dragonWhitelist") as String;
  37.     const dragonWhitelist = JSON.parse<String[]>(wString);
  38.     if (dragonWhitelist.includes(exitAction.charId)) {
  39.         exitAction.useExit();
  40.     } else {
  41.         exitAction.useExit("d22ol169gbrkc3bg469g");
  42.     }
  43. }
  44.  
  45. @json
  46. class sendArgs {
  47.     @alias("Char") // Name of the field
  48.     character: FieldValue.Char = new FieldValue.Char();
  49. }
  50.  
  51. export function onCommand(
  52.     addr: string,         // Address of this script instance receiving the action.
  53.     cmdAction: CmdAction, // Command action object.
  54. ): void {
  55.     if (!Room.canEdit(cmdAction.char.id)) {
  56.         cmdAction.error("You are not allowed to use this command!");
  57.         return;
  58.     }
  59.     const wString = Store.getString("dragonWhitelist") as String;
  60.     const dragonWhitelist = JSON.parse<String[]>(wString);
  61.     switch (cmdAction.keyword) {
  62.         case "whitelistAdd":
  63.             const data = JSON.parse<sendArgs>(cmdAction.data);
  64.             console.log(cmdAction.char.id + " " + cmdAction.data);
  65.             if (dragonWhitelist.includes(data.character.id)) {
  66.                 cmdAction.error(`${data.character.name} ${data.character.surname} \(${data.character.id}\) is already whitelisted.`);
  67.             } else {
  68.                 dragonWhitelist.push(data.character.id);
  69.                 Store.setString("dragonWhitelist", JSON.stringify(dragonWhitelist));
  70.                 cmdAction.info(`${data.character.name} ${data.character.surname} \(${data.character.id}\) has been added to the whitelist.`)
  71.             }
  72.             break;
  73.         case "whitelistRemove":
  74.             const data = JSON.parse<sendArgs>(cmdAction.data);
  75.             const index = dragonWhitelist.indexOf(data.character.id);
  76.             if (index > -1) {
  77.                 dragonWhitelist.splice(index, 1);
  78.                 Store.setString("dragonWhitelist", JSON.stringify(dragonWhitelist));
  79.                 cmdAction.info(`${data.character.name} ${data.character.surname} \(${data.character.id}\) has been removed from the whitelist.`);
  80.             } else {
  81.                 cmdAction.error(`${data.character.name} ${data.character.surname} \(${data.character.id}\) isn't on the whitelist.`);
  82.             }
  83.             break;
  84.         default:
  85.             cmdAction.error("Unkown command");
  86.             break;
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment