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

[转载发布] LadyBaskerville's Miscellaneous Javascript Snippets

[复制链接]
累计送礼:
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 天前 | 显示全部楼层 |阅读模式
    Over the last months, I've accumulated a few code snippets I did for requests. While none of them deserves its own plugin thread, I wanted to share them somewhere in case someone else might find use in them.

    They are posted below as both .js files to download and place directly in your plugins folder and as spoilered code. The contents of the .js files and the spoilers should be exactly the same, so you only need to download one or the other.

    Terms of use for all following snippets:
    - Free for use in both non-commercial and commercial games.
    - No credit required.
    - Edits and reposts allowed.

    Require Living Actor
    This was requested as a separate snippet from my Summon Actor plugin.
    Place the notetag <Require Ling Actor: n> in a skill or item notebox to only enable the skill / item if actor #n is alive.
    Download as plugin
    Spoiler: Code
                    Code:       
    1. /*:
    2. * @plugindesc Just the <Require Living Actor> notetag from Summon Actor.
    3. * @author LadyBaskerville
    4. *
    5. * @help
    6. * ---------------------
    7. *      Notetag
    8. * ---------------------
    9. * You can disable certain skills and items if an actor is dead.
    10. * Use the notetag
    11. *     <Require Living Actor: n>
    12. * to only enable the skill or item if actor n is alive.
    13. *
    14. * ---------------------
    15. *     Terms of use
    16. * ---------------------
    17. * - Free for use in both non-commercial and commercial games.
    18. * - You may repost and edit this plugin.
    19. * - If you use only this snippet from the Summon Actor plugin,
    20. *   credit to me as LadyBaskerville is optional.
    21. *
    22. */
    23. (function() {
    24. var LB = LB || {};
    25. LB.SummonActor = LB.SummonActor || {};
    26. LB.SummonActor.notetagsLoaded = false;
    27. // ---------------
    28. //   DataManager
    29. // ---------------
    30. DataManager.LB_processReqActNotetags = function(group) {
    31.     for (var i = 0; i < group.length; i++) {
    32.         if (group[i]) {
    33.             if (group[i].meta['Require Living Actor']) {
    34.                 group[i]._LB_requiredActor = Number(group[i].meta['Require Living Actor'].trim());
    35.             } else {
    36.                 group[i]._LB_requiredActor = null;
    37.             }
    38.         }
    39.     }
    40. };
    41. LB.SummonActor.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
    42. DataManager.isDatabaseLoaded = function() {
    43.     if (!LB.SummonActor.DataManager_isDatabaseLoaded.call(this)) {
    44.         return false;
    45.     }
    46.     // the database is loaded, we can now preload the notetags if we haven't already done it
    47.     if (!LB.SummonActor.notetagsLoaded) {
    48.         // preload skill and item notetags
    49.         this.LB_processReqActNotetags($dataSkills);
    50.         this.LB_processReqActNotetags($dataItems);
    51.         LB.SummonActor.notetagsLoaded = true;
    52.     }
    53.     return true;
    54. };
    55. // -------------------------
    56. //     Game_BattlerBase
    57. // -------------------------
    58. LB.SummonActor.Game_BattlerBase_canUse = Game_BattlerBase.prototype.canUse;
    59. Game_BattlerBase.prototype.canUse = function(item) {
    60.     if (!LB.SummonActor.Game_BattlerBase_canUse.call(this, item)) return false;
    61.     if (!item._LB_requiredActor) return true;
    62.     if ($gameActors.actor(item._LB_requiredActor).isDead()) return false;
    63.     return true;
    64. };
    65. })();
    复制代码


    Shift Enemies (Version 1.1.0)
    From this request thread. Allows you to shift enemy battlers outside the boundaries of the Troop window with notetags.
    Use <ShiftX: n> and <ShiftY: n> in the enemy notebox to shift the battler n pixels to the right and down, respectively. Use negative values for the opposite directions.
    Version 1.1.0: Added Plugin Parameters for default Shift values.
    Download as plugin
    When you create the .js file yourself, make sure it is named "ShiftEnemies.js".
    Spoiler: Code
                    Code:       
    1. /*:
    2. * @plugindesc v1.1.0 Lets you shift enemy battlers outside the boundaries of the Troop Window with notetags.
    3. * @author LadyBaskerville
    4. *
    5. * @param Default Shift X
    6. * @desc Default horizontal shift if no notetag is present
    7. * @default 0
    8. *
    9. * @param Default Shift Y
    10. * @desc Default vertical shift if no notetag is present
    11. * @default 0
    12. *
    13. * @help
    14. * ShiftEnemies.js
    15. * Version 1.1.0
    16. *
    17. * Use the following notetags in the enemy notebox:
    18. * <ShiftX: n> to shift the enemy n pixels to the right.
    19. * <ShiftY: n> to shift the enemy n pixels down.
    20. * Use negative values of n to shift the enemy in the opposite direction.
    21. *
    22. * If you want to offset many enemies by the same amount, you can specify
    23. * default values for Shift X and Shift Y in the Plugin Parameters.
    24. * Enemies without Shift notetags will be shifted by the values specified
    25. * in the parameters.
    26. *
    27. * Changelog:
    28. * Version 1.1.0
    29. * - Added Default parameters.
    30. * Version 1.0.0
    31. * - Finished the plugin.
    32. *
    33. * Free for use in both non-commercial and commercial games.
    34. * No credit required.
    35. * Edits and reposts allowed.
    36. */
    37. (function() {
    38. var defShiftX = Number(PluginManager.parameters('ShiftEnemies')['Default Shift X']) || 0;
    39. var defShiftY = Number(PluginManager.parameters('ShiftEnemies')['Default Shift Y']) || 0;
    40. _GameTroop_setup = Game_Troop.prototype.setup;
    41. Game_Troop.prototype.setup = function(troopId) {
    42.     _GameTroop_setup.call(this, troopId);
    43.    this.shiftEnemies();
    44. };
    45. Game_Troop.prototype.shiftEnemies = function() {
    46.    this._enemies.forEach(function(e) {
    47.        if (e.enemy().meta.ShiftX) {
    48.            e._screenX += Number(e.enemy().meta.ShiftX);
    49.        } else {
    50.            e._screenX += defShiftX;
    51.        }
    52.        if (e.enemy().meta.ShiftY) {
    53.            e._screenY += Number(e.enemy().meta.ShiftY);
    54.        } else {
    55.            e._screenY += defShiftY;
    56.        }
    57.    }, this);
    58. };
    59. // Compatability
    60. if (typeof Imported !== 'undefined' && Imported.YEP_BattleEngineCore) {
    61.    Window_EnemyVisualSelect.prototype.makeWindowBoundaries = function() {
    62.        if (!this._requestRefresh) return;
    63.        this._minX = -1 * this.standardPadding();
    64.        this._maxX = Graphics.boxWidth - this.width + this.standardPadding();
    65.        this._minY = -1 * this.standardPadding();
    66.        this._maxY = Graphics.boxHeight - this.height + this.standardPadding();
    67.    };
    68. }
    69. })();
    复制代码


    Shift Actors (Version 1.1.0)
    Allows you to shift SV actors with notetags
    Use <ShiftX: n> and <ShiftY: n> in the actor notebox to shift the battler n pixels to the right and down, respectively. Use negative values for the opposite directions.
    Version 1.1.0: Added Plugin Parameters for default Shift values.
    Download as plugin
    When you create the .js file yourself, make sure it is named "ShiftActors.js".
    Spoiler: Code
                    Code:       
    1. /*:
    2. * @plugindesc Lets you shift SV actors with notetags.
    3. * @author LadyBaskerville
    4. *
    5. * @param Default Shift X
    6. * @desc Default horizontal shift if no notetag is present
    7. * @default 0
    8. *
    9. * @param Default Shift Y
    10. * @desc Default vertical shift if no notetag is present
    11. * @default 0
    12. *
    13. * @help
    14. * ShiftActors.js
    15. * Version 1.1.0
    16. *
    17. * Use the following notetags in the actor notebox:
    18. * <ShiftX: n> to shift the actor n pixels to the right.
    19. * <ShiftY: n> to shift the actor n pixels down.
    20. * Use negative values of n to shift the actor in the opposite direction.
    21. *
    22. * If you want to offset many actors by the same amount, you can specify
    23. * default values for Shift X and Shift Y in the Plugin Parameters.
    24. * Actors without Shift notetags will be shifted by the values specified
    25. * in the parameters.
    26. *
    27. * Free for use in both non-commercial and commercial games.
    28. * No credit required.
    29. * Edits and reposts allowed.
    30. */
    31. (function() {
    32. var defShiftX = Number(PluginManager.parameters('ShiftActors')['Default Shift X']) || 0;
    33. var defShiftY = Number(PluginManager.parameters('ShiftActors')['Default Shift Y']) || 0;
    34. _Sprite_Actor_setActorHome = Sprite_Actor.prototype.setActorHome;
    35. Sprite_Actor.prototype.setActorHome = function(index) {
    36.    _Sprite_Actor_setActorHome.call(this, index);
    37.    var id = this._actor._actorId;
    38.    if ($dataActors[id].meta.ShiftX) {
    39.        this.setHome(this._homeX + Number($dataActors[id].meta.ShiftX), this._homeY);
    40.    } else {
    41.        this.setHome(this._homeX + defShiftX, this._homeY);
    42.    }
    43.    if ($dataActors[id].meta.ShiftY) {
    44.        this.setHome(this._homeX, this._homeY + Number($dataActors[id].meta.ShiftY));
    45.    } else {
    46.        this.setHome(this._homeX, this._homeY + defShiftY);
    47.    }
    48. };
    49. })();
    复制代码


    Enemy Placement (Version 1.0.1)
    Lets you place enemy battlers using a semi-dynamic formula. More information in the Help file.
    Download as plugin
    When you create the .js file yourself, make sure it is named "EnemyPlacement.js".
    Spoiler: Code
                    Code:       
    1. /*:
    2. * @plugindesc v1.0.1 Lets you place enemy battlers using a semi-dynamic formula.
    3. * @author LadyBaskerville
    4. *
    5. * @param Use Default Placement
    6. * @desc If true, all enemies with no notetags will be placed at the default position specified in the parameters below.
    7. * @type boolean
    8. * @default false
    9. *
    10. * @param Default X Position
    11. * @desc X position if no notetag is present. Default: 16 + (troopSize + 2) * 32 - index * 32
    12. * @default 16 + (troopSize + 2) * 32 - index * 32
    13. *
    14. * @param Default Y Position
    15. * @desc Y position if no notetag is present. Default: screenHeight - statusHeight - troopSize * 48 + (index+1) * 48 - 32
    16. * @default screenHeight - statusHeight - troopSize * 48 + (index+1) * 48 - 32
    17. *
    18. * @help
    19. * EnemyPlacement.js
    20. * Version 1.0.1
    21. *
    22. * Use the following notetags in the enemy notebox:
    23. *
    24. * <XPosEval: [expression]> and <YPosEval: [expression]>
    25. * to place the enemy graphic at the X/Y position to which the Javascript line
    26. * [expression] evaluates. You can also use pure numbers.
    27. *
    28. * <UseDefaultXPos> and <UseDefaultYPos>
    29. * to place the enemy graphic at the default position specified
    30. * in this plugin's parameters.
    31. *
    32. * The plugin parameters allow you to set default formulas for the X and Y
    33. * positions. Set the parameter "Use Default Placement" to true if all
    34. * enemies without their own <X/YPosEval> notetags should use these default
    35. * values. You can also keep "Use Default Placement" set to false and use
    36. * the <UseDefaultX/YPos> notetags for each enemy that should be placed
    37. * at the default position.
    38. *
    39. * You can use the following variables as part of [expression]:
    40. * screenWidth - the width of the game window in pixels
    41. * screenHeight - the height of the game window in pixels
    42. * troopSize - the number of enemies in the troop
    43. * index - the index of the enemy within the troop
    44. * statusHeight - the height of the status window
    45. * (If you know what you are doing, you can also use:
    46. *  this - the Game_Troop object
    47. *  e - the Game_Enemy object)
    48. * For reference, the default X/Y positions in the parameters are:
    49. * X: 16 + (troopSize + 2) * 32 - index * 32
    50. * Y: screenHeight - statusHeight - troopSize * 48 + (index+1) * 48 - 32
    51. *
    52. * Changelog:
    53. * Version 1.0.1
    54. * - Fixed a mistake in the calculation of statusHeight.
    55. * Version 1.0.0
    56. * - Finished the plugin.
    57. *
    58. * Free for use in both non-commercial and commercial games.
    59. * No credit required.
    60. * Edits and reposts allowed.
    61. */
    62. (function() {
    63. var baseStatusHeight = 4;
    64. // Compatability
    65. if (typeof Imported !== 'undefined' && Imported.YEP_BattleEngineCore) {
    66.    Window_EnemyVisualSelect.prototype.makeWindowBoundaries = function() {
    67.        if (!this._requestRefresh) return;
    68.        this._minX = -1 * this.standardPadding();
    69.        this._maxX = Graphics.boxWidth - this.width + this.standardPadding();
    70.        this._minY = -1 * this.standardPadding();
    71.        this._maxY = Graphics.boxHeight - this.height + this.standardPadding();
    72.    };
    73.    baseStatusHeight = eval(Yanfly.Param.BECCommandRows);
    74. }
    75. var defXPosEval = PluginManager.parameters('EnemyPlacement')['Default X Position'] || 0;
    76. var defYPosEval = PluginManager.parameters('EnemyPlacement')['Default Y Position'] || 0;
    77. var useDef = PluginManager.parameters('EnemyPlacement')['Use Default Placement'] == 'true';
    78. _GameTroop_setup = Game_Troop.prototype.setup;
    79. Game_Troop.prototype.setup = function(troopId) {
    80.     _GameTroop_setup.call(this, troopId);
    81.    this.placeEnemies();
    82. };
    83. Game_Troop.prototype.placeEnemies = function() {
    84.    var screenWidth = Graphics.boxWidth;
    85.    var screenHeight = Graphics.boxHeight;
    86.    var troopSize = this._enemies.length;
    87.    var statusHeight = baseStatusHeight * Window_Base.prototype.lineHeight.call(this);
    88.    statusHeight += Window_Base.prototype.standardPadding.call(this) * 2;
    89.    for (var index = 0; index < this._enemies.length; index ++) {
    90.        var e = this._enemies[index];
    91.        if (e.enemy().meta.XPosEval) {
    92.            e._screenX = eval(e.enemy().meta.XPosEval);
    93.        } else if (useDef || e.enemy().meta.UseDefaultXPos) {
    94.            e._screenX = eval(defXPosEval);
    95.        }
    96.        if (e.enemy().meta.YPosEval) {
    97.            e._screenY = eval(e.enemy().meta.YPosEval);
    98.        } else if (useDef || e.enemy().meta.UseDefaultYPos) {
    99.            e._screenY = eval(defYPosEval);
    100.        }
    101.    }
    102. };
    103. })();
    复制代码



    Weapon Modifier
    From this request thread. Lets you specify a Modifier formula (number or javascript) in a weapon notetag and call it in the damage formula. More information in the Help file.
    Download as plugin
    When you create the .js file yourself, make sure it is named "WeaponModifier.js".
    Spoiler: Code
                    Code:       
    1. /*:
    2. * @plugindesc Specify an additional formula for weapons to include in the damage formula.
    3. * @author LadyBaskerville
    4. *
    5. * @param Default weapon modifier
    6. * @desc The value used for 'wm' if the equipped weapon has no Modifier tag.
    7. * @default 0
    8. *
    9. * @param Default enemy modifier
    10. * @desc The value used for 'wm' if the attacker is an enemy.
    11. * @default 0
    12. *
    13. * @help
    14. * WeaponModifier.js
    15. *
    16. * Use the notetag <Modifier: x> in the weapon notebox to specify a Weapon
    17. * Modifier formula.
    18. * x can be a number or line of Javascript code that uses the same context
    19. * as a skill's damage formula. ('a' = the user, 'b' = the target,
    20. * 'v[n]' = the value of variable n, 'this' = the Game_Action object)
    21. *
    22. * Example: <Modifier: a.mhp / a.hp>
    23. * Gives the weapon a higher Modifier if the user has less HP.
    24. *
    25. * To use the Modifier in damage calculation, include 'wm' in the damage
    26. * formula.
    27. *
    28. * Example: a.atk * 4 - b.def * 2 + wm * 0.2
    29. *
    30. * Free for use in both non-commercial and commercial games.
    31. * No credit required.
    32. * Edits and reposts allowed.
    33. */
    34. (function() {
    35. var params = PluginManager.parameters('WeaponModifier');
    36. var weaponDefault = params['Default weapon modifier'];
    37. var enemyDefault = params['Default enemy modifier'];
    38. Game_Battler.prototype.getWeaponModifier = function() {
    39.     if (this.isActor()) {
    40.         var w = $dataWeapons[this._equips[0]._itemId];
    41.         if (w.meta.Modifier) {
    42.             return w.meta.Modifier;
    43.         } else {
    44.             return weaponDefault;
    45.         }
    46.     } else {
    47.         return enemyDefault;
    48.     }
    49. };
    50. Game_Action.prototype.evalDamageFormula = function(target) {
    51.     try {
    52.         var item = this.item();
    53.         var a = this.subject();
    54.         var b = target;
    55.         var v = $gameVariables._data;
    56.         var wm = eval(a.getWeaponModifier());
    57.         var sign = ([3, 4].contains(item.damage.type) ? -1 : 1);
    58.         var value = Math.max(eval(item.damage.formula), 0) * sign;
    59.         if (isNaN(value)) value = 0;
    60.         return value;
    61.     } catch (e) {
    62.         return 0;
    63.     }
    64. };
    65. })();
    复制代码


    Weapon Over Actor (Version 1.0.1)
    From this request thread. Lets you change the order in which Sideview actor and weapon are drawn. Use the notetag <Weapon Over Actor> in the actor or weapon notebox to show the weapon image on top of the actor image. Warning: Might not work when changing weapons during battle.
    Download as plugin
    Spoiler: Code
                    Code:       
    1. /*:
    2. * @plugindesc v1.0.1 For sideview battle, change the order in which weapon and actor are drawn.
    3. * @author LadyBaskerville
    4. *
    5. * @help
    6. * Use the notetag <Weapon Over Actor> in the actor or weapon notebox
    7. * to draw the weapon image on top of the actor image.
    8. * Might not work when changing weapons during battle.
    9. *
    10. * Free for use in both non-commercial and commercial games.
    11. * No credit required.
    12. * Edits and reposts allowed.
    13. */
    14. Sprite_Actor.prototype.initMembers = function() {
    15.     Sprite_Battler.prototype.initMembers.call(this);
    16.     this._battlerName = '';
    17.     this._motion = null;
    18.     this._motionCount = 0;
    19.     this._pattern = 0;
    20.    this.createSprites();
    21. };
    22. Sprite_Actor.prototype.createSprites = function() {
    23.    this.createShadowSprite();
    24.    if (this._actor && ($dataActors[this._actor._actorId].meta["Weapon Over Actor"] ||
    25.                         ($dataWeapons[this._actor._equips[0]._itemId] && $dataWeapons[this._actor._equips[0]._itemId].meta["Weapon Over Actor"]))) {
    26.        this.createMainSprite();
    27.        this.createWeaponSprite();
    28.    } else {
    29.        this.createWeaponSprite();
    30.        this.createMainSprite();
    31.    }
    32.    this.createStateSprite();
    33. };
    34. Sprite_Actor.prototype.setBattler = function(battler) {
    35.     Sprite_Battler.prototype.setBattler.call(this, battler);
    36.     var changed = (battler !== this._actor);
    37.     if (changed) {
    38.         this._actor = battler;
    39.         if (battler) {
    40.             this.setActorHome(battler.index());
    41.         }
    42.        this.createSprites();
    43.         this.startEntryMotion();
    44.         this._stateSprite.setup(battler);
    45.     }
    46. };
    复制代码


    Reflect onto Opponent
    From this request thread. Changes the way magic reflection works - with the plugin, magic will allways be reflected onto the opponents' unit, even if an ally cast the spell. More information in the Help file.
    Download as plugin
    Spoiler: Code
                    Code:       
    1. /*:
    2. * @plugindesc Changes Magic Reflection: Magic is always reflected onto an opponent.
    3. * @author LadyBaskerville
    4. *
    5. * @help
    6. * Version 1.0.1
    7. *
    8. * With this plugin enabled, all skill with Hit Type: Magical Attack
    9. * will be reflected onto an opponent when Magic Reflection occurs.
    10. * If the attacker is an opponent, the magic will be reflected onto
    11. * the attacker (same as default reflection). If the attacker is
    12. * an ally, the magic will be reflected onto a random member of the
    13. * opponents' unit.
    14. *
    15. * You can let skills of other Hit Types use Magic Reflection
    16. * by placing the Notetag <EnableMRF> in the skill's notebox.
    17. *
    18. * Free for use in both non-commercial and commercial games.
    19. * No credit required.
    20. * Edits and reposts allowed.
    21. */
    22. _BattleManager_invokeMagicReflection = BattleManager.invokeMagicReflection;
    23. BattleManager.invokeMagicReflection = function(subject, target) {
    24.    if (subject.opponentsUnit().members().contains(target)) {
    25.        _BattleManager_invokeMagicReflection.call(this, subject, target);
    26.    } else {
    27.        var randOpp = subject.opponentsUnit().randomTarget();
    28.        if (randOpp) {
    29.            var tempSubj = this._subject;
    30.            subject = randOpp;
    31.            this._subject = subject;
    32.            _BattleManager_invokeMagicReflection.call(this, subject, target);
    33.            this._subject = tempSubj;
    34.        }
    35.    }
    36. };
    37. Game_Action.prototype.itemMrf = function(target) {
    38.     if (this.isMagical() || $dataSkills[this._item._itemId].meta.EnableMRF) {
    39.         return target.mrf;
    40.     } else {
    41.         return 0;
    42.     }
    43. };
    复制代码


    Battle Log Weaknesses
    From this thread. Shows a message in the Battle Log when an elemental weakness or resistance is hit (Element Rate above or below 100%, respectively). Note: The plugin is not extensively tested and probably won't play nice with larger battle engine type plugins because it's overriding the Window_BattleLog.displayActionResults function. I may add compatibility with Yanfly's Battle Engine Core or other (free, unobfuscated) battle engine plugins at request, provided they don't make extensive changes to how the battle log is handled.
    Download as Plugin
    When you create the .js file yourself, make sure it is named "LB_BattleLogWeaknesses.js".
    Spoiler: Code
                    JavaScript:       
    1. /*:
    2. * @plugindesc Show elemental weaknesses/resistances in the battle log
    3. * @author LadyBaskerville
    4. *
    5. * @help
    6. * Version 1.0.0
    7. * LB_BattleLogWeaknesses.js
    8. *
    9. * Free for use in both non-commercial and commercial games.
    10. * Free to edit and repost.
    11. * Credit appreciated, but not required.
    12. *
    13. * @param Weakness Message
    14. * @desc The message that is displayed when a weakness is hit
    15. * @default Weakpoint!
    16. *
    17. * @param Resistance Message
    18. * @desc The message that is displayed when a resistance is hit
    19. * @default Resist!
    20. *
    21. */
    22. var LB = LB || {};
    23. LB.BattleLogWeaknesses = LB.BattleLogWeaknesses || {};
    24. LB.BattleLogWeaknesses.weakMsg = String(PluginManager.parameters('LB_BattleLogWeaknesses')['Weakness Message']);
    25. LB.BattleLogWeaknesses.resistMsg = String(PluginManager.parameters('LB_BattleLogWeaknesses')['Resistance Message']);
    26. // OVERWRITE
    27. Window_BattleLog.prototype.displayActionResults = function(subject, target) {
    28.     if (target.result().used) {
    29.         this.push('pushBaseLine');
    30.         this.displayCritical(target);
    31.         this.LB_displayWeakness(target);
    32.         this.push('popupDamage', target);
    33.         this.push('popupDamage', subject);
    34.         this.displayDamage(target);
    35.         this.displayAffectedStatus(target);
    36.         this.displayFailure(target);
    37.         this.push('waitForNewLine');
    38.         this.push('popBaseLine');
    39.     }
    40. };
    41. // new
    42. Window_BattleLog.prototype.LB_displayWeakness = function(target) {
    43.     if (target.result().elementRate > 1) {
    44.         this.push('addText', LB.BattleLogWeaknesses.weakMsg);
    45.     } else if (target.result().elementRate < 1){
    46.         this.push('addText', LB.BattleLogWeaknesses.resistMsg);
    47.     }
    48. };
    49. LB.BattleLogWeaknesses.Game_ActionResult_clear = Game_ActionResult.prototype.clear;
    50. Game_ActionResult.prototype.clear = function() {
    51.     LB.BattleLogWeaknesses.Game_ActionResult_clear.call(this);
    52.     this.elementRate = 1;
    53. };
    54. LB.BattleLogWeaknesses.Game_Action_apply = Game_Action.prototype.apply;
    55. Game_Action.prototype.apply = function(target) {
    56.     LB.BattleLogWeaknesses.Game_Action_apply.call(this, target);
    57.     let result = target.result();
    58.     if (result.isHit()) {
    59.         result.elementRate = this.calcElementRate(target);
    60.     }
    61. };
    复制代码


    Custom Item Choices  Note: This version of the plugin is outdated; the plugin now has its own thread here.
    Only show specific kinds of items in the Select Item window, for when the Item Type distinction in the database isn't enough. Use the notetag <type:[customType]> in the item's notebox. Before using the Select Item command in an event, use the plugin command SetSelectItemType [customType] to only show items with the corresponding notetag in the Select Item window. Use the plugin command SetSelectItemType 0 to return to the default behavior (showing all regular items/key items/hidden items A/B in the selection window).

    Spoiler: Usage Example
    Here's an bare-bones example for how this plugin can be used to select seeds for planting as part of a simple farming game:

    Spoiler: Code
                    JavaScript:       
    1. /*:
    2. * @plugindesc Only show specific custom types of items in the Select Item window.
    3. * @author LadyBaskerville
    4. *
    5. * @help
    6. * CustomItemChoices
    7. * Version 1.0.0
    8. * by LadyBaskerville
    9. *
    10. * Item notetag: <type:[customType]>
    11. *
    12. * Before using the Select Item command in an event, use the plugin command
    13. * SetSelectItemType [customType]
    14. * to only show items with the notetag <type:[customType]> in the Select Item window.
    15. *
    16. * Use the plugin command
    17. * SetSelectItemType 0
    18. * to return to the default behavior (showing all items in the selection window).
    19. *
    20. * Free for use in both non-commercial and commercial games.
    21. * Credit appreciated, but not required.
    22. *
    23. */
    24. (function() {
    25. var LB = LB || {};
    26. LB.MoreItemChoices = LB.MoreItemChoices || {};
    27. LB.MoreItemChoices.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    28. Game_Interpreter.prototype.pluginCommand = function(command, args) {
    29.     LB.MoreItemChoices.Game_Interpreter_pluginCommand.call(this, command, args);
    30.     if (command == 'SetSelectItemType') {
    31.         if (args[0] == '0') {
    32.             $gameMessage.setItemChoiceCustomType(0);
    33.         }
    34.         else {
    35.             $gameMessage.setItemChoiceCustomType(args[0]);
    36.         }
    37.     }
    38.     return false;
    39. };
    40. Game_Message.prototype.setItemChoiceCustomType = function(customType) {
    41.     this._itemChoiceCustomType = customType;
    42. };
    43. Game_Message.prototype.itemChoiceCustomType = function(customType) {
    44.     return this._itemChoiceCustomType;
    45. };
    46. Window_EventItem.prototype.includes = function(item) {
    47.     var itypeId = $gameMessage.itemChoiceItypeId();
    48.     var customType = $gameMessage.itemChoiceCustomType();
    49.     if (customType == 0 || customType == '') {
    50.         return DataManager.isItem(item) && item.itypeId === itypeId;
    51.     } else {
    52.     return DataManager.isItem(item) && item.itypeId === itypeId && item.meta.type === customType;
    53.     }
    54. };
    55. })();
    复制代码


    I hope someone finds use in some of these small snippets



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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-8-1 07:37 , Processed in 0.130494 second(s), 53 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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