设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 108|回复: 10
打印 上一主题 下一主题

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
224
在线时间
30 小时
注册时间
2024-4-10
帖子
42
跳转到指定楼层
1
发表于 2024-4-22 21:09:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

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



JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // MrTS_LimitedInventory.js
  3. //=============================================================================
  4.  
  5. /*:
  6. * @plugindesc Limits inventory space by weight or item numbers.
  7. * @author Mr. Trivel
  8. *
  9. * @param Limit Mode
  10. * @desc Which mode to use? weight/number
  11. * Default: number
  12. * @default number
  13. *
  14. * @param Default Limit
  15. * @desc Inventory limit.
  16. * Default: 30
  17. * @default 30
  18. *
  19. * @param Default Weight
  20. * @desc If using 'weight' mode, how much items weight by default?
  21. * Default: 1
  22. * @default 1
  23. *
  24. * @param Show Window
  25. * @desc Show inventory limit window in item menu? true/false
  26. * Default: True
  27. * @default True
  28. *
  29. * @param Limit Text
  30. * @desc How will limit be named in Window?
  31. * Default: Limit:
  32. * @default Limit:
  33. *
  34. * @help
  35. * --------------------------------------------------------------------------------
  36. * Terms of Use
  37. * --------------------------------------------------------------------------------
  38. * Don't remove the header or claim that you wrote this plugin.
  39. * Credit Mr. Trivel if using this plugin in your project.
  40. * Free for commercial and non-commercial projects.
  41. * --------------------------------------------------------------------------------
  42. * Version 1.0
  43. * --------------------------------------------------------------------------------
  44. *
  45. * --------------------------------------------------------------------------------
  46. * Item Tags
  47. * --------------------------------------------------------------------------------
  48. * <Weight: [AMOUNT]>
  49. * If using 'weight' mode, use the following to determine the weight of item.
  50. *
  51. * Example:
  52. * <Weight: 5>
  53. * --------------------------------------------------------------------------------
  54. *
  55. * --------------------------------------------------------------------------------
  56. * Equipment Tags
  57. * --------------------------------------------------------------------------------
  58. * <InvLimitChange: [AMOUNT]>
  59. * Changes inventory limit by AMOUNT while item is equipped. Works for both modes.
  60. *
  61. * <InvLimitChange: -5>
  62. * <InvLimitChange: 10>
  63. * --------------------------------------------------------------------------------
  64. *
  65. * --------------------------------------------------------------------------------
  66. * Plugin Commands
  67. * --------------------------------------------------------------------------------
  68. * InventoryLimit Add [AMOUNT] - Adds Amount to limit.
  69. * InventoryLimit Sub [AMOUNT] - Removes Amount from limit.
  70. * InventoryLimit Ignore - Ignores inventory limit when adding items
  71. * InventoryLimit StopIgnore - Stops ignoring inventory limit when adding items
  72. *
  73. * Examples:
  74. * InventoryLimit Add 10
  75. * InventoryLimit Sub 5
  76. * InventoryLimit Ignore
  77. * InventoryLimit StopIgnore
  78. * --------------------------------------------------------------------------------
  79. *
  80. * --------------------------------------------------------------------------------
  81. * Script Calls
  82. * --------------------------------------------------------------------------------
  83. * $gameParty.getInventorySpaceLeft() - returns amount of space left
  84. * $gameParty.getInventorySpaceTotal() - returns total amount of space
  85. * $gameParty.getInventorySpaceUsed() - returns used amount of space
  86. * --------------------------------------------------------------------------------
  87. *
  88. * --------------------------------------------------------------------------------
  89. * Version History
  90. * --------------------------------------------------------------------------------
  91. * 1.0 - Release
  92. */
  93.  
  94. (function() {
  95.         var parameters = PluginManager.parameters('MrTS_LimitedInventory');
  96.         var paramLimitMode = String(parameters['Limit Mode'] || "number");
  97.         var paramDefaultLimit = Number(parameters['Default Limit'] || 30);
  98.         var paramDefaultWeight = Number(parameters['Default Weight'] || 1);
  99.         var paramShowWindow = (parameters['Show Window'] || "true").toLowerCase() === "true";
  100.         var paramLimitText = String(parameters['Limit Text'] || "Limit:");
  101.  
  102.         //--------------------------------------------------------------------------
  103.         // Game_Interpreter
  104.         //
  105.  
  106.         var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  107.         Game_Interpreter.prototype.pluginCommand = function(command, args) {
  108.                 _Game_Interpreter_pluginCommand.call(this, command, args);
  109.                 if (command.toLowerCase() === "inventorylimit") {
  110.                         switch (args[0].toUpperCase())
  111.                         {
  112.                                 case 'ADD':
  113.                                 {
  114.                                         $gameParty.increaseInventorySpace(Number(args[1]));
  115.                                 } break;
  116.                                 case 'SUB':
  117.                                 {
  118.                                         $gameParty.decreaseInventorySpace(Number(args[1]));
  119.                                 } break;
  120.                                 case 'IGNORE':
  121.                                 {
  122.                                         $gameParty._ignoreInvLimit = true;
  123.                                 } break;
  124.                                 case 'STOPIGNORE':
  125.                                 {
  126.                                         $gameParty._ignoreInvLimit = false;
  127.                                 } break;                               
  128.                         }
  129.                 }
  130.         };
  131.  
  132.         //--------------------------------------------------------------------------
  133.         // Game_Party
  134.  
  135.         var _Game_Party_initialize = Game_Party.prototype.initialize;
  136.         Game_Party.prototype.initialize = function() {
  137.                 _Game_Party_initialize.call(this);
  138.                 this._inventorySpace = paramDefaultLimit;
  139.                 this._modifiedInvSpace = 0;
  140.                 this._ignoreInvLimit = false;
  141.         };
  142.  
  143.         Game_Party.prototype.increaseInventorySpace = function(amount) {
  144.                 this._modifiedInvSpace += amount;
  145.         };
  146.  
  147.         Game_Party.prototype.decreaseInventorySpace = function(amount) {
  148.                 this.increaseInventorySpace(-amount);
  149.         };
  150.  
  151.         Game_Party.prototype.getInventorySpaceTotal = function() {
  152.                 var base = this._inventorySpace;
  153.                 var mod = this._modifiedInvSpace;
  154.                 var equipment = 0;
  155.                 for (var i = 0; i < this.members().length; i++) {
  156.                         equipment += this.members()[i].getInventorySpaceBonus();
  157.                 }
  158.                 return Math.max(0, (base+mod+equipment));
  159.         };
  160.  
  161.         Game_Party.prototype.getInventorySpaceUsed = function() {
  162.                 var used = 0;
  163.                 for (var i = 0; i < this.allItems().length; i++) {
  164.                         switch(paramLimitMode)
  165.                         {
  166.                                 case 'number':
  167.                                 {
  168.                                         used += this.numItems(this.allItems()[i]);
  169.                                 } break;
  170.                                 case 'weight':
  171.                                 {
  172.                                         var weight = this.allItems()[i].meta.Weight ? Number(this.allItems()[i].meta.Weight) : paramDefaultWeight;
  173.                                         used += this.numItems(this.allItems()[i]) * weight;
  174.                                 } break;
  175.  
  176.                         }
  177.                 }
  178.                 return used;
  179.         };
  180.  
  181.         Game_Party.prototype.getInventorySpaceLeft = function() {
  182.                 return this.getInventorySpaceTotal() - this.getInventorySpaceUsed();
  183.         };
  184.  
  185.         Game_Party.prototype.getItemWeight = function(item) {
  186.                 switch(paramLimitMode)
  187.                 {
  188.                         case 'number':
  189.                         {
  190.                                 return 1;
  191.                         } break;
  192.                         case 'weight':
  193.                         {
  194.                                 var weight = item.meta.Weight ? Number(item.meta.Weight) : paramDefaultWeight;
  195.                                 return weight;
  196.                         } break;
  197.  
  198.                 }
  199.                 return 1;
  200.         };
  201.  
  202.         var _Game_Party_gainItem = Game_Party.prototype.gainItem;
  203.         Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
  204.                 if (amount < 0 || this._ignoreInvLimit) _Game_Party_gainItem.call(this, item, amount, includeEquip);
  205.                 else
  206.                 {
  207.                         var weight = this.getItemWeight(item);
  208.                         var tWeight = weight * amount;
  209.                         var aWeight = this.getInventorySpaceLeft();
  210.                         if ((aWeight - tWeight) >= 0) _Game_Party_gainItem.call(this, item, amount, includeEquip);
  211.                         else
  212.                         {
  213.                                 var newAmount = Math.floor(aWeight/weight);
  214.                                 if (newAmount > 0)
  215.                                         _Game_Party_gainItem.call(this, item, newAmount, includeEquip);
  216.                         }
  217.                 }
  218.         };
  219.  
  220.         Game_Actor.prototype.getInventorySpaceBonus = function() {
  221.                 var bonus = 0;
  222.                 for (var i = 0; i < this.equips().length; i++) {
  223.                         if (!this.equips()[i]) continue;
  224.                         if (this.equips()[i].meta.InvLimitChange)
  225.                                 bonus += Number(this.equips()[i].meta.InvLimitChange);
  226.                 }
  227.                 return bonus;
  228.         };
  229.  
  230.         //--------------------------------------------------------------------------
  231.         // Window_InventoryLimit
  232.         //
  233.         // Shows how much is left.
  234.  
  235.         function Window_InventoryLimit() {
  236.                 this.initialize.apply(this, arguments);       
  237.         };
  238.  
  239.         Window_InventoryLimit.prototype = Object.create(Window_Base.prototype);
  240.         Window_InventoryLimit.prototype.constructor = Window_InventoryLimit;
  241.  
  242.         Window_InventoryLimit.prototype.initialize = function(x, y, w, h) {
  243.                 Window_Base.prototype.initialize.call(this, x, y, w, h);
  244.                 this.refresh();
  245.         };
  246.  
  247.         Window_InventoryLimit.prototype.refresh = function() {
  248.                 this.contents.clear();
  249.                 var u = $gameParty.getInventorySpaceUsed();
  250.                 var t = $gameParty.getInventorySpaceTotal();
  251.                 this.drawText(paramLimitText + " " + u + "/" + t, 0, 0);
  252.         };
  253.  
  254.         //--------------------------------------------------------------------------
  255.         // Scene_Item
  256.         //
  257.  
  258.         var _Scene_Item_create = Scene_Item.prototype.create;
  259.         Scene_Item.prototype.create = function() {
  260.                 _Scene_Item_create.call(this);
  261.                 if (paramShowWindow)
  262.                         this.createLimitWindow();
  263.         };
  264.  
  265.         Scene_Item.prototype.createLimitWindow = function() {
  266.                 var wx = this._itemWindow.x;
  267.                 var ww = this._itemWindow.width;
  268.                 var wh = this._itemWindow.fittingHeight(1);
  269.                 this._itemWindow.height = this._itemWindow.height - wh;
  270.                 this._itemWindow.refresh();
  271.                 var wy = this._itemWindow.y + this._itemWindow.height;
  272.                 this._invLimitWindow = new Window_InventoryLimit(wx, wy, ww, wh);
  273.                 this.addWindow(this._invLimitWindow);
  274.         };
  275.  
  276.         var _Scene_Item_useItem = Scene_Item.prototype.useItem;
  277.         Scene_Item.prototype.useItem = function() {
  278.                 _Scene_Item_useItem.call(this);
  279.                 if (this._invLimitWindow) this._invLimitWindow.refresh();
  280.         };
  281. })();


这是跳出错误代码的位置

JAVASCRIPT 代码复制
  1. {
  2.                                 var weight = item.meta.Weight ? Number(item.meta.Weight) : paramDefaultWeight;
  3.                                 return weight;
  4.                         } break;
  5.  
  6.                 }
  7.                 return 1;
  8.         };
  9.  
  10.         var _Game_Party_gainItem = Game_Party.prototype.gainItem;
  11.         Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
  12.                 if (amount < 0 || this._ignoreInvLimit) _Game_Party_gainItem.call(this, item, amount, includeEquip);
  13.                 else



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

点评

如果想治标不治本的话可以把问号前面的 "item.meta.Weight" 改成 "item&&item.meta&&item.meta.Weight" 这种连锁检查的写法。  发表于 2024-4-23 16:15

Lv2.观梦者

梦石
0
星屑
530
在线时间
272 小时
注册时间
2012-4-8
帖子
175
2
发表于 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 正在路上
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9283
在线时间
1838 小时
注册时间
2020-1-2
帖子
1082
3
发表于 2024-4-22 21:55:49 | 只看该作者
这是另一个重量你尝试看看如果需要仓库的我到时候再发但是是不同作者的插件

DEX_WeightLimit.zip

3.15 KB, 下载次数: 3

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

使用道具 举报

Lv1.梦旅人

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

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

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

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
224
在线时间
30 小时
注册时间
2024-4-10
帖子
42
5
 楼主| 发表于 2024-4-22 22:47:24 | 只看该作者
505681468 发表于 2024-4-22 21:20
可能是 Scene_Equip.prototype.onItemOk 获取了错误的 item ?
可以看看 this.actor().changeEquip(this._s ...

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

使用道具 举报

Lv1.梦旅人

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

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

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
224
在线时间
30 小时
注册时间
2024-4-10
帖子
42
7
 楼主| 发表于 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吗....
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
224
在线时间
30 小时
注册时间
2024-4-10
帖子
42
8
 楼主| 发表于 2024-4-23 01:30:18 | 只看该作者
好吧,不是插件BUG

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

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

使用道具 举报

Lv2.观梦者

梦石
0
星屑
530
在线时间
272 小时
注册时间
2012-4-8
帖子
175
9
发表于 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 正在路上
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
224
在线时间
30 小时
注册时间
2024-4-10
帖子
42
10
 楼主| 发表于 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 塞糖

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-4 00:59

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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