- Joined
- Jan 20, 2014
- Messages
- 385
- Reaction score
- 123
- First Language
- English
This is my very first MV plug-in, and I need some feedback/help!
What it does: This lets you write a bunch of different descriptions, dialogue, etc. for various events, and have them randomly displayed when clicked. For instance, I can write multiple descriptions of a crystal, and then every time you click on a crystal (that uses the plug-in command), it will give you one of the descriptions randomly. You can have characters say different dialogue to you each time you talk to them, and so on. See the script help file for more info, and examples.
There are parameters to change window position, face graphic, etc. You can also override these in each event.
You have to edit the script itself to add your text -- adding it all in parameters would be incredibly tedious and limiting.
Everything works as intended, but I don't know if this is the best way to do it. Any serious problems here? Is it okay to use "switch" for this? Is there a more efficient method? If I have hundreds of "objects" is that going to be a problem? Other thoughts?
*** THIS IS IN PROGRESS *** Use at your own risk. I may radically rewrite this script, and you will need to redo your changes with different code.
What it does: This lets you write a bunch of different descriptions, dialogue, etc. for various events, and have them randomly displayed when clicked. For instance, I can write multiple descriptions of a crystal, and then every time you click on a crystal (that uses the plug-in command), it will give you one of the descriptions randomly. You can have characters say different dialogue to you each time you talk to them, and so on. See the script help file for more info, and examples.
There are parameters to change window position, face graphic, etc. You can also override these in each event.
You have to edit the script itself to add your text -- adding it all in parameters would be incredibly tedious and limiting.
Everything works as intended, but I don't know if this is the best way to do it. Any serious problems here? Is it okay to use "switch" for this? Is there a more efficient method? If I have hundreds of "objects" is that going to be a problem? Other thoughts?
*** THIS IS IN PROGRESS *** Use at your own risk. I may radically rewrite this script, and you will need to redo your changes with different code.
Code:
//=============================================================================// CRG_RandomText.js//=============================================================================/*: * @plugindesc v1.02 Displays random text when clicking on an event. * @author Tommy Gun * * @help * * You need to manually edit this script and add your objects (or whatever you * want the player to click on) and your text. You can add any number of * sentences, and any number of objects (create a new "case" for each one). * * Then add the plug-in command "RandomText object" (without quotes) to each * event, and replace "object" with the name you used in the script. * * Example: RandomText candles * * You can also use the shorter version "rt object" if you prefer. * * You can override the default parameters in two ways: * 1) use the Advanced Template to change options in the script * 2) pass the arguments in the plug-in command (which will also override #1), * in this format: * RandomText object Background WindowPos NameBox ShowFace FaceName FaceNum * * Example: RandomText candles 1 1 none true Actor3 4 * * If you leave out any at the end, the default values will be used. * * Example: RandomText candles 1 1 none true * In this case Actor1 would be shown, or whatever you have set. * * Name Box: You must have Yanfly Message Core installed. To disable, leave * blank or type "none" or 0. Underscores will get converted into spaces * when used in the plug-in command. * Example: Tommy_Gun * * Word Wrap: You must install a separate plug-in, then add the tag they use. * Yanfly Message Core: <WordWrap> * Yami: <wrap> * You can also leave it blank to disable word wrap. * * @param Background * @desc [0 = window, 1 = dim, 2 = transparent] * @default 1 * * @param Window Position * @desc [0 = top, 1 = middle, 2 = bottom] * @default 1 * * @param Name Box * @desc Requires Yanfly Message Core! Type a name to show in the name box or use "none" to disable. Example: Tommy * @default none * * @param Show Face * @desc Displays a face graphic. [true/false] * @default false * * @param Face Name * @desc Type the name of the face graphic. Example: Actor1 * @default Actor1 * * @param Face Number * @desc Type the number of the face graphic [0-3 top row, 4-7 bottom row] * @default 0 * * @param Word Wrap Tag * @desc Requires another plug-in! Yanfly Message Core: <WordWrap> / Yami: <wrap> * @default * */(function() { var parameters = PluginManager.parameters('CRG_RandomText'); // Parameters var backgroundParam = Number(parameters['Background'] || 1); var windowPositionParam = Number(parameters['Window Position'] || 1); var nameBoxParam = String(parameters['Name Box'] || 'none'); var showFaceParam = String(parameters['Show Face'] || 'false'); var faceNameParam = String(parameters['Face Name'] || 'Actor1'); var faceNumberParam = Number(parameters['Face Number'] || 0); var wordWrapTagParam = String(parameters['Word Wrap Tag'] || ''); var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command === 'RandomText' || command === 'rt' ) { switch (args[0]) { /* ## OBJECT TEMPLATE - copy and paste below to add more objects ## case 'NameHere': var object = [ "", "", "", ""]; break; ## ADVANCED TEMPLATE TO OVERRIDE PARAMETERS - you can delete the lines you don't need to override ## case 'NameHere': var backgroundCase = '0'; var windowPositionCase = '0'; var nameBoxCase = ''; var showFaceCase = 'true'; var faceNameCase = 'Actor1'; var faceNumberCase = '0'; var object = [ "", "", "", ""]; break; ###### ADD OBJECTS BELOW HERE ###### */ case 'candles': var object = [ "There are three candles burning brightly.", "A candle holder with three lit candles.", "These candles look like they've been recently lit.", "Let us bask in its warm, glowing, warming glow."]; break; /* ###### DO NOT EDIT PAST HERE ###### */ } // Load arguments, case settings, or parameters var background = Number(args[1] || backgroundCase || backgroundParam); var windowPosition = Number(args[2] || windowPositionCase || windowPositionParam); var nameBox = String(args[3] || nameBoxCase || nameBoxParam); var showFace = String(args[4] || showFaceCase || showFaceParam); var faceName = String(args[5] || faceNameCase || faceNameParam); var faceNumber = Number(args[6] || faceNumberCase || faceNumberParam); // Check name box, convert underscores to spaces if (nameBox == 'none' || nameBox == 0) { nameBox = ''; } else { nameBox = "\\n<" + nameBox.replace(/_/g,' ') + ">"; } // Select random sentence var randomText = object[Math.floor(Math.random() * object.length)]; // Create Message if (showFace === 'true') { $gameMessage.setFaceImage(faceName,faceNumber); } $gameMessage.setBackground(background); $gameMessage.setPositionType(windowPosition); $gameMessage.add(nameBox + wordWrapTagParam + randomText); } };})();
Last edited by a moderator:

