找回密码
 注册用户
查看: 377|回复: 0

[RMMV] 简易物品指定职业不可使用

[复制链接]

88

主题

7

回帖

1277

积分

资深会员

积分
1277
发表于 2024-8-16 09:34:41 | 显示全部楼层 |阅读模式
本帖最后由 烁灵 于 2024-8-16 10:53 编辑

在物品备注中设置,指定的职业不可使用该物品或只有指定职业可以使用该物品

QQ截图20240816092907.png

QQ截图20240816105046.png

脚本:保存为 ClassCannotUseItem.js
  1. //=============================================================================
  2. /*:
  3. * ClassCannotUseItem.js
  4. * @plugindesc v1.00 物品不能被指定职业使用
  5. * @author 烁灵 更多脚本请访问 www.hknmtt.com
  6. *
  7. * @help
  8. * 在物品备注中填写:
  9. * <职业N不可用>
  10. * 则 N 号职业不可使用该物品
  11. * <职业N可用>
  12. * 则只有 N 号职业可以使用该物品(不能重复使用本项备注)
  13. * N为职业编号,从1开始
  14. */
  15. //=============================================================================
  16. (()=>{
  17.     let reg = /<职业(\s*[0-9]+\s*)不可用>/
  18.     let reg2 = /<职业(\s*[0-9]+\s*)可用>/
  19.     var sl_Scene_Battle_onActorOk = Scene_Battle.prototype.onActorOk;
  20.     Scene_Battle.prototype.onActorOk = function() {
  21.         let action = BattleManager.inputtingAction();
  22.         let actor = this._actorWindow.actor()
  23.         if (this._actorCommandWindow.currentSymbol() == 'item') {
  24.             if (!action.testApply(actor)) {
  25.                 SoundManager.playBuzzer();
  26.                 this._actorWindow.activate();
  27.                 return
  28.             }
  29.         }
  30.         return sl_Scene_Battle_onActorOk.call(this)
  31.     };
  32.    
  33.     Game_Action.prototype.meetsClassCannotUseItem = function(target) {
  34.         let checkClass = false;
  35.         if (this.isItem() && target.isActor()) {
  36.             let item = this.item();
  37.             checkClass = item.note.split("\n").some(line => {
  38.                 line = line.trim();
  39.                 if (line.match(reg)) {
  40.                     if (target._classId == parseInt(RegExp.$1.trim())) {
  41.                         return true;
  42.                     }
  43.                 }
  44.                 return false;
  45.             });
  46.         }
  47.         return checkClass;
  48.     }
  49.     Game_Action.prototype.meetsClassCanUseItem = function(target) {
  50.         let checkClass = true;
  51.         if (this.isItem() && target.isActor()) {
  52.             let item = this.item();
  53.             checkClass = item.note.split("\n").every(line => {
  54.                 line = line.trim();
  55.                 if (line.match(reg2)) {
  56.                     if (target._classId != parseInt(RegExp.$1.trim())) {
  57.                         return false;
  58.                     }
  59.                 }
  60.                 return true;
  61.             });
  62.         }
  63.         return checkClass;
  64.     }
  65.     var sl_Game_Action_testApply = Game_Action.prototype.testApply;
  66.     Game_Action.prototype.testApply= function(target) {
  67.         let result = sl_Game_Action_testApply.call(this, target)
  68.         return result && !this.meetsClassCannotUseItem(target) && this.meetsClassCanUseItem(target);
  69.     };
  70. })()
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册用户

本版积分规则

Archiver|QQ群: 48625831|爱上RPG|哈库纳玛塔塔 |网站地图 Clicky

GMT+8, 2024-10-23 07:36 , Processed in 0.106503 second(s), 21 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

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