设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 63|回复: 0

[转载发布] Random Dialogue v1.03a

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    7959

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    29925
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    38778

    灌水之王

    发表于 4 天前 | 显示全部楼层 |阅读模式
    Random Dialogue v1.03a
    Author: Michael Morris @Blue Booth Studios
    Demo thanks to Anthony Xue: http://ancient-architects.com/files/Conversation Demo.zip

    Introduction
        Sometimes you just need NPCs to say random stuff.  Not completely random, per say, but for example, let's say you have an NPC who shares rumors with the player.  As long as said rumor is unlocked, you don't care which rumor the NPC cares to share.  Likewise, you may have a series of lines kids can say "you look funny!", "Mister, where do babies come from?" or something else inane.  You might even have the kids say smart things.  But again, you simply care that one intelligent option is chosen, not which specific line activates.  While you can do all of this manually using conditional branches... you can also use this script and not have that nasty conditional mess to check every time something goes wonky.  This script takes care of all the issues above for you, so you can spend less time checking random kid 36b says the right thing.  In fact, this can even be used to improve world immersion, as your NPCs will now say different, but appropriate things!

    Features

    • Select a dialogue line at random from a series of dialogue lines.  This has many uses, but for example, allows you to easily replicate Fi's "rumors" system from Skyward Sword.
    • Dialogue lines can be limited based on real-time conditions - for example, "I know where the cave is" will only show if a game switch is active, which indicates the player has heard about the cave.
    • Dialogue lines separated into categories and topics.  This means you can have rumors, game tips, and a whole bunch of other stuff in rumors.json, and select "rumors" to only choose from rumor dialogue lines.
    • Random dialogue lines use the message box without additional modification, so any changes to the message box you make before calling the Plugin Command (position, windowskin, etc.) will carry over to affect the appearance of the dialogue lines.
    • Dialogue lines can be restricted by a further condition - "available" is intended to track when a line is unlocked (for example, if the player kills a bandit, dialogue about that bandit being dangerous won't show).  "restriction" is intended to further restrict dialogue lines to be appropriate to a speaker.  For example, you can use a game variable with a manually tracked index (ie. Widow = 1, Guard = 2, Veteran = 3), so that an NPC will not say a random line that would be out of character.
    • Random will now avoid consecutive repetition of a given dialogue line, provided more than one random dialogue line is available to choose from.
    • Faceset support!
    • NPCs will not resume movement while a random dialogue line is displayed.
    • Plugin now displays user-friendly error messages for an incorrect number of parameters, misspelling of command, etc.
    • Plugin now supports case insensitive checks (requires rumors.json having all Category and Topic values in lower-case).

    Screenshots
        None.


    How to Use

    • Copy script into your game js/plugins directory.
    • Create a Rumors.json file in your game data directory.
    • Import this script into your project and set all two parameters.
    • Use the Plugin Command to get a random dialogue line output into message box.

    Demo
        Thanks to Anthony Xue, a demo is available here:
    http://ancient-architects.com/files/Conversation Demo.zip

        Create a new project, and then extract this archive into that new project.


    Script
    Spoiler                Code:       
    1. //=============================================================================
    2. // Bluebooth Plugins - Random Conversations
    3. // BBS_RandomConversations.js
    4. //=============================================================================
    5. //=============================================================================
    6. /*:
    7. * @title Random Conversations Plugin
    8. * @author Michael Morris (https://www.patreon.com/bluebooth)
    9. * @date Feb 19, 2016
    10. * @filename BBS_RandomConversations.js
    11. * If you enjoy/benefit from my work, please support me on Patreon!
    12. *
    13. * https://www.patreon.com/bluebooth
    14. *
    15. * @plugindesc v1.03a Add random dialogue for a specific topic to your game.
    16. * This allows you to pick a random (unlocked) rumor to share, pick a hint at random, given
    17. * general dialogue on a specific point, etc.  There's a lot of exciting things you can
    18. * do with this!  Original design was merged with elements of Iavra's Achievements
    19. * file parsing and then new enhancements / reworkings were added on top of that.
    20. * Special Thanks to Tsukihime for all the help.
    21. * Special Thanks to Anthony Xue for bug fixes and documentation help.
    22. * Special Thanks to Iavra, the file parse handling is modified from his own (awesome) Achievements plugin.
    23. *  You should pick it up, it's really well done.
    24. *
    25. * ============================================================================
    26. * Terms of Use
    27. * ============================================================================
    28. *   - Free for use in non-commercial projects with credits
    29. *   - Contact me for commercial use
    30. *
    31. * ============================================================================
    32. * Parameters
    33. * ============================================================================
    34. * @param Configuration File
    35. * @desc Name of an external configuration file to load at game start. Default: data/Rumors.json
    36. * @default data/Rumors.json
    37. *
    38. * @param Case Insensitive
    39. * @desc Enable to use case insensitive string comparisons.  You will need to manually
    40. * convert Rumors.json Categories and Topics values to lower case.
    41. * @default false
    42. *
    43. * @param Debug Mode
    44. * @desc Enable to activate console variable logging.  Use for debugging odd behaviour.
    45. * true to enable console variable logging.
    46. * @default false
    47. *
    48. * @help
    49. * ============================================================================
    50. * Description
    51. * ============================================================================
    52. * Add random dialogue for a specific topic to your game.  This allows you to pick a random (unlocked) rumor to share,
    53. * pick a hint at random, given general dialogue on a specific point, etc.  There's a lot of exciting things you can
    54. * do with this!  Original design was merged with elements of Iavra's Achievements file parsing and then new
    55. * enhancements / reworkings were added on top of that.
    56. *
    57. * To add random dialogue to your game, create a txt file in your data directory called rumors.json.  This is
    58. * a very flexible system that can be used from anything to random dialogue to selecting one random rumor from a series of many,
    59. * to doing the same for hints, and so on.  To support having multiple topics (each with an item that can be selected at random),
    60. * these dialogue items are split into both Topics (ie. "The Temple Puzzle") and "Categories" (ie. "Puzzles").  Each dialogue
    61. * entry consists of multiple properties:
    62. *
    63. * id           A unique numeric id, that may not contain commas or whitespaces.
    64. * topic        Topic name.
    65. * category        Category name.
    66. * dialogue        Dialogue box contents associated with this topic.  To add \c[], \v[], \i... or other message shortcuts, you must use two slashes \\ in JSON.  See examples below.
    67. * available    Eval condition as string.  If true, this dialogue item is available.
    68. * restriction  Eval condition as string.  If false, this dialogue item is available.  Used to restrict random conversation items
    69. *                for specific NPCs (ie. "adventurer only", "widow only", etc.)
    70. *
    71. * This is a sample file, containing one of each achievement types:
    72. *
    73. * [
    74. *    {
    75. *         "id":0,
    76. *         "topic":"SantaCompana",
    77. *            "category":"Toledo",
    78. *         "dialogue":"They say the \\c[3]Santa Compana\\c[0] has been spotted near the \\c[3]Old Monastery\\c[0].  I hope it doesn't get any closer to town.",
    79. *         "available":"$gameSwitches.value(297) === false",
    80. *         "restriction":"false"
    81. *    },
    82. *    {
    83. *         "id":1,
    84. *         "topic":"SantaCompana",
    85. *             "category":"Toledo",
    86. *         "dialogue":"I haven't heard any news about \\c[3]Santa Compana\\c[0] sightings.  Maybe the reaper has moved on?",
    87. *         "available":"$gameSwitches.value(297) === true",
    88. *         "restriction":"false"
    89. *    },
    90. *    {
    91. *         "id":2,
    92. *         "topic":"Culebre",
    93. *             "category":"Toledo",
    94. *         "dialogue":"I don't know how my family is going to stay fed with that damned \\c[3]Culebre\\c[0] at large.",
    95. *         "available":"$gameSwitches.value(126) === false",
    96. *         "restriction":"$gameVariables.value(77) === 2"
    97. *    }
    98. * ]
    99. *
    100. * ============================================================================
    101. * Plugin Commands
    102. * ============================================================================
    103. * Use the following plugin commands to manipulate custom controls.
    104. *
    105. * Plugin Commands:
    106. *
    107. *     RandomConversation getRandomMsg category topic faceset faceNum        # Get a random dialogue entry with corresponding category, and topic.  Optional faceset and faceNum may be specified.
    108. *
    109. * ============================================================================
    110. * Change Log
    111. * ============================================================================
    112. * 1.03a - Fixed short-list bug.
    113. * 1.03  - Category and Topic search now has added case insensitivity mode for more user-friendly usage.
    114. * 1.02a - Fixed some typos and bugs courtesy of Steffen (Anthony Xue).  Thanks man!  User friendly check added for # args.
    115. * 1.02  - Added in lastconv check to avoid repeating random dialogue when other entries can be played instead.
    116. * 1.01a - Common mispelling now detected to be more dev friendly.
    117. *         - Finally found out and documented how to add \... codes as in native Messagebox.
    118. * 1.01  - Faceset and faceNum are now optional parameters.
    119. * 1.00a - Fixed references to bad element in help.
    120. * 1.00  - Plugin finished.
    121. *
    122. */
    123. //=============================================================================
    124. //=============================================================================
    125. var Imported = Imported || {} ;
    126. var BBS = BBS || {};
    127. Imported.RandomConversations = 1;
    128. BBS.RandomConversations = BBS.RandomConversations || {};
    129. (function() {
    130.     // Stores all rumors.
    131.     var _rumors;
    132.     var curCategory;
    133.     var curTopic;
    134.     var lastConv;
    135.     //=============================================================================
    136.     // Parameter Variables
    137.     //=============================================================================
    138.     var parameters = PluginManager.parameters('BBS_RandomConversations');
    139.     var pConfiguration      = String(parameters['Configuration File'] || 'data/Rumors.json');
    140.     var pLowerCaseChecks  = eval(String(parameters['Case Insensitive'] || 'false'));
    141.     var pDebugging          = eval(String(parameters['Debug Mode'] || 'false'));
    142.     //=============================================================================
    143.     // Rumor Class
    144.     //=============================================================================
    145.     function Rumor() {
    146.         this.initialize.apply(this, arguments);
    147.     };
    148.     Rumor.prototype.initialize = function(data) {
    149.         this._id = Number(data.id);
    150.         this._topic = String(data.topic);
    151.         this._category = String(data.category);
    152.         this._dialogue = String(data.dialogue);
    153.         this._availableStr = String(data.available);
    154.         this._restrictionStr = String(data.restriction);
    155.     };
    156.     Rumor.prototype._isUnlocked = function() {
    157.         return eval(this._availableStr);
    158.     };
    159.     Rumor.prototype._isRestricted = function() {
    160.         return eval(this._restrictionStr);
    161.     };
    162.     Rumor.prototype.isAvailable = function() {
    163.         return (this._isUnlocked() && !this._isRestricted());
    164.     };
    165.     Rumor.prototype = Object.create(Rumor.prototype);
    166.     Rumor.prototype.constructor = Rumor;
    167.     /**
    168.      * Creates rumors from the given data and loads their current state, afterwards.
    169.      */
    170.     var _create = function(data) {
    171.         var temp = [];
    172.         for(var i = 0, max = data.length; i < max; ++i) {
    173.             entry = data[i];
    174.             temp.push(new Rumor(entry));
    175.         }
    176.   
    177.         _rumors = temp;
    178.         curCategory = '';
    179.         curTopic = '';
    180.         lastConv = -1;
    181.   
    182.         if (pDebugging) {
    183.             console.log(_rumors);
    184.         }
    185.     };
    186.     //=============================================================================
    187.     // Game_Interpreter
    188.     //=============================================================================
    189.     var BBS_RC_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    190.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
    191.         // User friendly correction
    192.         if (command === 'RandomConversation') {
    193.             console.log("BBS_RandomConversations plugin command not called correctly.  Did you mean RandomConversations?");
    194.         }
    195.   
    196.         if (command === 'RandomConversations')
    197.         {
    198.             switch (args[0]) {
    199.                 case 'getRandomMsg':
    200.                     SceneManager._scene.getRandomDialogue(args);
    201.                     break;
    202.             };
    203.         }
    204.         else {
    205.             BBS_RC_Game_Interpreter_pluginCommand.call(this, command, args);
    206.         }
    207.     };
    208.     //=============================================================================
    209.     // Game_Temp
    210.     //=============================================================================
    211.     /* Tsukihime - Generates a random number from the given interval.
    212.      You can customize the algorithm used to generate a
    213.      random number if needed */
    214.     Game_Temp.prototype._generateRandomValue = function(min, max) {
    215.         if (min === max) {
    216.           return min;
    217.         }
    218.         else {
    219.           // Maybe you can customize this
    220.           return Math.floor(Math.random() * (max - min + 1)) + min
    221.         }
    222.     };
    223.     //=============================================================================
    224.     // Scene_Map
    225.     //=============================================================================
    226.     Scene_Map.prototype._createShortlist = function(category, topic) {
    227.         var temp = [];
    228.         this.shortlist = [];
    229.         lastConv = -1;
    230.   
    231.         for (var i = 0; i < _rumors.length; i++)
    232.         {
    233.             if (_rumors[i]._category === category && _rumors[i]._topic === topic)
    234.             {
    235.                 if (_rumors[i].isAvailable()) {
    236.                     temp.push(_rumors[i]);
    237.                 }
    238.             }
    239.         }
    240.   
    241.         if (temp.length > 1) {
    242.             // Remove last conversation entry, only if there are sufficient entries to remove it.
    243.             for (var j = 0; j < temp.length; j++) {
    244.                 if (temp[j]._id != lastConv) {
    245.                     this.shortlist.push(temp[j]);
    246.                 }
    247.             }
    248.         }
    249.         else {
    250.             this.shortlist = temp;
    251.         }
    252.   
    253.         // For debugging sake.
    254.         if (this.shortlist.length <= 0) {
    255.             console.log("ERROR: No random conversations options for Category: '" + category + "' ; Topic: '" + topic + "'");
    256.         }
    257.         curCategory = category;
    258.         curTopic = topic;
    259.     };
    260.     Scene_Map.prototype.getRandomDialogue = function(args) {
    261.         if (args.length < 2) {
    262.             console.log("ERROR: Too few parameters passed into getRandomMsg(...).  Minimum args: 2.");
    263.         }
    264.   
    265.         var category = String(args[1]);
    266.         var topic = String(args[2]);
    267.   
    268.         // User sanity; remove need for matching capitalization.
    269.         if (pLowerCaseChecks === true) {
    270.             category = category.toLowerCase();
    271.             topic = topic.toLowerCase();
    272.         }
    273.   
    274.         this._createShortlist(category, topic);
    275.         if (this.shortlist.length <= 0) return;
    276.   
    277.         var randomIndex = $gameTemp._generateRandomValue(0, (this.shortlist.length - 1));
    278.   
    279.         $gameMap._interpreter.setWaitMode('message');
    280.   
    281.         if (args.length > 3) {
    282.             var faceFile = String(args[3]);
    283.       
    284.             var faceNum = 0;
    285.             if (args.length > 4) {
    286.                 faceNum = Number(args[4]);
    287.             }
    288.       
    289.             $gameMessage.setFaceImage(faceFile, faceNum);
    290.         }
    291.   
    292.         $gameMessage.addText(this.shortlist[randomIndex]._dialogue);
    293.         lastConv = this.shortlist[randomIndex]._id;
    294.     };
    295.     //=============================================================================
    296.     // class Scene_Boot
    297.     //=============================================================================
    298.     var BBS_RC_Scene_Boot_create = Scene_Boot.prototype.create;
    299.     Scene_Boot.prototype.create = function() {
    300.         BBS_RC_Scene_Boot_create.call(this);
    301.         this._loadFile(pConfiguration, _create);
    302.     };
    303.     Scene_Boot.prototype._loadFile = function(url, callback) {
    304.         var request = new XMLHttpRequest();
    305.         request.open('GET', url);
    306.         request.overrideMimeType('application/json');
    307.         request.onload = function() { callback(JSON.parse(request.responseText)); }
    308.         request.onerror = function() { throw new Error('There was an error loading the file ' + url); }
    309.         request.send();
    310.     };
    311.     var BBS_RC_Scene_Boot_isReady = Scene_Boot.prototype.isReady;
    312.     Scene_Boot.prototype.isReady = function() {
    313.         return !!_rumors && BBS_RC_Scene_Boot_isReady.call(this);
    314.     };
    315.   
    316. })(BBS.RandomConversations);
    317. //=============================================================================
    318. // End of File
    319. //=============================================================================
    复制代码





    Known Bugs / TODO
    Make your suggestions or report bugs here!

    Requirements

    • Yanfly's Message Core plugin - YEP_MessageCore.js.  Set the "Word Wrap" plugin parameter to true.

    History
    Spoilerv1.03a
       - Fixed bug with availability and restriction conditions due to shortlist caching.
    v1.03
       - Category and Topic search now has added case insensitivity mode for more user-friendly usage.
    v1.02a
       - Fixed typos and bugs courtesy of Steffen (Anthony Xue).  Thanks man!  User friendly check added for # args.
    v1.02

       - Added in lastconv check to avoid repeating random dialogue when other entries can be played instead.
    v1.01a
      - Finally found out and documented how to add \... codes as in native Messagebox.
      - Common misspelling now detected to be more developer friendly.
    v1.01
      - Faceset and faceNum are now optional parameters.
      - Squashed some bugs.
      - Fixed the last few documentation errors.
    v1.00a
      - Fixed documentation errors.
    v1.00
      - Plugin released.




    Suggestions, bug reports, and feature requests are welcomed!


    Compatibility Issues
    None known.  Compatible with Klaus Map Overlays, Terrax Lighting System, and most (if not all) of Yanfly's plugins.

    FAQ
    Q: The demo won't open, how to open it?
        A: Download Winrar and try again.


    Credit and Thanks

    • Micheal Morris @Blue Booth Studios
    • Credit to Tsukihime for continuing to be so helpful!
    • Special Thanks to Anthony Xue for bug fixes and documentation help.
    • Iavra for the JSON handling code, based on that from achievements.js.

    Author's Notes
    Free for non-commercial usage as long as credit is given, contact me for commercial use.



    本贴来自国际rpgmaker官方论坛作者:bluebooth处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/random-dialogue-v1-03a.57313/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 07:32 , Processed in 0.113053 second(s), 57 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表