iMagicBae

Gani Staff Companion v2

Jul 5th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   // Scripted by iMagic
  2. /*
  3. ==============================================================================
  4.   This is the Gani Staff Companion Tool V.2. Meant to make the job of the gani
  5.   team a little bit easier.
  6.  
  7.   In this version you can:
  8.  
  9.   - Replace your Idle and Walk animations.
  10.  
  11.   - Play sound files as well as search for soundfiles stored on the server.
  12.  
  13.   - Store notes.
  14.  
  15.   - Find .png images on the server
  16.  
  17.   - Spawn temp.npcs that mimic a speficic image.
  18. ==============================================================================
  19. */
  20.  
  21. function onCreated() {
  22.     // Folder in which you want the note files to be stored (they are .txt files).
  23.   this.notes_path = "levels/users/Graal2007722/logs/";
  24.   setShape(1, 32, 32);
  25. }
  26.  
  27.   // Send the respective note file to the respective client whenever they open the GUI.
  28. function onActionLoadNote(owner) {
  29.   temp.lines = {};
  30.   temp.notepath = getNotePath(temp.owner);
  31.     // Check if they had a note file. If not. create one.
  32.   if (!(fileExists(temp.notepath))) {
  33.     temp.newfile = {
  34.       "I noticed you didnt have a note file",
  35.       "So I created one for you :D",
  36.       "Welcome to your notes!",
  37.       "",
  38.       "Dont forget to save your notes before",
  39.       "closing the Tool!",
  40.     };
  41.     temp.newfile.savelines(temp.notepath, 0);
  42.   }
  43.   temp.lines.loadlines(temp.notepath);
  44.  
  45.     // Send them the note file.
  46.   triggerAction(this.x, this.y, "RecieveNote", temp.owner, {temp.lines});
  47. }
  48.  
  49.   // Save the note server-side to the proper owner's txt file.
  50. function onActionSaveNote(owner, note) {
  51.   temp.notepath = getNotePath(temp.owner);
  52.   temp.lines = temp.note;
  53.   temp.newlines = {};
  54.  
  55.   for (temp.i = 0; temp.i < temp.lines.size(); temp.i++) {
  56.     temp.newlines.add(temp.lines[temp.i]);
  57.   }
  58.  
  59.     // Doesnt overwrite the previus note. Deletes whatever there was before and add what's currently on the note.
  60.   temp.newlines.savelines(temp.notepath, 0);
  61. }
  62.  
  63.   // Send an array of found files.
  64. function onActionGetFiles(query, format, playerID) {
  65.   temp.file_to_get = temp.query;
  66.   temp.raw_file_list = findfiles("*" @ temp.file_to_get @ temp.format, 1);
  67.  
  68.   temp.files = {};
  69.   for (temp.i = 0; temp.i < temp.raw_file_list.size(); temp.i++) {
  70.     temp.token = temp.raw_file_list[temp.i].tokenize("/");
  71.     temp.files.add(temp.token[temp.token.size() - 1]);
  72.   }
  73.   triggerAction(this.x, this.y, "RecieveFiles", temp.format, {temp.files}, temp.playerID);
  74. }
  75.  
  76.   // Generates a notepath given the user. Each user has their own note .txt file.
  77. function getNotePath(playerID) {
  78.   temp.suffix = format("%s_companionnote.txt", temp.playerID);
  79.     // Appends the custom filename to the custom folder in which to store the note.
  80.   temp.path = this.notes_path @ temp.suffix;
  81.   return temp.path;
  82. }
  83.  
  84.   // Place the NPC server-side for other staff to see.
  85. function onActionPlaceNPC(image, x, y) {
  86.   temp.obj = putnpc2(temp.x, temp.y, NULL);
  87.   temp.obj.image = temp.image;
  88. }
  89.  
  90.   // Destroys the NPCs on the level which arent hooked up to a class.
  91. function onActionDestroyNPCS() {
  92.   for (temp.npc : this.level.npcs) {
  93.     if (temp.npc.joinedclasses == NULL) {
  94.       temp.npc.destroy();
  95.     }
  96.   }
  97. }
  98.  
  99. //#CLIENTSIDE
  100. function onCreated() {
  101.   this.chat = "Gani Staff Companion";
  102.     // Commands with which you can launch the tool.
  103.   this.aliases = {
  104.     ":companion", "test", ":GSC"
  105.   };
  106.   setShape(1, 32, 32);
  107.  
  108.     // The server's default walk and idle.
  109.     // This is what the reset button sets the walk and idle back to.
  110.   this.default_walk = "ol_walk";
  111.   this.default_idle = "ol_idle";
  112. }
  113.  
  114. /*
  115.   Using onMouseDown("left") here instead of onActionLeftMouse() because Carlito said
  116.   that for the latter, the NPC has to actually be clicked, so if anything else is on top
  117.   of the NPC it wont trigger it.
  118. */
  119. function onMouseDown(mouse) {
  120.   switch (temp.mouse) {
  121.     case "left":
  122.     if (mousex in |this.x, this.x + 2| && mousey in |this.y, this.y + 2|) {
  123.       if (player.chat in this.aliases) {
  124.         if (isObject("Win1_Companion")) {
  125.          onDestroyGui();
  126.         }
  127.         onDrawGui();
  128.       }
  129.     }
  130.     break;
  131.   }
  132. }
  133.  
  134. function onDrawGui() {
  135.   new GuiWindowCtrl("Win1_Companion") {
  136.     profile = GuiBlueWindowProfile;
  137.     width = 230;
  138.     height = 170;
  139.     useownprofile = true;
  140.     x = (screenwidth / 2) * 0.8;
  141.     y = ((screenheight / 2) - height) * 0.37;
  142.     canminimize = canmaximize = canresize = false;
  143.     canclose = canmove = closequery = true;
  144.     text = "Gani Staff Companion V.2";
  145.  
  146.     new GuiMLTextCtrl("Text_ReplaceAni") {
  147.       x = 10;
  148.       y = 27;
  149.       height = 135;
  150.       width = 150;
  151.       useownprofile = true;
  152.       profile.modal = false;
  153.     }
  154.  
  155.     new GuiMLTextCtrl("Text_Walk") {
  156.       x = Text_ReplaceAni.x;
  157.       y = Text_ReplaceAni.y + 20;
  158.       height = 135;
  159.       width = 380;
  160.       useownprofile = true;
  161.       profile.modal = false;
  162.     }
  163.  
  164.     new GuiMLTextCtrl("Text_Idle") {
  165.       x = Text_ReplaceAni.x;
  166.       y = Text_ReplaceAni.y + 65;
  167.       height = 135;
  168.       width = 380;
  169.       useownprofile = true;
  170.       profile.modal = false;
  171.     }
  172.  
  173.     new GuiTextEditCtrl("Input_Walk") {
  174.       profile = GuiBlueTextEditProfile;
  175.       x = Text_Walk.x;
  176.       y = Text_Walk.y + 20;
  177.       width = 180;
  178.       height = 20;
  179.       text = "";
  180.       hint = "Replaces your walk animation with another gani.";
  181.     }
  182.  
  183.     new GuiTextEditCtrl("Input_Idle") {
  184.       profile = GuiBlueTextEditProfile;
  185.       x = Text_Idle.x;
  186.       y = Text_Idle.y + 20;
  187.       width = Input_Walk.width;
  188.       height = Input_Walk.height;
  189.       text = "";
  190.       hint = "Replaces your idle animation with another gani.";
  191.     }
  192.  
  193.     new GuiButtonCtrl("Button_ReplaceAniApply") {
  194.       profile = GuiBlueButtonProfile;
  195.       width = 60;
  196.       height = 20;
  197.       x = 10;
  198.       y = Win1_Companion.height - height - 10;
  199.       text = "Apply";
  200.     }
  201.     new GuiButtonCtrl("Button_ReplaceAniReset") {
  202.       profile = GuiBlueButtonProfile;
  203.       width = 60;
  204.       height = 20;
  205.       x = Button_ReplaceAniApply.x + Button_ReplaceAniApply.width + 5;
  206.       y = Win1_Companion.height - height - 10;
  207.       text = "Reset";
  208.       hint = "Set your animations back to the server's default walk and idle";
  209.     }
  210.   }
  211.     // Sounds Window.
  212.   new GuiWindowCtrl("Win2_Companion") {
  213.     profile = GuiBlueWindowProfile;
  214.     x = Win1_Companion.x + Win1_Companion.width;
  215.     y = Win1_Companion.y;
  216.     width = 300;
  217.     height = 250;
  218.     useownprofile = true;
  219.     canminimize = canmaximize = canresize = canmove = canclose = false;
  220.  
  221.     new GuiMLTextCtrl("Text_Sounds") {
  222.       x = 10;
  223.       y = 27;
  224.       height = 135;
  225.       width = 380;
  226.       useownprofile = true;
  227.       profile.modal = false;
  228.     }
  229.  
  230.     new GuiMLTextCtrl("Text_PlaySound") {
  231.       x = Text_Sounds.x;
  232.       y = Text_Sounds.y + 20;
  233.       height = 135;
  234.       width = 380;
  235.       useownprofile = true;
  236.       profile.modal = false;
  237.     }
  238.  
  239.     new GuiTextEditCtrl("Input_PlaySound") {
  240.       profile = GuiBlueTextEditProfile;
  241.       x = Text_PlaySound.x;
  242.       y = Text_PlaySound.y + 20;
  243.       width = 175;
  244.       height = 20;
  245.       text = "";
  246.       hint = "Plays a sound file.";
  247.     }
  248.  
  249.     new GuiButtonCtrl("Button_PlaySound") {
  250.       profile = GuiBlueButtonProfile;
  251.       width = 40;
  252.       height = 20;
  253.       x = Input_PlaySound.x + Input_PlaySound.width + 5;
  254.       y = Input_PlaySound.y;
  255.       text = "Play";
  256.     }
  257.  
  258.     new GuiButtonCtrl("Button_ClearSound") {
  259.       profile = GuiBlueButtonProfile;
  260.       width = 40;
  261.       height = 20;
  262.       x = Button_PlaySound.x + Button_PlaySound.width + 5;
  263.       y = Button_PlaySound.y;
  264.       text = "Clear";
  265.     }
  266.  
  267.     new GuiMLTextCtrl("Text_FindSound") {
  268.       x = Input_PlaySound.x;
  269.       y = Input_PlaySound.y + 25;
  270.       height = 135;
  271.       width = 380;
  272.       useownprofile = true;
  273.       profile.modal = false;
  274.     }
  275.  
  276.     new GuiTextEditCtrl("Input_FindSound") {
  277.       profile = GuiBlueTextEditProfile;
  278.       x = Text_FindSound.x;
  279.       y = Text_FindSound.y + 20;
  280.       width = Input_PlaySound.width;
  281.       height = 20;
  282.       text = "";
  283.       hint = "Finds .wav files on the server";
  284.     }
  285.  
  286.     new GuiButtonCtrl("Button_FindSound") {
  287.       profile = GuiBlueButtonProfile;
  288.       width = 40;
  289.       height = 20;
  290.       x = Input_FindSound.x + Input_FindSound.width + 5;
  291.       y = Input_FindSound.y;
  292.       text = "Find";
  293.     }
  294.  
  295.     new GuiScrollCtrl("Scroll_FoundSounds") {
  296.       profile = GuiBlueScrollProfile;
  297.       x = Input_FindSound.x;
  298.       y = Input_FindSound.y + Input_FindSound.height + 10;
  299.       width = Win2_Companion.width - 30;
  300.       height = 100;
  301.       hScrollBar = "dynamic";
  302.       vScrollBar = "dynamic";
  303.  
  304.       new GuiTextListCtrl("List_FoundSounds") {
  305.         profile = GuiBlueTextListProfile;
  306.         x = y = 0;
  307.         width = Scroll_FoundSounds.width;
  308.         fitparentwidth = false;
  309.       }
  310.     }
  311.   }
  312.     // Notes window.
  313.   new GuiWindowCtrl("Win3_Companion") {
  314.     profile = GuiBlueWindowProfile;
  315.     x = Win2_Companion.x + Win2_Companion.width;
  316.     y = Win2_Companion.y;
  317.     width = 280;
  318.     height = 525;
  319.     useownprofile = true;
  320.     canminimize = canmaximize = canresize = canmove = canclose = false;
  321.  
  322.     new GuiMLTextCtrl("Text_Notes") {
  323.       x = 10;
  324.       y = 27;
  325.       height = 135;
  326.       width = 380;
  327.       useownprofile = true;
  328.       profile.modal = false;
  329.     }
  330.  
  331.     new GuiScrollCtrl("Scroll_NotesWindow") {
  332.       profile = GuiBlueScrollProfile;
  333.       scrollprofile = GuiBlueScrollProfile;
  334.       x = Text_Notes.x;
  335.       y = Text_Notes.y + 20;
  336.       width = Win3_Companion.width - 20;
  337.       height = Win3_Companion.height - 80;
  338.       useownprofile = true;
  339.       profile.fillColor = "51 93 176";
  340.       profile.opaque = true;
  341.       profile.border = 1;
  342.       profile.bitmap = "guiblue_scroll_noback.png";
  343.       horizsizing = "width";
  344.       vertsizing  = "height";
  345.  
  346.       new GuiMLTextEditCtrl("Text_NotesWindow") {
  347.         profile = SyntaxHighlightProfile;
  348.         x = 0;
  349.         y = 0;
  350.         width = Scroll_NotesWindow.width;
  351.         height = Scroll_Notes.height;
  352.         useownprofile = true;
  353.  
  354.         profile.fillcolorhl = "51 107 176"; // Background color
  355.         profile.fontcolor = "255 255 255";
  356.         profile.fontsize = 13.5;
  357.         horizsizing = "width";
  358.         wordwrap = false;
  359.       }
  360.     }
  361.  
  362.     new GuiButtonCtrl("Button_SaveNote") {
  363.       profile = GuiBlueButtonProfile;
  364.       width = 80;
  365.       height = 20;
  366.       x = Scroll_NotesWindow.x + Scroll_NotesWindow.width - width;
  367.       y = Scroll_NotesWindow.y + Scroll_NotesWindow.height + 5;
  368.       text = "Save Note";
  369.     }
  370.   }
  371.     // Img NPC spawner Window
  372.   new GuiWindowCtrl("Win4_Companion") {
  373.     profile = GuiBlueWindowProfile;
  374.     x = Win2_Companion.x;
  375.     y = Win2_Companion.y + Win2_Companion.height;
  376.     width = Win2_Companion.width;
  377.     height = 275;
  378.     useownprofile = true;
  379.     canminimize = canmaximize = canresize = canmove = canclose = false;
  380.  
  381.     new GuiMLTextCtrl("Text_Images") {
  382.       x = 10;
  383.       y = 27;
  384.       height = 135;
  385.       width = 380;
  386.       useownprofile = true;
  387.       profile.modal = false;
  388.     }
  389.  
  390.     new GuiMLTextCtrl("Text_ImageFile") {
  391.       x = Text_Sounds.x;
  392.       y = Text_Sounds.y + 20;
  393.       height = 135;
  394.       width = 380;
  395.       useownprofile = true;
  396.       profile.modal = false;
  397.     }
  398.  
  399.     new GuiTextEditCtrl("Input_ImageFile") {
  400.       profile = GuiBlueTextEditProfile;
  401.       x = Text_ImageFile.x;
  402.       y = Text_ImageFile.y + 20;
  403.       width = 210;
  404.       height = 20;
  405.       text = "";
  406.       hint = "Places an image file on the level at the given coordinates.";
  407.     }
  408.  
  409.     new GuiMLTextCtrl("Text_ImageFileX") {
  410.       x = Input_ImageFile.x;
  411.       y = Input_ImageFile.y + 25;
  412.       height = 135;
  413.       width = 380;
  414.       useownprofile = true;
  415.       profile.modal = false;
  416.     }
  417.  
  418.     new GuiTextEditCtrl("Input_ImageFileX") {
  419.       profile = GuiBlueTextEditProfile;
  420.       x = Text_ImageFileX.x + 15;
  421.       y = Text_ImageFileX.y - 3;
  422.       width = 45;
  423.       height = 20;
  424.       text = "";
  425.       hint = "X coordinate to spawn the image file at.";
  426.     }
  427.  
  428.     new GuiMLTextCtrl("Text_ImageFileY") {
  429.       x = Input_ImageFileX.x + Input_ImageFileX.width + 5;
  430.       y = Input_ImageFile.y + 25;
  431.       height = 135;
  432.       width = 380;
  433.       useownprofile = true;
  434.       profile.modal = false;
  435.     }
  436.  
  437.     new GuiTextEditCtrl("Input_ImageFileY") {
  438.       profile = GuiBlueTextEditProfile;
  439.       x = Text_ImageFileY.x + 15;
  440.       y = Text_ImageFileY.y - 3;
  441.       width = 45;
  442.       height = 20;
  443.       text = "";
  444.       hint = "Y coordinate to spawn the image file at.";
  445.     }
  446.  
  447.     new GuiCheckBoxCtrl("Check_AutoCoord") {
  448.       profile = GuiBlueCheckBoxProfile;
  449.       x = Input_ImageFileY.x + Input_ImageFileY.width + 10;
  450.       y = Input_ImageFileY.y + 3;
  451.       width = height = 15;
  452.       hint = "Autogenerate coordinates depending on the player's position.";
  453.     }
  454.  
  455.     new GuiMLTextCtrl("Text_AutoCoord") {
  456.       x = Check_AutoCoord.x + Check_AutoCoord.width + 5;
  457.       y = Check_AutoCoord.y;
  458.       height = 135;
  459.       width = 380;
  460.       useownprofile = true;
  461.       profile.modal = false;
  462.     }
  463.  
  464.     new GuiButtonCtrl("Button_Place") {
  465.       profile = GuiBlueButtonProfile;
  466.       width = 50;
  467.       height = 20;
  468.       x = Input_ImageFile.x + Input_ImageFile.width + 15;
  469.       y = Input_ImageFile.y;
  470.       text = "Place";
  471.     }
  472.  
  473.     new GuiButtonCtrl("Button_Destroy") {
  474.       profile = GuiBlueButtonProfile;
  475.       width = 50;
  476.       height = 40;
  477.       x = Button_Place.x;
  478.       y = Button_Place.y + Button_Place.height + 5;
  479.       text = "Destroy";
  480.       hint = "Destroy all image files in the level that were placed with this tool";
  481.     }
  482.  
  483.     new GuiMLTextCtrl("Text_FindImage") {
  484.       x = Input_ImageFile.x;
  485.       y = Input_ImageFile.y + 50;
  486.       height = 135;
  487.       width = 380;
  488.       useownprofile = true;
  489.       profile.modal = false;
  490.     }
  491.  
  492.     new GuiTextEditCtrl("Input_FindImage") {
  493.       profile = GuiBlueTextEditProfile;
  494.       x = Text_FindImage.x;
  495.       y = Text_FindImage.y + 20;
  496.       width = Input_ImageFile.width;
  497.       height = 20;
  498.       text = "";
  499.       hint = "Finds .png files on the server";
  500.     }
  501.  
  502.     new GuiButtonCtrl("Button_FindImage") {
  503.       profile = GuiBlueButtonProfile;
  504.       width = 40;
  505.       height = 20;
  506.       x = Button_Place.x;
  507.       y = Input_FindImage.y;
  508.       text = "Find";
  509.     }
  510.  
  511.     new GuiScrollCtrl("Scroll_FoundImages") {
  512.       profile = GuiBlueScrollProfile;
  513.       x = Input_FindImage.x;
  514.       y = Input_FindImage.y + Input_FindImage.height + 10;
  515.       width = Win4_Companion.width - 30;
  516.       height = 100;
  517.       hScrollBar = "dynamic";
  518.       vScrollBar = "dynamic";
  519.  
  520.       new GuiTextListCtrl("List_FoundImages") {
  521.         profile = GuiBlueTextListProfile;
  522.         x = y = 0;
  523.         width = 140;
  524.         fitparentwidth = true;
  525.       }
  526.     }
  527.   }
  528.   getNotes();
  529.   onUpdateText();
  530. }
  531.  
  532.   // Request to get the users notes as soon as the Gui is launched.
  533. function getNotes() {
  534.   triggerAction(this.x, this.y, "LoadNote", player.account);
  535. }
  536.  
  537.   // Load the user's notes.
  538. function onActionRecieveNote(player, note) {
  539.   if (temp.player == player.account) {
  540.     Text_NotesWindow.setlines(temp.note[0]);
  541.   }
  542. }
  543.  
  544. function Button_SaveNote.onAction() {
  545.   triggerAction(this.x, this.y, "SaveNote", player.account, Text_NotesWindow.getlines());
  546.   shared.adminmessage("Note saved!");
  547. }
  548.  
  549. function onUpdateText() {
  550.     // Some prefixes for the text.
  551.   temp.prefix_big = "<font color=white size=16 face=arial>";
  552.   temp.prefix_small = "<font color=white size=15 face=arial>";
  553.  
  554.   Text_ReplaceAni.text = temp.prefix_big   @ "<b>Replace Animations";
  555.   Text_Sounds.text     = temp.prefix_big   @ "<b>Sounds";
  556.   Text_Images.text     = temp.prefix_big   @ "<b>Images";
  557.   Text_Notes.text      = temp.prefix_big   @ "<b>Notepad";
  558.   Text_Walk.text       = temp.prefix_small @ "Walk:";
  559.   Text_Idle.text       = temp.prefix_small @ "Idle:";
  560.   Text_ImageFile.text  = temp.prefix_small @ "Spawn an image file";
  561.   Text_FindImage.text  = temp.prefix_small @ "Find an image file:";
  562.   Text_ImageFileX.text = temp.prefix_small @ "X:";
  563.   Text_ImageFileY.text = temp.prefix_small @ "Y:";
  564.   Text_AutoCoord.text  = temp.prefix_small @ "Auto";
  565.   Text_PlaySound.text  = temp.prefix_small @ "Play a sound file:";
  566.   Text_FindSound.text  = temp.prefix_small @ "Find a sound file:";
  567.  
  568.   onTimeout();
  569. }
  570.  
  571.   // The main window has been closed, close the others as well.
  572. function Win1_Companion.onCloseQuery() {
  573.   setTimer(0);
  574.   onDestroyGui();
  575. }
  576.  
  577.   // Replace the walk and idle animations.
  578. function Button_ReplaceAniApply.onAction() {
  579.   if (Input_Walk.text == NULL && Input_Idle.text == NULL) {
  580.     shared.adminmessage("Both fields are empty!");
  581.     return;
  582.   }
  583.     // This is made in such a way so that you can either just replace the walk or just replace the idle.
  584.   if (Input_Idle.text != NULL) {
  585.       // Remove the .gani of the input if there is any.
  586.     temp.input_idle = (Input_Idle.text.ends(".gani") ? Input_Idle.text.substring(0, Input_Idle.text.length() - 5) : Input_Idle.text);
  587.     player.ani = temp.input_idle;
  588.     replaceani("idle", temp.input_idle);
  589.   }
  590.   if (Input_Walk.text != NULL) {
  591.     temp.input_walk = (Input_Walk.text.ends(".gani") ? Input_Walk.text.substring(0, Input_Walk.text.length() - 5) : Input_Walk.text);
  592.     replaceani("walk", temp.input_walk);
  593.   }
  594.   player.chat = "Ganis replaced!";
  595. }
  596.  
  597.   // Reset the walk and idle back to the server's default.
  598. function Button_ReplaceAniReset.onAction() {
  599.   player.ani = this.default_idle;
  600.   replaceani("walk", this.default_walk);
  601.   replaceani("idle", this.default_idle);
  602.   player.chat = "Walk and Idle have been reset!";
  603. }
  604.  
  605.   // Play a sound file if one isnt playing already.
  606. function Button_PlaySound.onAction() {
  607.   if (!(isSoundPlaying(this.previous_file))) {
  608.       // Check for empty input.
  609.     if (Input_PlaySound.text == NULL) {
  610.       shared.adminmessage("You must put in a filename!");
  611.       return;
  612.     }
  613.       // Check if their volume is too low. If so, increase it and let them know it's been increased.
  614.     if ($pref::audio::sfxvolume <= 15) {
  615.       $pref::audio::sfxvolume = 40;
  616.       shared.adminmessage("Your game volume was too low. I've set it to 40. Press play again");
  617.       return;
  618.     }
  619.  
  620.       // Ensure the file always ends with .wav
  621.     temp.sound_file = (Input_PlaySound.text.ends(".wav") ? Input_PlaySound.text : Input_PlaySound.text @ ".wav");
  622.  
  623.       // If the soundfile exists, play it. If not, let them know it doesnt exist.
  624.     if (fileExists(temp.sound_file)) {
  625.       play(temp.sound_file);
  626.       this.previous_file = temp.sound_file;
  627.     } else {
  628.       shared.adminmessage("That file doesnt exist!");
  629.     }
  630.   } else {
  631.     shared.adminmessage("The previous file is still playing!");
  632.   }
  633. }
  634.  
  635.   // Clear the sound input.
  636. function Button_ClearSound.onAction() {
  637.   if (Input_PlaySound.text == NULL) {
  638.     shared.adminmessage("Nothing to clear.");
  639.     return;
  640.   }
  641.   Input_PlaySound.text = "";
  642. }
  643.  
  644.   // Search for sound files on the server
  645. function Button_FindSound.onAction() {
  646.     // Check for NULL input.
  647.   if (Input_FindSound.text == NULL) {
  648.     shared.adminmessage("Search field is empty!");
  649.     return;
  650.   }
  651.     // Request a list of all the sound files with the matching query.
  652.   triggerAction(this.x, this.y, "GetFiles", Input_FindSound.text, "*.wav", player.account);
  653. }
  654.  
  655.   // Search for image files on the server
  656. function Button_FindImage.onAction() {
  657.     // Check for NULL input.
  658.   if (Input_FindImage.text == NULL) {
  659.     shared.adminmessage("Search field is empty!");
  660.     return;
  661.   }
  662.     // Request a list of all the sound files with the matching query.
  663.   triggerAction(this.x, this.y, "GetFiles", Input_FindImage.text, "*.png", player.account);
  664. }
  665.  
  666.   // Gets the array of found files and turns it into a list..
  667. function onActionRecieveFiles(format, files, player) {
  668.     // Avoid the client or the wrong player being updated.
  669.   if (temp.player != player.account) { return; }
  670.  
  671.   switch (temp.format) {
  672.     case "*.wav":
  673.     temp.list = temp.files;
  674.     with (List_FoundSounds) {
  675.       clearrows();
  676.       for (temp.i = 0; temp.i < temp.list[0].size(); i++) {
  677.         addrow(temp.i, temp.list[0][temp.i]);
  678.       }
  679.     }
  680.     break;
  681.  
  682.     case "*.png":
  683.     temp.list = temp.files;
  684.     with (List_FoundImages) {
  685.       clearrows();
  686.       for (temp.i = 0; temp.i < temp.list[0].size(); i++) {
  687.         addrow(temp.i, temp.list[0][temp.i]);
  688.       }
  689.     }
  690.     break;
  691.   }
  692. }
  693.  
  694.   // Replaces the text of the input when you click on one of the found files.
  695. function List_FoundSounds.onSelect() {
  696.   Input_FindSound.text = params[1];
  697. }
  698.  
  699. function List_FoundImages.onSelect() {
  700.   Input_FindImage.text = params[1];
  701. }
  702.  
  703. function Button_Place.onAction() {
  704.   if (Input_ImageFile.text == NULL) {
  705.     shared.adminmessage("You must type in a filename!");
  706.     return;
  707.   }
  708.   if (Input_ImageFileX.text == NULL || Input_ImageFileY.text == NULL) {
  709.     shared.adminmessage("Erroneous coordinates. Please check the given X and Y positions");
  710.     return;
  711.   }
  712.     // Add '.png' if the filename doesnt have it.
  713.   temp.input_image_file = (Input_ImageFile.text.ends(".png") ? Input_ImageFile.text : Input_ImageFile.text @ ".png");
  714.  
  715.   triggerAction(this.x, this.y, "PlaceNPC", temp.input_image_file, int(Input_ImageFileX.text), int(Input_ImageFileY.text));
  716. }
  717.  
  718.   // Destroy all of the NPCs created by the tool.
  719. function Button_Destroy.onAction() {
  720.   triggerAction(this.x, this.y, "DestroyNPCS", "");
  721. }
  722.  
  723.   // Toggle generating coordinates based on the player's x and y.
  724. function Check_AutoCoord.onAction() {
  725.   this.auto_coord = ! this.auto_coord;
  726. }
  727.  
  728.   // Destroys all the windows
  729. function onDestroyGui() {
  730.   Win1_Companion.destroy();
  731.   Win2_Companion.destroy();
  732.   Win3_Companion.destroy();
  733.   Win4_Companion.destroy();
  734. }
  735.  
  736.   // Keep the windows next to each other.
  737. function onTimeout() {
  738.   if (this.auto_coord) {
  739.     Input_ImageFileX.text = player.x;
  740.     Input_ImageFileY.text = player.y;
  741.   }
  742.   Win2_Companion.x = Win1_Companion.x + Win1_Companion.width;
  743.   Win2_Companion.y = Win1_Companion.y;
  744.  
  745.   Win3_Companion.x = Win2_Companion.x + Win2_Companion.width;
  746.   Win3_Companion.y = Win2_Companion.y;
  747.  
  748.   Win4_Companion.x = Win2_Companion.x;
  749.   Win4_Companion.y = Win2_Companion.y + Win2_Companion.height;
  750.   setTimer(.05);
  751. }
Add Comment
Please, Sign In to add comment