查看: 2130|回复: 1

[已经解决] 怎么实现自动回血也能把小数点保留

[复制链接]
梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

发表于 2016-3-27 13:38:17 | 显示全部楼层 |阅读模式

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

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

×
[pre lang="ruby"]        #每秒恢复生命魔法HPMP
        unless self.battler == nil
          if Graphics.frame_count % 40 == 0
          hp = self.battler.maxhp/100
          if hp < 1
          @hhp = 0  if @hhp == nil
            @hhp += hp
            end
          sp = self.battler.maxsp/100
          self.battler.hp+=hp
          self.battler.sp+=sp
          unless @hhp < 1 and @hhp == nil
            @hhp -= (@hhp).to_i
          end
        end
        end
[/pre]

我写了这么一段,可是只有当恢复的HP是整数,也就是至少是1的时候,才会恢复。
是小数点的时候并不能恢复,多久都不会恢复。
我就加了个HHP来存小数,当HHP整数了就恢复,然后HHP再取小数点。

评分

参与人数 1星屑 +35 收起 理由
RyanBern + 35 手动认可奖励

查看全部评分

梦石
0
星屑
9716
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2016-3-27 13:49:03 | 显示全部楼层
本帖最后由 cinderelmini 于 2016-3-27 23:37 编辑
  1. #每秒恢复生命魔法HPMP
  2.         if self.battler
  3.           @thp ||= 0.0
  4.           @tsp ||= 0.0
  5.           if Graphics.frame_count % 40 == 0
  6.             hp = self.battler.maxhp / 100.0
  7.             sp = self.battler.maxsp / 100.0
  8.             @thp += hp
  9.             @tsp += sp
  10.             if @thp.to_i > 1
  11.               self.battler.hp += @thp.to_i
  12.               @thp -= @thp.to_i
  13.             end
  14.             if @tsp.to_i > 1
  15.               self.battler.sp += @tsp.to_i
  16.               @tsp -= @tsp.to_i
  17.             end
  18.           end
  19.         end
复制代码
也许能成?

点评

哦,这个我已经自己改过了,还有>1改成了>=1  发表于 2016-3-28 11:58
改了一下,现在这样比较靠谱……  发表于 2016-3-27 23:37
可以。谢谢  发表于 2016-3-27 20:53

评分

参与人数 2星屑 +220 收起 理由
RyanBern + 200 认可答案
夜狠简单 + 20 塞糖

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部