查看: 1013|回复: 10

[有事请教] 为什么负重插件MrTS_LimitedInventory.js一直出现错误?

[复制链接]
梦石
0
星屑
268
在线时间
33 小时
注册时间
2024-4-10
回帖
33
发表于 2024-4-22 21:09:57 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

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

×
这是关于负重系统的插件,使用上很简单,本来测试也没什么问题

但最近才发现,装备穿回的时候就会出现错误,游戏崩溃,道具栏新增删除都没有问题

就只有装备穿回的时候,游戏就崩溃

螢幕擷取畫面 2024-04-22 204955.jpg

  1. //=============================================================================
  2. // MrTS_LimitedInventory.js
  3. //=============================================================================

  4. /*:
  5. * @plugindesc Limits inventory space by weight or item numbers.
  6. * @author Mr. Trivel
  7. *
  8. * @param Limit Mode
  9. * @desc Which mode to use? weight/number
  10. * Default: number
  11. * @default number
  12. *
  13. * @param Default Limit
  14. * @desc Inventory limit.
  15. * Default: 30
  16. * @default 30
  17. *
  18. * @param Default Weight
  19. * @desc If using 'weight' mode, how much items weight by default?
  20. * Default: 1
  21. * @default 1
  22. *
  23. * @param Show Window
  24. * @desc Show inventory limit window in item menu? true/false
  25. * Default: True
  26. * @default True
  27. *
  28. * @param Limit Text
  29. * @desc How will limit be named in Window?
  30. * Default: Limit:
  31. * @default Limit:
  32. *
  33. * @help
  34. * --------------------------------------------------------------------------------
  35. * Terms of Use
  36. * --------------------------------------------------------------------------------
  37. * Don't remove the header or claim that you wrote this plugin.
  38. * Credit Mr. Trivel if using this plugin in your project.
  39. * Free for commercial and non-commercial projects.
  40. * --------------------------------------------------------------------------------
  41. * Version 1.0
  42. * --------------------------------------------------------------------------------
  43. *
  44. * --------------------------------------------------------------------------------
  45. * Item Tags
  46. * --------------------------------------------------------------------------------
  47. * <Weight: [AMOUNT]>
  48. * If using 'weight' mode, use the following to determine the weight of item.
  49. *
  50. * Example:
  51. * <Weight: 5>
  52. * --------------------------------------------------------------------------------
  53. *
  54. * --------------------------------------------------------------------------------
  55. * Equipment Tags
  56. * --------------------------------------------------------------------------------
  57. * <InvLimitChange: [AMOUNT]>
  58. * Changes inventory limit by AMOUNT while item is equipped. Works for both modes.
  59. *
  60. * <InvLimitChange: -5>
  61. * <InvLimitChange: 10>
  62. * --------------------------------------------------------------------------------
  63. *
  64. * --------------------------------------------------------------------------------
  65. * Plugin Commands
  66. * --------------------------------------------------------------------------------
  67. * InventoryLimit Add [AMOUNT] - Adds Amount to limit.
  68. * InventoryLimit Sub [AMOUNT] - Removes Amount from limit.
  69. * InventoryLimit Ignore - Ignores inventory limit when adding items
  70. * InventoryLimit StopIgnore - Stops ignoring inventory limit when adding items
  71. *
  72. * Examples:
  73. * InventoryLimit Add 10
  74. * InventoryLimit Sub 5
  75. * InventoryLimit Ignore
  76. * InventoryLimit StopIgnore
  77. * --------------------------------------------------------------------------------
  78. *
  79. * --------------------------------------------------------------------------------
  80. * Script Calls
  81. * --------------------------------------------------------------------------------
  82. * $gameParty.getInventorySpaceLeft() - returns amount of space left
  83. * $gameParty.getInventorySpaceTotal() - returns total amount of space
  84. * $gameParty.getInventorySpaceUsed() - returns used amount of space
  85. * --------------------------------------------------------------------------------
  86. *
  87. * --------------------------------------------------------------------------------
  88. * Version History
  89. * --------------------------------------------------------------------------------
  90. * 1.0 - Release
  91. */

  92. (function() {
  93.         var parameters = PluginManager.parameters('MrTS_LimitedInventory');
  94.         var paramLimitMode = String(parameters['Limit Mode'] || "number");
  95.         var paramDefaultLimit = Number(parameters['Default Limit'] || 30);
  96.         var paramDefaultWeight = Number(parameters['Default Weight'] || 1);
  97.         var paramShowWindow = (parameters['Show Window'] || "true").toLowerCase() === "true";
  98.         var paramLimitText = String(parameters['Limit Text'] || "Limit:");

  99.         //--------------------------------------------------------------------------
  100.         // Game_Interpreter
  101.         //
  102.        
  103.         var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  104.         Game_Interpreter.prototype.pluginCommand = function(command, args) {
  105.                 _Game_Interpreter_pluginCommand.call(this, command, args);
  106.                 if (command.toLowerCase() === "inventorylimit") {
  107.                         switch (args[0].toUpperCase())
  108.                         {
  109.                                 case 'ADD':
  110.                                 {
  111.                                         $gameParty.increaseInventorySpace(Number(args[1]));
  112.                                 } break;
  113.                                 case 'SUB':
  114.                                 {
  115.                                         $gameParty.decreaseInventorySpace(Number(args[1]));
  116.                                 } break;
  117.                                 case 'IGNORE':
  118.                                 {
  119.                                         $gameParty._ignoreInvLimit = true;
  120.                                 } break;
  121.                                 case 'STOPIGNORE':
  122.                                 {
  123.                                         $gameParty._ignoreInvLimit = false;
  124.                                 } break;                               
  125.                         }
  126.                 }
  127.         };

  128.         //--------------------------------------------------------------------------
  129.         // Game_Party

  130.         var _Game_Party_initialize = Game_Party.prototype.initialize;
  131.         Game_Party.prototype.initialize = function() {
  132.                 _Game_Party_initialize.call(this);
  133.                 this._inventorySpace = paramDefaultLimit;
  134.                 this._modifiedInvSpace = 0;
  135.                 this._ignoreInvLimit = false;
  136.         };

  137.         Game_Party.prototype.increaseInventorySpace = function(amount) {
  138.                 this._modifiedInvSpace += amount;
  139.         };

  140.         Game_Party.prototype.decreaseInventorySpace = function(amount) {
  141.                 this.increaseInventorySpace(-amount);
  142.         };

  143.         Game_Party.prototype.getInventorySpaceTotal = function() {
  144.                 var base = this._inventorySpace;
  145.                 var mod = this._modifiedInvSpace;
  146.                 var equipment = 0;
  147.                 for (var i = 0; i < this.members().length; i++) {
  148.                         equipment += this.members()[i].getInventorySpaceBonus();
  149.                 }
  150.                 return Math.max(0, (base+mod+equipment));
  151.         };

  152.         Game_Party.prototype.getInventorySpaceUsed = function() {
  153.                 var used = 0;
  154.                 for (var i = 0; i < this.allItems().length; i++) {
  155.                         switch(paramLimitMode)
  156.                         {
  157.                                 case 'number':
  158.                                 {
  159.                                         used += this.numItems(this.allItems()[i]);
  160.                                 } break;
  161.                                 case 'weight':
  162.                                 {
  163.                                         var weight = this.allItems()[i].meta.Weight ? Number(this.allItems()[i].meta.Weight) : paramDefaultWeight;
  164.                                         used += this.numItems(this.allItems()[i]) * weight;
  165.                                 } break;
  166.                                
  167.                         }
  168.                 }
  169.                 return used;
  170.         };

  171.         Game_Party.prototype.getInventorySpaceLeft = function() {
  172.                 return this.getInventorySpaceTotal() - this.getInventorySpaceUsed();
  173.         };

  174.         Game_Party.prototype.getItemWeight = function(item) {
  175.                 switch(paramLimitMode)
  176.                 {
  177.                         case 'number':
  178.                         {
  179.                                 return 1;
  180.                         } break;
  181.                         case 'weight':
  182.                         {
  183.                                 var weight = item.meta.Weight ? Number(item.meta.Weight) : paramDefaultWeight;
  184.                                 return weight;
  185.                         } break;
  186.                        
  187.                 }
  188.                 return 1;
  189.         };

  190.         var _Game_Party_gainItem = Game_Party.prototype.gainItem;
  191.         Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
  192.                 if (amount < 0 || this._ignoreInvLimit) _Game_Party_gainItem.call(this, item, amount, includeEquip);
  193.                 else
  194.                 {
  195.                         var weight = this.getItemWeight(item);
  196.                         var tWeight = weight * amount;
  197.                         var aWeight = this.getInventorySpaceLeft();
  198.                         if ((aWeight - tWeight) >= 0) _Game_Party_gainItem.call(this, item, amount, includeEquip);
  199.                         else
  200.                         {
  201.                                 var newAmount = Math.floor(aWeight/weight);
  202.                                 if (newAmount > 0)
  203.                                         _Game_Party_gainItem.call(this, item, newAmount, includeEquip);
  204.                         }
  205.                 }
  206.         };

  207.         Game_Actor.prototype.getInventorySpaceBonus = function() {
  208.                 var bonus = 0;
  209.                 for (var i = 0; i < this.equips().length; i++) {
  210.                         if (!this.equips()[i]) continue;
  211.                         if (this.equips()[i].meta.InvLimitChange)
  212.                                 bonus += Number(this.equips()[i].meta.InvLimitChange);
  213.                 }
  214.                 return bonus;
  215.         };

  216.         //--------------------------------------------------------------------------
  217.         // Window_InventoryLimit
  218.         //
  219.         // Shows how much is left.
  220.        
  221.         function Window_InventoryLimit() {
  222.                 this.initialize.apply(this, arguments);       
  223.         };
  224.        
  225.         Window_InventoryLimit.prototype = Object.create(Window_Base.prototype);
  226.         Window_InventoryLimit.prototype.constructor = Window_InventoryLimit;
  227.        
  228.         Window_InventoryLimit.prototype.initialize = function(x, y, w, h) {
  229.                 Window_Base.prototype.initialize.call(this, x, y, w, h);
  230.                 this.refresh();
  231.         };
  232.        
  233.         Window_InventoryLimit.prototype.refresh = function() {
  234.                 this.contents.clear();
  235.                 var u = $gameParty.getInventorySpaceUsed();
  236.                 var t = $gameParty.getInventorySpaceTotal();
  237.                 this.drawText(paramLimitText + " " + u + "/" + t, 0, 0);
  238.         };

  239.         //--------------------------------------------------------------------------
  240.         // Scene_Item
  241.         //

  242.         var _Scene_Item_create = Scene_Item.prototype.create;
  243.         Scene_Item.prototype.create = function() {
  244.                 _Scene_Item_create.call(this);
  245.                 if (paramShowWindow)
  246.                         this.createLimitWindow();
  247.         };

  248.         Scene_Item.prototype.createLimitWindow = function() {
  249.                 var wx = this._itemWindow.x;
  250.                 var ww = this._itemWindow.width;
  251.                 var wh = this._itemWindow.fittingHeight(1);
  252.                 this._itemWindow.height = this._itemWindow.height - wh;
  253.                 this._itemWindow.refresh();
  254.                 var wy = this._itemWindow.y + this._itemWindow.height;
  255.                 this._invLimitWindow = new Window_InventoryLimit(wx, wy, ww, wh);
  256.                 this.addWindow(this._invLimitWindow);
  257.         };

  258.         var _Scene_Item_useItem = Scene_Item.prototype.useItem;
  259.         Scene_Item.prototype.useItem = function() {
  260.                 _Scene_Item_useItem.call(this);
  261.                 if (this._invLimitWindow) this._invLimitWindow.refresh();
  262.         };
  263. })();
复制代码


这是跳出错误代码的位置

  1.                         {
  2.                                 var weight = item.meta.Weight ? Number(item.meta.Weight) : paramDefaultWeight;
  3.                                 return weight;
  4.                         } break;
  5.                        
  6.                 }
  7.                 return 1;
  8.         };

  9.         var _Game_Party_gainItem = Game_Party.prototype.gainItem;
  10.         Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
  11.                 if (amount < 0 || this._ignoreInvLimit) _Game_Party_gainItem.call(this, item, amount, includeEquip);
  12.                 else
复制代码



拜托了,真是完全找不到原因

点评

如果想治标不治本的话可以把问号前面的 "item.meta.Weight" 改成 "item&&item.meta&&item.meta.Weight" 这种连锁检查的写法。  发表于 2024-4-23 16:15
梦石
0
星屑
1333
在线时间
471 小时
注册时间
2012-4-8
回帖
314
发表于 2024-4-22 21:20:24 | 显示全部楼层
可能是 Scene_Equip.prototype.onItemOk 获取了错误的 item ?
可以看看 this.actor().changeEquip(this._slotWindow.index(), this._itemWindow.item());
看看 _itemWindow Window_EquipItem 究竟给了什么,干了什么
pokemon 和 digimon 正在路上
回复

使用道具 举报

梦石
0
星屑
10274
在线时间
1919 小时
注册时间
2020-1-2
回帖
1043
发表于 2024-4-22 21:55:49 | 显示全部楼层
这是另一个重量你尝试看看如果需要仓库的我到时候再发但是是不同作者的插件

DEX_WeightLimit.zip

3.15 KB, 下载次数: 11

B站没人气的夏目漠漠,直播间:5378938实用插件教程点击红字传送
回复

使用道具 举报

梦石
0
星屑
268
在线时间
33 小时
注册时间
2024-4-10
回帖
33
 楼主| 发表于 2024-4-22 22:32:25 | 显示全部楼层
xiamumomo 发表于 2024-4-22 21:55
这是另一个重量你尝试看看如果需要仓库的我到时候再发但是是不同作者的插件 ...

谢谢,感觉用起来差不多,但这个没出错误

仓库的插件我也满需要的...目前是用PH_Warehouse,就介面稍嫌不满意
回复

使用道具 举报

梦石
0
星屑
268
在线时间
33 小时
注册时间
2024-4-10
回帖
33
 楼主| 发表于 2024-4-22 22:47:24 | 显示全部楼层
505681468 发表于 2024-4-22 21:20
可能是 Scene_Equip.prototype.onItemOk 获取了错误的 item ?
可以看看 this.actor().changeEquip(this._s ...

谢谢帮忙,但这我看不懂...还是想修好这个错误...
回复

使用道具 举报

梦石
0
星屑
268
在线时间
33 小时
注册时间
2024-4-10
回帖
33
 楼主| 发表于 2024-4-22 23:48:52 | 显示全部楼层
xiamumomo 发表于 2024-4-22 21:55
这是另一个重量你尝试看看如果需要仓库的我到时候再发但是是不同作者的插件 ...

研究很久有两个小问题...
1.刚进入游戏他不会运行,要点一次道具栏才会启动,很奇怪
2.游戏内没办法提高负重上限...
回复

使用道具 举报

梦石
0
星屑
268
在线时间
33 小时
注册时间
2024-4-10
回帖
33
 楼主| 发表于 2024-4-23 01:03:10 | 显示全部楼层
var weight = item.meta.Weight ? Number(item.meta.Weight) : paramDefaultWeight;
return weight;

var weight = this.getItemWeight(item);
var tWeight = weight * amount;

不管怎么修永远都会出现194跟207的错误...这是插件的BUG吗....
回复

使用道具 举报

梦石
0
星屑
268
在线时间
33 小时
注册时间
2024-4-10
回帖
33
 楼主| 发表于 2024-4-23 01:30:18 | 显示全部楼层
好吧,不是插件BUG

我重开专案只装负重插件就一切正常
我以为有插件冲突,所以把原专案的插件全都关闭,问题依旧
可能以前有动到基本程式,所以把新专案的js档案盖上,问题依旧
游戏内有事件脚本写错? 我把事件全部关闭,问题依旧

................我能关的都关完了,还有哪里有可能出问题阿....
回复

使用道具 举报

梦石
0
星屑
1333
在线时间
471 小时
注册时间
2012-4-8
回帖
314
发表于 2024-4-23 03:19:06 | 显示全部楼层
本帖最后由 505681468 于 2024-4-23 03:27 编辑

[原因]
穿脱装备的时候,会脱空装备,脚本做的判断漏判了
也可能是版本更新的原因,导致的错误

[解决]
试试在脚本后面补一句

[测试]
简单看了下穿脱,没发现啥,原理应该就是这样,而且环境不一样,有其他问题可以说说

  1.         var _Game_Party_gainItem_fix = Game_Party.prototype.gainItem;
  2.         Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
  3.             var container = this.itemContainer(item);
  4.             if (container) {
  5.                 _Game_Party_gainItem_fix.call(this, item, amount, includeEquip)
  6.             }
  7.         };
复制代码




另外,这个好像是背包负重?一开始还以为是装备负重
pokemon 和 digimon 正在路上
回复

使用道具 举报

梦石
0
星屑
268
在线时间
33 小时
注册时间
2024-4-10
回帖
33
 楼主| 发表于 2024-4-23 19:52:36 | 显示全部楼层
最后我发现还是插件的问题,当Limit Mode选择weight的时候就会出现,选择number的时候运作就正常,最后修改后的答案是这个,假设以后还有人有一样的问题希望能帮到你

  1. Game_Party.prototype.getItemWeight = function(item) {
  2.     switch(paramLimitMode) {
  3.         case 'number':
  4.             return 1;
  5.             break;
  6.         case 'weight':
  7.             if (item && item.meta && item.meta.Weight) {
  8.                 return parseFloat(item.meta.Weight) || paramDefaultWeight;
  9.             } else {
  10.                 return paramDefaultWeight;
  11.             }
  12.             break;
  13.     }
  14.     return 1;
  15. };
复制代码

评分

参与人数 1赞 +1 收起 理由
505681468 + 1 塞糖

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部