gmod吧 关注:90,623贴子:1,903,301
  • 19回复贴,共1

[教程]在你的游戏模式中用lua来关闭玩家伤害(伪)

只看楼主收藏回复

这个教程最核心的就是Entity:SetHealth( number newHealth )这个函数


IP属地:山东1楼2018-05-23 13:25回复
    玩过gmod沙盒模式的人都知道,在游戏里可以启用或关闭玩家伤害;但是在自己制作的游戏模式里不能关闭(好像)。所以,我们应该用lua来模仿一个关闭玩家伤害的脚本。


    IP属地:山东2楼2018-05-23 13:27
    回复
      2025-08-08 11:11:47
      广告
      不感兴趣
      开通SVIP免广告
      先在init.lua里加上一句:function GM:PlayerHurt(victim,attacker,healthRemaining,damageTaken )
      victim:受害者(被伤害者)
      attacker:攻击者(打人者)
      healthRemaining:剩余生命
      damageTaken:伤害血量


      IP属地:山东3楼2018-05-23 13:30
      回复(2)
        下面再加上:if (attacker:IsPlayer()) then
        if:判断命令
        attacker:攻击者(打人者)
        在变量后加上 : 表示调用这个变量的类型的方法
        IsPlayer()是否为玩家,如果是返回true(是)如果不是返回false(否)


        IP属地:山东4楼2018-05-23 13:36
        回复
          victim:SetHealth(healthRemaining+damageTaken)
          victim:受害者(被伤害者)
          SetHealth():设置血量 [关键代码]
          healthRemaining+damageTaken:剩余生命+伤害血量=先前血量 (可能会有1血的误差)


          IP属地:山东5楼2018-05-23 13:38
          回复
            最后在单独两行加上end表示if和function的结束


            IP属地:山东6楼2018-05-23 13:39
            回复
              所以全代码为
              function GM:PlayerHurt(victim,attacker,healthRemaining,damageTaken )
              if (attacker:IsPlayer()) then
              victim:SetHealth(healthRemaining+damageTaken)
              end
              end


              IP属地:山东7楼2018-05-23 13:52
              回复
                支持


                IP属地:广东来自iPhone客户端8楼2018-05-23 15:52
                回复
                  2025-08-08 11:05:47
                  广告
                  不感兴趣
                  开通SVIP免广告
                  你这是要干什么


                  IP属地:浙江来自iPhone客户端9楼2018-05-23 16:24
                  收起回复
                    日常改代码,也亏得老游戏好改


                    IP属地:内蒙古来自Android客户端10楼2018-05-24 00:30
                    收起回复