iMagicBae

Gani Staff Companion v3

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