Project1
标题: RPG状态实现技巧,无需新增脚本 [打印本页]
作者: 无忧谷主幻 时间: 2025-12-14 10:58
标题: RPG状态实现技巧,无需新增脚本
本帖最后由 无忧谷主幻 于 2026-6-14 13:29 编辑
分享几个超实用的状态实现技巧——无需新增任何脚本,仅需修改原生脚本的几行代码,就能轻松做出各类战斗状态效果!
本文收录的所有方法,都是基于基础脚本的微调,新手也能快速上手
后续会持续更新不同状态的修改思路,欢迎大家在评论区交流自己的脚本修改小技巧
(状态名称仅供参考)
1,不屈:角色受到致命伤时,保留1HP
Game_Battler 1 第265行
- #--------------------------------------------------------------------------
- # ● 战斗不能判定
- #--------------------------------------------------------------------------
- def dead?
- return (@hp == 0 and not @immortal)
- end
复制代码
将其改为
- #--------------------------------------------------------------------------
- # ● 战斗不能判定
- #--------------------------------------------------------------------------
- def dead?
- if @hp == 0 and @states.include?(100)
- @hp+=1
- return false
- else
- return (@hp == 0 and not @immortal)
- end
- end
复制代码
1.1,不屈·改:角色受到致命伤时,保留1HP,之后移除该状态
- #--------------------------------------------------------------------------
- # ● 战斗不能判定
- #--------------------------------------------------------------------------
- def dead?
- if @hp == 0 and @states.include?(100)
- @hp += 1 # 濒死保护:HP+1
- @states.delete(100)
- return false # 判定为未死亡
- else
- # 普通死亡判定
- return (@hp == 0 and not @immortal)
- end
- end
复制代码
2,减伤:按照百分百,减免部分伤害
Game_Battler 3 62行与147行
- # 防御修正
- if self.guarding?
- self.damage /= 2
- end
- end
复制代码
统统改成
- # 防御修正
- self.damage /= 2 if self.guarding?
- # 101号状态减伤30%
- self.damage = (self.damage * 7) / 10 if self.state?(101)
- end
复制代码
PS:253行也有一个防御修正,但这个应该不需要改,毕竟敌人是不会使用道具的,你自己应该也不会用道具打自己
2.1,免伤:将受到的伤害直接降为0
- # 防御修正
- self.damage /= 2 if self.guarding?
- self.damage = 0 if self.state?(101) # 101号状态触发100%免伤
- end
复制代码
3,增幅:增加特定属性的威力百分百
Game_Battler 3 173行
- # 计算威力
- power = skill.power + user.atk * skill.atk_f / 100
- if power > 0
- power -= self.pdef * skill.pdef_f / 200
- power -= self.mdef * skill.mdef_f / 200
- power = [power, 0].max
- end
复制代码
将其改成
- # 计算威力
- power = skill.power + user.atk * skill.atk_f / 100
- sz = [[11,38,15],[11,39,13]]
- # 使用带11号属性的技能,在38号状态的作用下,威力1.5倍,在39号状态的作用下,威力1.3倍
- for i in 0...sz.size
- if skill.element_set.include?(sz[i][0]) and user.state?(sz[i][1])
- power *= sz[i][2]
- power /= 10
- end
- end
- if power > 0
- power -= self.pdef * skill.pdef_f / 200
- power -= self.mdef * skill.mdef_f / 200
- power = [power, 0].max
- end
复制代码
4,属性护盾:受到特定属性攻击时,按百分比减免伤害
Game_Battler 3 55行与145行
- # 伤害符号正确的情况下
- if self.damage > 0
复制代码
将其改成
- # 伤害符号正确的情况下
- if self.damage > 0
- if self.state?(103)
- end
- if skill.element_set.include?(14)
- self.damage = self.damage*60/100
- #处于103号状态,受到带有14号属性的攻击时,伤害变成原本的60%
- end
复制代码
若想添加多个属性的减伤也是可以的
- # 伤害符号正确的情况下
- if self.damage > 0
- if self.state?(103)
- if skill.element_set.include?(6)
- self.damage=self.damage*0/100
- end
- if skill.element_set.include?(14)
- self.damage=self.damage*60/100
- end
- end
复制代码
5,愈合:每回合自动回复一定比例的HP
Scene_Battle 4 129~133行
- # 连续伤害
- if @active_battler.hp > 0 and @active_battler.slip_damage?
- @active_battler.slip_damage_effect
- @active_battler.damage_pop = true
- end
复制代码
下面(注意!是下面,不是覆盖)
- if @active_battler.state?(105) and @active_battler.hp >0 #105号状态恢复生命
- @active_battler.damage=-@active_battler.maxhp/10 #恢复生命百分比,这里设置为10%,也可设置固定值
- @active_battler.damage=@active_battler.damage.to_i
- @active_battler.hp-=@active_battler.damage
- @active_battler.animation_id = 4 #自动补血动画编号
- @active_battler.damage_pop = true
- end
复制代码
5.5:回蓝:每回合自动回复一定数值的MP
- # 判定105号状态,恢复500点SP
- if @active_battler.is_a?(Game_Actor)
- if @active_battler.hp > 0 and @active_battler.state?(105)
- @active_battler.sp += 500
- end
- end
复制代码
6,狂战:HP越少,攻击力越高
Game_Actor 264行
- #--------------------------------------------------------------------------
- # ● 获取基本攻击力
- #--------------------------------------------------------------------------
- def base_atk
- weapon = $data_weapons[@weapon_id]
- return weapon != nil ? weapon.atk : 0
- end
复制代码
将其改成
- #--------------------------------------------------------------------------
- # ● 获取基本攻击力
- #--------------------------------------------------------------------------
- def base_atk
- n = 0
- if @weapon_id > 0
- weapon = $data_weapons[@weapon_id]
- n += weapon.atk
- end
- if self.state?(106)
- n += n*(100-self.hp*100/self.maxhp)/100
- end
- return n
- end
复制代码
7,多种毒( 别问为什么只有3种,我也想多写几个,但是想不到还能写什么效果了)
①风毒:每回合按扣除10%MP
②水毒:每回合扣除剩余HP的10%
③火毒:每回合扣除1000点HP
Game_Battler 3 318行
- #--------------------------------------------------------------------------
- # ● 应用连续伤害效果
- #--------------------------------------------------------------------------
- def slip_damage_effect
- # 设置伤害
- self.damage = self.maxhp / 10
- # 分散
- if self.damage.abs > 0
- amp = [self.damage.abs * 15 / 100, 1].max
- self.damage += rand(amp+1) + rand(amp+1) - amp
- end
- # HP 的伤害减法运算
- self.hp -= self.damage
复制代码
将其改成
- #--------------------------------------------------------------------------
- # ● 应用连续伤害效果
- #--------------------------------------------------------------------------
- def slip_damage_effect
- if self.state?(3) #默认的毒效果
- # 设置伤害
- self.damage = self.maxhp / 10
- # 分散
- if self.damage.abs > 0
- amp = [self.damage.abs * 15 / 100, 1].max
- self.damage += rand(amp+1) + rand(amp+1) - amp
- end
- # HP 的伤害减法运算
- self.hp -= self.damage
- end
- # 风毒:每回合扣除最大SP的10%
- if self.state?(17)
- sp_dmg = self.maxsp * 10 / 100
- self.damage = sp_dmg # 记录伤害数值(用于战斗界面显示)
- self.sp -= sp_dmg # 扣减SP
- self.sp = [self.sp, 0].max # 限制SP下限,避免出现负数
- end
- # 水毒:每回合扣除剩余HP的10%
- if self.state?(18)
- self.damage = self.hp * 1 / 10
- self.hp -= self.damage
- end
- # 火毒:每回合扣除固定1000点HP
- if self.state?(19)
- self.damage = 1000
- self.hp -= self.damage
- end
- # 土毒:初始为0,每经过1回合扣除的伤害加50
- if self.state?(17)
- remaining_turns = @states_turn[17]
- calculated_damage = (21 - remaining_turns) * 50# 10回合解除就填11,20回合解除就填21
- self.damage = [calculated_damage, 9999].min
- self.hp -= self.damage
- end
复制代码
8,增伤:提升/降低技能伤害百分百
Game_Battler 3 140~141行
# 计算基本伤害
self.damage = power * rate / 20
# 计算基本伤害
self.damage = power * rate / 20
下面
# 状态加成 技能伤害增加30%
if user.state?(107)
self.damage = self.damage * 130 / 100 # 对使用者的技能伤害加成30%
end
# 状态加成 技能伤害增加30%
if user.state?(107)
self.damage = self.damage * 130 / 100 # 对使用者的技能伤害加成30%
end
PS:只对技能有效,若想对普通攻击也有效,在上面的应用通常攻击效果也加一遍
8.1,固定增伤:只提升/降低特定技能的伤害百分比
if user.state?(108) && skill.id == 245
self.damage = self.damage * 200 / 100
end
if user.state?(108) && skill.id == 245
self.damage = self.damage * 200 / 100
end
也可以改成复数技能
if user.state?(108) && [1, 2, 3, 4, 5, 6].include?(skill.id)
self.damage = self.damage * 150 / 100
end
if user.state?(108) && [1, 2, 3, 4, 5, 6].include?(skill.id)
self.damage = self.damage * 150 / 100
end
9,猫箱:50%几率,使受到是伤害变成0
Game_Battler 3 194~195行
# HP 的伤害减法运算
last_hp = self.hp
# HP 的伤害减法运算
last_hp = self.hp
下面
if self.state?(109) && self.damage.is_a?(Numeric) && self.damage > 0
self.damage = 0 if rand(100) < 50 # 50%概率将伤害置0
end
if self.state?(109) && self.damage.is_a?(Numeric) && self.damage > 0
self.damage = 0 if rand(100) < 50 # 50%概率将伤害置0
end
作者: 灯笼菜刀王 时间: 2025-12-17 18:31
本帖最后由 灯笼菜刀王 于 2025-12-17 18:34 编辑
抓个虫, include?(100) 下面却是 delete(115)
只从@states里delete会有隐患, 因为还有个@states_turn留着, 而且也会让你之前费力问的"自动状态替换相关"失效, 笑, 建议用 remove_state(115)
回蓝也可以 @active_battler.damage = "SP+500" 这样来伤害显示, 不过这种做法会让 同时有中毒,回血,回蓝时只显示回蓝, 当然,你之前的写法会在 回血和中毒同时存在的时候只显示回血, 笑
而赖着不死状态, 玩家第一次碰到, 最多的反应会是"菜刀,又出BUG啦" ,摊手
效果有了, 如何表现最好也考虑下
作者: 无忧谷主幻 时间: 2025-12-19 20:09
数字填错,已经修改
SP伤害显示因为用久了彩虹神剑,我默认都是不显示的,不过根据情况不同确实可以加上
作者: 微妙夏伤_ 时间: 2026-1-11 02:04
关于第3点的属性增伤,大佬写的只是技能,我琢磨半天仿照技能的弄了个平A的。- # 计算基本伤害
- atk = [attacker.atk - self.pdef / 2, 0].max
- self.damage = atk * (20 + attacker.str) / 20
复制代码
通常攻击的这里替换成以下:- ####################附加状态后属性增伤#########################
- # 计算威力
- power = [attacker.atk - self.pdef / 2, 0].max
- sz = [[1,24,1.5],[11,39,1.3]]
- # 使用带1号属性的武器,在24号状态的作用下,威力1.5倍,使用带11号属性的技能,在39号状态的作用下,威力1.3倍
- for i in 0...sz.size
- if attacker.element_set.include?(sz[i][0]) and attacker.state?(sz[i][1])
- power *= sz[i][2]
- end
- atk = power
- self.damage = atk * (20 + attacker.str) / 20
- end
- ####################附加状态后属性增伤#########################
复制代码
作者: 微妙夏伤_ 时间: 2026-1-11 02:09
至于为什么取消了
【power /=10】这个,是因为我计算伤害的时候,应该打出108的打出了107,应该打出144的打出了142,然后发现是这个的原因。
然后特技里的这个反而要保留,我试着取消,发现如果是回血技能,*1.5倍(取消了/10的这一步),就会变成*150倍。。。
| 欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |