tale

Volunteer
Veteran
Joined
Dec 16, 2016
Messages
809
Reaction score
1,360
First Language
English
Primarily Uses
N/A
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:
<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

Code:
/*=============================================================================
 ItemCallScript.js
----------------------------------------------------------------------------
 (C)2018 Triacontane
 This software is released under the MIT License.
 http://opensource.org/licenses/mit-license.php
----------------------------------------------------------------------------
 Version
 1.0.0 2018/09/16 初版
----------------------------------------------------------------------------
 [Blog]   : https://triacontane.blogspot.jp/
 [Twitter]: https://twitter.com/triacontane/
 [GitHub] : https://github.com/triacontane/
=============================================================================*/

/*:
 * @plugindesc ItemCallScriptPlugin
 * @author triacontane
 *
 * @param commandPrefix
 * @text Note box prefix
 * @desc Prefix specified when the note of another plugin is used. (Can be a blank)
 * @default
 *
 * @help ItemCallScript.js
 *
 * Create an item or skill that will run any script when used.
 * JavaScript knowlegde is required for use.
 * Specify the following in the Note box.
 * <call:(insert script here)>
 *
 * If the effect range is set for all allies and all enemies,
 * this plugin will be executed for all targets.
 *
 * The following variables and functions can be used.
 * user     : Item user
 * target   : Item target
 * v(n)     : Get the value of variable [n]
 * sv(n, m) : Set value [m] to variable [n]
 * s(n)     : Get the value of switch [n]
 * ss(n, m) : Set value [m] to switch [n]
 * 
 * There are no plugin commands for this plugin.
 *
 * This plugin is released under the MIT License.
 */
/*:ja
 * @plugindesc スクリプト呼び出しアイテムプラグイン
 * @author トリアコンタン
 *
 * @param commandPrefix
 * @text メモ欄接頭辞
 * @desc 他のプラグインとメモ欄もしくはプラグインコマンドの名称が被ったときに指定する接頭辞です。通常は指定不要です。
 * @default
 *
 * @help ItemCallScript.js
 *
 * 使用したときに任意のスクリプトを実行するアイテムもしくはスキルを作成できます。
 * 活用にはJavaScriptの知識が必要です。
 * メモ欄に以下の通り指定してください。
 * <call:(実行したいスクリプト)>
 * <スクリプト:(実行したいスクリプト)>
 *
 * 効果範囲を味方全体、敵全体にすると対象の全員分だけスクリプトが実行されます。
 *
 * スクリプト中では以下の変数、関数が使用できます。
 * user     : アイテムの使用者
 * target   : アイテムの対象
 * v(n)     : 変数[n]の値を取得
 * sv(n, m) : 変数[n]に値[m]を設定
 * s(n)     : スイッチ[n]の値を取得
 * ss(n, m) : スイッチ[n]に値[m]を設定
 * 
 * このプラグインにはプラグインコマンドはありません。
 *
 * 利用規約:
 *  作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
 *  についても制限はありません。
 *  このプラグインはもうあなたのものです。
 */

(function() {
    'use strict';

    /**
     * Get database meta information.
     * @param object Database item
     * @param name Meta name
     * @returns {String} meta value
     */
    var getMetaValue = function(object, name) {
        var tagName = param.commandPrefix + name;
        return object.meta.hasOwnProperty(tagName) ? convertEscapeCharacters(object.meta[tagName]) : null;
    };

    /**
     * Get database meta information.(for multi language)
     * @param object Database item
     * @param names Meta name array (for multi language)
     * @returns {String} meta value
     */
    var getMetaValues = function(object, names) {
        var metaValue;
        names.some(function(name) {
            metaValue = getMetaValue(object, name);
            return metaValue !== null;
        });
        return metaValue;
    };

    /**
     * Convert escape characters.(require any window object)
     * @param text Target text
     * @returns {String} Converted text
     */
    var convertEscapeCharacters = function(text) {
        var windowLayer = SceneManager._scene._windowLayer;
        return windowLayer ? windowLayer.children[0].convertEscapeCharacters(text.toString()) : text;
    };

    /**
     * Create plugin parameter. param[paramName] ex. param.commandPrefix
     * @param pluginName plugin name(EncounterSwitchConditions)
     * @returns {Object} Created parameter
     */
    var createPluginParameter = function(pluginName) {
        var paramReplacer = function(key, value) {
            if (value === 'null') {
                return value;
            }
            if (value[0] === '"' && value[value.length - 1] === '"') {
                return value;
            }
            try {
                return JSON.parse(value);
            } catch (e) {
                return value;
            }
        };
        var parameter     = JSON.parse(JSON.stringify(PluginManager.parameters(pluginName), paramReplacer));
        PluginManager.setParameters(pluginName, parameter);
        return parameter;
    };

    var param = createPluginParameter('ItemCallScript');

    var _Game_Action_applyItemUserEffect = Game_Action.prototype.applyItemUserEffect;
    Game_Action.prototype.applyItemUserEffect = function(target) {
        _Game_Action_applyItemUserEffect.apply(this, arguments);
        this.applyItemScript(target);
    };

    var _Game_Action_applyGlobal = Game_Action.prototype.applyGlobal;
    Game_Action.prototype.applyGlobal = function() {
        _Game_Action_applyGlobal.apply(this, arguments);
        if (this.isForNone()) {
            this.applyItemScript(null);
        }
    };

    Game_Action.prototype.isForNone = function() {
        return this.checkItemScope([0]);
    };

    var _Game_Action_testApply = Game_Action.prototype.testApply;
    Game_Action.prototype.testApply = function(target) {
        return _Game_Action_testApply.apply(this, arguments) || !!this.getItemScript();
    };

    Game_Action.prototype.applyItemScript = function(target) {
        var script = this.getItemScript();
        var user = this.subject();
        if (script) {
            var v = $gameVariables.value.bind($gameVariables);
            var sv = $gameVariables.setValue.bind($gameVariables);
            var s = $gameSwitches.value.bind($gameSwitches);
            var ss = $gameSwitches.setValue.bind($gameSwitches);
            eval(script);
        }
    };

    Game_Action.prototype.getItemScript = function() {
        return getMetaValues(this.item(), ['スクリプト', 'call']);
    };
})();
 
Last edited:

Lomognom

Warper
Member
Joined
Jun 12, 2020
Messages
1
Reaction score
2
First Language
Rus
Primarily Uses
RMMV
Hi may someone need it: For change variables.
For example i put in (item note) to change (Var.) in item menu by using item.
Code:
<call:$gameVariables.setValue(9, $gameVariables.value(9)+50);>
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
3,176
Reaction score
1,179
First Language
Dutch
Primarily Uses
RMMV
I add the SE and variable as samples in the script, just in case :)
 

Dopan

Veteran
Veteran
Joined
Mar 27, 2020
Messages
684
Reaction score
352
First Language
German
Primarily Uses
RMMV
I am curius, i was using the yep skill core and "custom execution" to archieve this.
(call script on action)
Or i was using skill common events if it should happen after the action...

is there much difference if using this Plugin?
 

Latest Threads

Latest Posts

Latest Profile Posts

Holy cow... work is demanding and I'm back in college. I'm kind of scared of my dad right now after the incident, but at least I don't live with him all the time. Anyway, working on Fandom Scouts and my FNAF character set. The FNAF sprites are actually going to be used in the game... unfortunately the enemy sprites are FNAF World traces, so no sharing those.
The honeymoon period is over with Cyberpunk 2077, It sadly doesnt live up to the hype, pretty graphics arent everything (especially when I cant even do something as simple as changing the radio station over!). Replaying Breath of the wild has reminded me what a good game really looks like, plus that one has good glitches!....
Ami


Maybe...a Drinkable Water Plant or something?
Who would have thought making interesting birds would be so difficult/fun?

Randomly spawning anywhere on map (sometimes even flying), having a chance of landing on a different spot on map when flying. Also chance of flying off screen if spooked/sees the player

I think I got it!

Forum statistics

Threads
107,680
Messages
1,031,390
Members
139,801
Latest member
IsaacRPG
Top