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

[转载发布] Item Call Script

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

    连续签到: 2 天

    [LV.7]常住居民III

    8004

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 4 天前 | 显示全部楼层 |阅读模式
    ItemCallScript - Version 1.0.0 (2018/09/16)

    Creator name: Triacontane

    Introduction
    Create an item or skill that will run any script when used.

    Note: Javascript knowledge is required for use.



    Instructions-
    Specify the following in the item or skill note box:
    <call:insert script here>

    Example-
                    Code:       
    1. <call:AudioManager.playSe({name: 'Item2', pan: 0, pitch: 100, volume: 100});>
    复制代码


    Note: If you want play your own sound effect for item without default sound (Item3)-
    In database > System > Sounds for "Use Item" set to (None)
    That is, if you plan on using item call script to play sound individually for each items.

    Credit and Thanks: Triacontane

    Terms of Use
    -
    Free for commercial and non-commercial use.

    License
    -
    MIT License: http://opensource.org/licenses/mit-license.php

    Dropbox link: https://www.dropbox.com/s/fugjlnqjk358kyj/ItemCallScript.js?dl=1

    Spoiler: js sample
                    Code:       
    1. /*=============================================================================
    2. ItemCallScript.js
    3. ----------------------------------------------------------------------------
    4. (C)2018 Triacontane
    5. This software is released under the MIT License.
    6. http://opensource.org/licenses/mit-license.php
    7. ----------------------------------------------------------------------------
    8. Version
    9. 1.0.0 2018/09/16 初版
    10. ----------------------------------------------------------------------------
    11. [Blog]   : https://triacontane.blogspot.jp/
    12. [Twitter]: https://twitter.com/triacontane/
    13. [GitHub] : https://github.com/triacontane/
    14. =============================================================================*/
    15. /*:
    16. * @plugindesc ItemCallScriptPlugin
    17. * @author triacontane
    18. *
    19. * @param commandPrefix
    20. * @text Note box prefix
    21. * @desc Prefix specified when the note of another plugin is used. (Can be a blank)
    22. * @default
    23. *
    24. * @help ItemCallScript.js
    25. *
    26. * Create an item or skill that will run any script when used.
    27. * JavaScript knowlegde is required for use.
    28. * Specify the following in the Note box.
    29. * <call:(insert script here)>
    30. *
    31. * If the effect range is set for all allies and all enemies,
    32. * this plugin will be executed for all targets.
    33. *
    34. * The following variables and functions can be used.
    35. * user     : Item user
    36. * target   : Item target
    37. * v(n)     : Get the value of variable [n]
    38. * sv(n, m) : Set value [m] to variable [n]
    39. * s(n)     : Get the value of switch [n]
    40. * ss(n, m) : Set value [m] to switch [n]
    41. * 
    42. * There are no plugin commands for this plugin.
    43. *
    44. * This plugin is released under the MIT License.
    45. */
    46. /*:ja
    47. * @plugindesc スクリプト呼び出しアイテムプラグイン
    48. * @author トリアコンタン
    49. *
    50. * @param commandPrefix
    51. * @text メモ欄接頭辞
    52. * @desc 他のプラグインとメモ欄もしくはプラグインコマンドの名称が被ったときに指定する接頭辞です。通常は指定不要です。
    53. * @default
    54. *
    55. * @help ItemCallScript.js
    56. *
    57. * 使用したときに任意のスクリプトを実行するアイテムもしくはスキルを作成できます。
    58. * 活用にはJavaScriptの知識が必要です。
    59. * メモ欄に以下の通り指定してください。
    60. * <call:(実行したいスクリプト)>
    61. * <スクリプト:(実行したいスクリプト)>
    62. *
    63. * 効果範囲を味方全体、敵全体にすると対象の全員分だけスクリプトが実行されます。
    64. *
    65. * スクリプト中では以下の変数、関数が使用できます。
    66. * user     : アイテムの使用者
    67. * target   : アイテムの対象
    68. * v(n)     : 変数[n]の値を取得
    69. * sv(n, m) : 変数[n]に値[m]を設定
    70. * s(n)     : スイッチ[n]の値を取得
    71. * ss(n, m) : スイッチ[n]に値[m]を設定
    72. * 
    73. * このプラグインにはプラグインコマンドはありません。
    74. *
    75. * 利用規約:
    76. *  作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
    77. *  についても制限はありません。
    78. *  このプラグインはもうあなたのものです。
    79. */
    80. (function() {
    81.     'use strict';
    82.     /**
    83.      * Get database meta information.
    84.      * @param object Database item
    85.      * @param name Meta name
    86.      * @returns {String} meta value
    87.      */
    88.     var getMetaValue = function(object, name) {
    89.         var tagName = param.commandPrefix + name;
    90.         return object.meta.hasOwnProperty(tagName) ? convertEscapeCharacters(object.meta[tagName]) : null;
    91.     };
    92.     /**
    93.      * Get database meta information.(for multi language)
    94.      * @param object Database item
    95.      * @param names Meta name array (for multi language)
    96.      * @returns {String} meta value
    97.      */
    98.     var getMetaValues = function(object, names) {
    99.         var metaValue;
    100.         names.some(function(name) {
    101.             metaValue = getMetaValue(object, name);
    102.             return metaValue !== null;
    103.         });
    104.         return metaValue;
    105.     };
    106.     /**
    107.      * Convert escape characters.(require any window object)
    108.      * @param text Target text
    109.      * @returns {String} Converted text
    110.      */
    111.     var convertEscapeCharacters = function(text) {
    112.         var windowLayer = SceneManager._scene._windowLayer;
    113.         return windowLayer ? windowLayer.children[0].convertEscapeCharacters(text.toString()) : text;
    114.     };
    115.     /**
    116.      * Create plugin parameter. param[paramName] ex. param.commandPrefix
    117.      * @param pluginName plugin name(EncounterSwitchConditions)
    118.      * @returns {Object} Created parameter
    119.      */
    120.     var createPluginParameter = function(pluginName) {
    121.         var paramReplacer = function(key, value) {
    122.             if (value === 'null') {
    123.                 return value;
    124.             }
    125.             if (value[0] === '"' && value[value.length - 1] === '"') {
    126.                 return value;
    127.             }
    128.             try {
    129.                 return JSON.parse(value);
    130.             } catch (e) {
    131.                 return value;
    132.             }
    133.         };
    134.         var parameter     = JSON.parse(JSON.stringify(PluginManager.parameters(pluginName), paramReplacer));
    135.         PluginManager.setParameters(pluginName, parameter);
    136.         return parameter;
    137.     };
    138.     var param = createPluginParameter('ItemCallScript');
    139.     var _Game_Action_applyItemUserEffect = Game_Action.prototype.applyItemUserEffect;
    140.     Game_Action.prototype.applyItemUserEffect = function(target) {
    141.         _Game_Action_applyItemUserEffect.apply(this, arguments);
    142.         this.applyItemScript(target);
    143.     };
    144.     var _Game_Action_applyGlobal = Game_Action.prototype.applyGlobal;
    145.     Game_Action.prototype.applyGlobal = function() {
    146.         _Game_Action_applyGlobal.apply(this, arguments);
    147.         if (this.isForNone()) {
    148.             this.applyItemScript(null);
    149.         }
    150.     };
    151.     Game_Action.prototype.isForNone = function() {
    152.         return this.checkItemScope([0]);
    153.     };
    154.     var _Game_Action_testApply = Game_Action.prototype.testApply;
    155.     Game_Action.prototype.testApply = function(target) {
    156.         return _Game_Action_testApply.apply(this, arguments) || !!this.getItemScript();
    157.     };
    158.     Game_Action.prototype.applyItemScript = function(target) {
    159.         var script = this.getItemScript();
    160.         var user = this.subject();
    161.         if (script) {
    162.             var v = $gameVariables.value.bind($gameVariables);
    163.             var sv = $gameVariables.setValue.bind($gameVariables);
    164.             var s = $gameSwitches.value.bind($gameSwitches);
    165.             var ss = $gameSwitches.setValue.bind($gameSwitches);
    166.             eval(script);
    167.         }
    168.     };
    169.     Game_Action.prototype.getItemScript = function() {
    170.         return getMetaValues(this.item(), ['スクリプト', 'call']);
    171.     };
    172. })();
    复制代码




    本贴来自国际rpgmaker官方论坛作者:ovate处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/item-call-script.115897/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-8-1 09:33 , Processed in 0.117013 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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