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

Project1

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

[有事请教] 关于连击脚本,如何触发连击时随机选择目标?

[复制链接]

Lv4.逐梦者

素材区好人

梦石
3
星屑
6792
在线时间
3462 小时
注册时间
2011-7-21
帖子
2254

极短24参与极短23参与极短22参与极短21参与

跳转到指定楼层
1
发表于 2023-12-20 23:26:48 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
找到一个不错的连击脚本,可以自由设计连击概率和连击次数,并且连击的时候不会消耗MP

但是仍然有一个问题,每次连击时都会选择同一个目标,与其说是连击不如叫追击
如何触发连击后,进行连击的单体技能随机选择目标?

RUBY 代码复制
  1. class Game_Temp
  2.   #--------------------------------------------------------------------------
  3.   # ● 定义实例变量
  4.   #--------------------------------------------------------------------------
  5.   attr_accessor :连击FLAG
  6.   def 连击FLAG;return @连击FLAG||=false;end
  7.   end
  8.  
  9. module RPG
  10.   class Skill
  11.     attr_accessor :连击
  12.     attr_accessor :desc
  13.     attr_accessor :几率
  14.     def 连击;return @连击||=0;end
  15.     def description
  16.      description = @description.split(/@/)[0]
  17.      return description != nil ? description : ''
  18.    end
  19.    def desc
  20.      desc = @description.split(/@/)[1]
  21.      return desc != nil ? desc.to_i : 0
  22.    end
  23.    def 几率
  24.      desc = @description.split(/@/)[2]
  25.      return desc != nil ? desc.to_i : 0
  26.      end
  27.    end
  28. end
  29.  
  30. #==============================================================================
  31. # ■ Scene_Battle (分割定义 4)
  32. #------------------------------------------------------------------------------
  33. #  处理战斗画面的类。
  34. #==============================================================================
  35.  
  36. class Scene_Battle
  37. #--------------------------------------------------------------------------
  38.   # ● 刷新画面 (主回合步骤 5 : 显示伤害)
  39.   #--------------------------------------------------------------------------
  40.   alias update_phase4_step5_20211213 update_phase4_step5
  41.   def update_phase4_step5
  42.     update_phase4_step5_20211213
  43.     敌全灭=true
  44.     for enemy in $game_troop.enemies
  45.     敌全灭=false if enemy.exist?
  46.     end
  47.     if @active_battler.current_action.skill_id != 0 and !敌全灭
  48.     skill=$data_skills[@active_battler.current_action.skill_id].dup
  49.     @连击||=skill.desc
  50.     # 移至步骤 2
  51.     if @连击 > 0 and skill.几率 > rand(100)
  52.     @phase4_step = 2
  53.     $game_temp.连击FLAG=true
  54.   end
  55.     @连击-=1
  56.     end
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● 刷新画面 (主回合步骤 6 : 刷新)
  60.   #--------------------------------------------------------------------------
  61.   alias update_phase4_step6_20211213 update_phase4_step6
  62.   def update_phase4_step6
  63.     update_phase4_step6_20211213
  64.     skill=$data_skills[@active_battler.current_action.skill_id].dup if @active_battler.current_action.skill_id != 0
  65.     @连击=nil
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # ● 生成特技行动结果
  69.   #--------------------------------------------------------------------------
  70.   def make_skill_action_result
  71.     # 获取特技
  72.     @skill = $data_skills[@active_battler.current_action.skill_id]
  73.     # 如果不是强制行动
  74.     unless @active_battler.current_action.forcing
  75.       # 因为 SP 耗尽而无法使用的情况下
  76.       unless @active_battler.skill_can_use?(@skill.id)
  77.         # 清除强制行动对像的战斗者
  78.         $game_temp.forcing_battler = nil
  79.         # 移至步骤 1
  80.         @phase4_step = 1
  81.         return
  82.       end
  83.     end
  84.     # 消耗 SP
  85.     if $game_temp.连击FLAG
  86.       $game_temp.连击FLAG=false
  87.       else
  88.     @active_battler.sp -= @skill.sp_cost
  89.     end
  90.     # 刷新状态窗口
  91.     @status_window.refresh
  92.     # 在帮助窗口显示特技名
  93.     @help_window.set_text(@skill.name, 1)
  94.     # 设置动画 ID
  95.     @animation1_id = @skill.animation1_id
  96.     @animation2_id = @skill.animation2_id
  97.     # 设置公共事件 ID
  98.     @common_event_id = @skill.common_event_id
  99.     # 设置对像侧战斗者
  100.     set_target_battlers(@skill.scope)
  101.     # 应用特技效果
  102.     for target in @target_battlers
  103.       target.skill_effect(@active_battler, @skill)
  104.     end
  105.   end
  106. end
  107.  
  108. class Game_Battler
  109.   #--------------------------------------------------------------------------
  110.   # ● 可以使用特技的判定
  111.   #     skill_id : 特技 ID
  112.   #--------------------------------------------------------------------------
  113.   def skill_can_use?(skill_id)
  114.     return true if $game_temp.连击FLAG
  115.     # SP 不足的情况下不能使用
  116.     if $data_skills[skill_id].sp_cost > self.sp
  117.       return false
  118.     end
  119.     # 战斗不能的情况下不能使用
  120.     if dead?
  121.       return false
  122.     end
  123.     # 沉默状态的情况下、物理特技以外的特技不能使用
  124.     if $data_skills[skill_id].atk_f == 0 and self.restriction == 1
  125.       return false
  126.     end
  127.     # 获取可以使用的时机
  128.     occasion = $data_skills[skill_id].occasion
  129.     # 战斗中的情况下
  130.     if $game_temp.in_battle
  131.       # [平时] 或者是 [战斗中] 可以使用
  132.       return (occasion == 0 or occasion == 1)
  133.     # 不是战斗中的情况下
  134.     else
  135.       # [平时] 或者是 [菜单中] 可以使用
  136.       return (occasion == 0 or occasion == 2)
  137.     end
  138.   end
  139.   end

Lv5.捕梦者

梦石
0
星屑
33188
在线时间
10490 小时
注册时间
2009-3-15
帖子
4756
2
发表于 2023-12-21 00:07:54 | 只看该作者
本帖最后由 soulsaga 于 2023-12-24 14:44 编辑

RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2.   # ● 设置物品或特技对像方的战斗者
  3.   #     scope : 特技或者是物品的范围
  4.   #--------------------------------------------------------------------------
  5.   def set_target_battlers(scope)
  6.     # 行动方的战斗者是敌人的情况下
  7.     if @active_battler.is_a?(Game_Enemy)
  8.       # 效果范围分支
  9.       case scope
  10.       when 1  # 敌单体
  11.         index = @active_battler.current_action.target_index
  12.         @target_battlers.push($game_party.smooth_target_actor(index))
  13.       when 2  # 敌全体
  14.         for actor in $game_party.actors
  15.           if actor.exist?
  16.             @target_battlers.push(actor)
  17.           end
  18.         end
  19.       when 3  # 我方单体
  20.         index = @active_battler.current_action.target_index
  21.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  22.       when 4  # 我方全体
  23.         for enemy in $game_troop.enemies
  24.           if enemy.exist?
  25.             @target_battlers.push(enemy)
  26.           end
  27.         end
  28.       when 5  # 我方单体 (HP 0)
  29.         index = @active_battler.current_action.target_index
  30.         enemy = $game_troop.enemies[index]
  31.         if enemy != nil and enemy.hp0?
  32.           @target_battlers.push(enemy)
  33.         end
  34.       when 6  # 我方全体 (HP 0)
  35.         for enemy in $game_troop.enemies
  36.           if enemy != nil and enemy.hp0?
  37.             @target_battlers.push(enemy)
  38.           end
  39.         end
  40.       when 7  # 使用者
  41.         @target_battlers.push(@active_battler)
  42.       end
  43.     end
  44.     # 行动方的战斗者是角色的情况下
  45.     if @active_battler.is_a?(Game_Actor)
  46.       # 效果范围分支
  47.       case scope
  48.       when 1  # 敌单体
  49.         index = @active_battler.current_action.target_index
  50.         if $game_temp.连击FLAG
  51.         @target_battlers.push($game_troop.random_target_enemy)
  52.         return
  53.         end
  54.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  55.       when 2  # 敌全体
  56.         for enemy in $game_troop.enemies
  57.           if enemy.exist?
  58.             @target_battlers.push(enemy)
  59.           end
  60.         end
  61.       when 3  # 我方单体
  62.         index = @active_battler.current_action.target_index
  63.         @target_battlers.push($game_party.smooth_target_actor(index))
  64.       when 4  # 我方全体
  65.         for actor in $game_party.actors
  66.           if actor.exist?
  67.             @target_battlers.push(actor)
  68.           end
  69.         end
  70.       when 5  # 我方单体 (HP 0)
  71.         index = @active_battler.current_action.target_index
  72.         actor = $game_party.actors[index]
  73.         if actor != nil and actor.hp0?
  74.           @target_battlers.push(actor)
  75.         end
  76.       when 6  # 我方全体 (HP 0)
  77.         for actor in $game_party.actors
  78.           if actor != nil and actor.hp0?
  79.             @target_battlers.push(actor)
  80.           end
  81.         end
  82.       when 7  # 使用者
  83.         @target_battlers.push(@active_battler)
  84.       end
  85.     end
  86.   end


未测,

点评

你不会以为我给的脚本是直接插入的吧?那是要你改的  发表于 2024-1-4 15:49
改了,51行报错  发表于 2023-12-30 23:00
改成 if @连击 !=nil 就可以了,顺便不要像我一样忘了放在 class Scene_Battle T 口 T  发表于 2023-12-30 11:29
仍然没变化…  发表于 2023-12-25 23:50
还是不行吗?那试试这个  发表于 2023-12-24 14:45
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
5680
在线时间
782 小时
注册时间
2019-1-20
帖子
191
3
发表于 2024-1-2 22:47:22 | 只看该作者
  1. =begin
  2. 顺便把敌人的也加了,不要就把### 1 那几行删除
  3. =end
  4. class Scene_Battle
  5. #--------------------------------------------------------------------------
  6.   # ● 设置物品或特技对像方的战斗者
  7.   #     scope : 特技或者是物品的范围
  8.   #--------------------------------------------------------------------------
  9.   def set_target_battlers(scope)
  10.     # 行动方的战斗者是敌人的情况下
  11.     if @active_battler.is_a?(Game_Enemy)
  12.       # 效果范围分支
  13.       case scope
  14.       when 1  # 敌单体
  15.         index = @active_battler.current_action.target_index
  16.         
  17.         if @连击 !=nil ### 1
  18.         @target_battlers.push($game_party.random_target_actor)
  19.         return
  20.         end
  21.       
  22.         @target_battlers.push($game_party.smooth_target_actor(index))
  23.       when 2  # 敌全体
  24.         for actor in $game_party.actors
  25.           if actor.exist?
  26.             @target_battlers.push(actor)
  27.           end
  28.         end
  29.       when 3  # 我方单体
  30.         index = @active_battler.current_action.target_index
  31.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  32.       when 4  # 我方全体
  33.         for enemy in $game_troop.enemies
  34.           if enemy.exist?
  35.             @target_battlers.push(enemy)
  36.           end
  37.         end
  38.       when 5  # 我方单体 (HP 0)
  39.         index = @active_battler.current_action.target_index
  40.         enemy = $game_troop.enemies[index]
  41.         if enemy != nil and enemy.hp0?
  42.           @target_battlers.push(enemy)
  43.         end
  44.       when 6  # 我方全体 (HP 0)
  45.         for enemy in $game_troop.enemies
  46.           if enemy != nil and enemy.hp0?
  47.             @target_battlers.push(enemy)
  48.           end
  49.         end
  50.       when 7  # 使用者
  51.         @target_battlers.push(@active_battler)
  52.       end
  53.     end
  54.     # 行动方的战斗者是角色的情况下
  55.     if @active_battler.is_a?(Game_Actor)
  56.       # 效果范围分支
  57.       case scope
  58.       when 1  # 敌单体
  59.         index = @active_battler.current_action.target_index
  60.         
  61.         if @连击 !=nil ### 2
  62.         @target_battlers.push($game_troop.random_target_enemy)
  63.         return
  64.         end
  65.       
  66.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  67.       when 2  # 敌全体
  68.         for enemy in $game_troop.enemies
  69.           if enemy.exist?
  70.             @target_battlers.push(enemy)
  71.           end
  72.         end
  73.       when 3  # 我方单体
  74.         index = @active_battler.current_action.target_index
  75.         @target_battlers.push($game_party.smooth_target_actor(index))
  76.       when 4  # 我方全体
  77.         for actor in $game_party.actors
  78.           if actor.exist?
  79.             @target_battlers.push(actor)
  80.           end
  81.         end
  82.       when 5  # 我方单体 (HP 0)
  83.         index = @active_battler.current_action.target_index
  84.         actor = $game_party.actors[index]
  85.         if actor != nil and actor.hp0?
  86.           @target_battlers.push(actor)
  87.         end
  88.       when 6  # 我方全体 (HP 0)
  89.         for actor in $game_party.actors
  90.           if actor != nil and actor.hp0?
  91.             @target_battlers.push(actor)
  92.           end
  93.         end
  94.       when 7  # 使用者
  95.         @target_battlers.push(@active_battler)
  96.       end
  97.     end
  98.   end
  99. end #  class
复制代码


点评

多谢,已经解决  发表于 2024-1-5 00:37

评分

参与人数 1+1 收起 理由
无忧谷主幻 + 1 认可答案

查看全部评分


提高解答机会的方法:
看一下对应版本的帮助文件 看天气预报说今天不下雨
改变问题为更有可能的或常见的 如:天气自动变化下雨→天气系统 果然不准呀~
使用论坛的搜索功能查找相关问题 好丧啊... ...想看女装
清楚说明实际上你想解决的问题  想看坛友的女装  
脚本自己有改过的地方要标明  不要遮脸的
脚本有问题但不是默认的要全部贴出来 大胆点,尽情发
三包原则:包有BUG,包甩锅,包咕咕
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-28 04:22

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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