饥荒mod制作吧 关注:2,791贴子:11,863

超精简原版人物升级系统mod

只看楼主收藏回复



IP属地:浙江1楼2017-01-25 15:34回复
    以前问过同学,如果要做mod,做怎样的比较好,同学是威屌档,觉得想要玩一个扩展化的威屌。
    于是我就一直朝着这个方向试着去做。
    刚开始我想岔了,想要以一个mod人物的形式去做,然后发现麻烦的要死。后来换了个方向,终于成功了。


    IP属地:浙江2楼2017-01-25 15:37
    回复
      modmain里面的代码:
      local function randomDo(rate, func, ...)
      local num = math.random(1, 100)
      if rate <= num then
      func(...)
      end
      end
      local function updateAtk(inst)
      inst.components.combat.damagemultiplier = 1 + inst.atk_level / 100
      inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * (1 + inst.atk_level / 200))
      end
      local function updateSanity(inst)
      local sanity_percent = inst.components.sanity:GetPercent()
      inst.components.sanity.max = math.ceil (200 + inst.sanity_level * 1.5)
      inst.components.sanity:SetPercent(sanity_percent)
      end
      local function updateSpeed(inst)
      inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * (1 + inst.speed_level / 200))
      inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * (1 + inst.speed_level / 200))
      end
      local function updateHealth(inst)
      local health_percent = inst.components.health:GetPercent()
      inst.components.health.maxhealth = math.ceil (150 + inst.health_level * 1.5)
      inst.components.health:SetPercent(health_percent)
      end
      local function updateHunger(inst)
      local hunger_percent = inst.components.hunger:GetPercent()
      inst.components.hunger.max = math.ceil (150 + inst.hunger_level * 1.5)
      inst.components.hunger:SetPercent(hunger_percent)
      end
      local function atkLevelUp(inst)
      if inst.atk_level >= 100 then
      inst.components.talker:Say('power max!')
      else
      inst.atk_level = inst.atk_level + 1
      inst.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
      end
      updateAtk(inst)
      end
      local function sanityLevelUp(inst)
      if inst.sanity_level >= 100 then
      inst.components.talker:Say('sanity max!')
      else
      inst.sanity_level = inst.sanity_level + 1
      inst.HUD.controls.status.brain:ScaleTo(1.3,1,.7)
      end
      updateSanity(inst)
      end
      local function speedLevelUp(inst)
      if inst.speed_level >= 100 then
      inst.components.talker:Say('speed max!')
      else
      inst.components.talker:Say('speed up!'..(inst.speed_level))
      inst.speed_level = inst.speed_level + 1
      end
      updateSpeed(inst)
      end
      local function healthLevelUp(inst)
      if inst.health_level >= 100 then
      inst.components.talker:Say('health max!')
      else
      inst.health_level = inst.health_level + 1
      inst.HUD.controls.status.heart:ScaleTo(1.3,1,.7)
      end
      updateHealth(inst)
      end
      local function hungerLevelUp(inst)
      if inst.hunger_level >= 100 then
      inst.components.talker:Say('stomach max!')
      else
      inst.hunger_level = inst.hunger_level + 1
      inst.HUD.controls.status.stomach:ScaleTo(1.3,1,.7)
      end
      updateHunger(inst)
      end
      local function onEat(inst, food)
      if food then
      --怪物肉,10%几率升级攻击力
      if food.prefab == "monstermeat" then
      randomDo(10, atkLevelUp, inst)
      --怪物千层饼,50%几率升级攻击力
      elseif food.prefab == "monstermonsterlasagna" then
      randomDo(50, atkLevelUp, inst)
      --下略
      elseif food.prefab == "fruitmedley" or food.prefab == "jammypreserves" then
      randomDo(5, sanityLevelUp, inst)
      elseif food.prefab == "butterflymuffin" then
      randomDo(30, sanityLevelUp, inst)
      elseif food.prefab == "stuffedeggplant" or food.prefab == "pumpkincookie" then
      randomDo(50, sanityLevelUp, inst)
      elseif food.prefab == "frogglebunwich" then
      randomDo(20, speedLevelUp, inst)
      elseif food.prefab == "turkeydinner" then
      randomDo(30, speedLevelUp, inst)
      elseif food.prefab == "fishtacos" then
      randomDo(50, speedLevelUp, inst)
      elseif food.prefab == "dragonpie" then
      randomDo(80, healthLevelUp, inst)
      elseif food.prefab == 'waffles' then
      randomDo(80, healthLevelUp, inst)
      elseif food.prefab == 'kabobs' then
      randomDo(10, hungerLevelUp, inst)
      elseif food.prefab == 'honeynuggets' then
      randomDo(30, hungerLevelUp, inst)
      end
      end
      end
      --刷新所有属性
      local function applyupgrades(inst)
      updateHunger(inst)
      updateHealth(inst)
      updateSpeed(inst)
      updateSanity(inst)
      updateAtk(inst)
      end
      --预加载时,读取存档数据里面的
      local function onpreload(inst, data)
      if data then
      --未使用该mod的旧档里没有等级数据,如果是旧档,则等级设置为0
      inst.hunger_level = data.hunger_level or 0
      inst.health_level = data.health_level or 0
      inst.sanity_level = data.sanity_level or 0
      inst.atk_level = data.atk_level or 0
      inst.speed_level = data.speed_level or 0
      applyupgrades(inst)
      --re-set these from the save data, because of load-order clipping issues
      if data.health and data.health.health then inst.components.health.currenthealth = 30 end
      if data.hunger and data.hunger.hunger then inst.components.hunger.current = data.hunger.hunger end
      if data.sanity and data.sanity.current then inst.components.sanity.current = data.sanity.current end
      inst.components.health:DoDelta(0)
      inst.components.hunger:DoDelta(0)
      inst.components.sanity:DoDelta(0)
      end
      end
      --存档时将人物的各项等级保存下来
      local function onsave(inst, data)
      data.hunger_level = inst.hunger_level
      data.health_level = inst.health_level
      data.sanity_level = inst.sanity_level
      data.atk_level = inst.atk_level
      data.speed_level = inst.speed_level
      end
      local function plus(inst)
      --初始化各项等级为0
      inst.hunger_level = 0
      inst.health_level = 0
      inst.sanity_level = 0
      inst.atk_level = 0
      inst.speed_level = 0
      --设置吃东西后调用函数,根据食物不同升级
      inst.components.eater:SetOnEatFn(onEat)
      --设置保存函数,在存档时调用
      inst.OnSave = onsave
      --设置预加载函数,在人物预加载时调用
      inst.OnPreLoad = onpreload
      end
      AddPlayerPostInit(function(inst)
      if inst.prefab == "wilson" then
      plus(inst)
      end
      end)


      IP属地:浙江3楼2017-01-25 15:38
      收起回复
        modinfo里面的信息:
        name = "wilsonplus"
        description = "sssssssssup wilson!"
        author = "Jing"
        version = "Public preview version"
        forumthread = ""
        -- This lets other players know if your mod is out of date, update it to match the current version in the game
        api_version = 6


        IP属地:浙江4楼2017-01-25 15:38
        回复
          以上就是全部,只要modmain和一个modinfo两个不可缺少的文件即可,并且modmain里的代码已经很精简了,不到两百行。


          IP属地:浙江5楼2017-01-25 15:39
          收起回复
            可以直接拷贝过去就能用,这个mod给威尔逊赋予了一套升级系统:
            吃生怪物肉/怪物千层饼 提升攻击力上限 增加饱食度消耗速率
            最高2倍伤害 1.5倍饥饿速率
            蝴蝶松饼/果酱羹/茄子饭/南瓜饼/水果拼盘 加精神上限
            butterflymuffin/jammypreserves/stuffedeggplant/pumpkincookie/fruitmedley
            最高350精神
            移动速度
            火鸡大餐 青蛙汉堡/玉米饼鱼
            turkeydinner/frogglebunwich /fishtacos
            最高1.5倍速度
            火龙果派/华夫饼 血量上限
            dragonpie/waffles
            最高300血量上限
            饱食度上限
            肉串/蜜汁金砖
            kabobs/honeynuggets
            最高300饱食度上限


            IP属地:浙江6楼2017-01-25 15:40
            回复

              最后面的这个函数是重点


              IP属地:浙江7楼2017-01-25 15:44
              收起回复
                AddSimPostInit(function(inst)
                if inst.prefab == "wodb" then
                WodbPostInit(inst)
                end
                end)
                我原本是看到了贴吧里教程上的一个人物mod里面有这样一个函数
                于是我想着通过用这种函数给人物附加一些东西进去
                但,用这里的AddSimPostInit是不行的
                通过做打印测试,发现这里注册的函数,执行时间是在人物加载完了之后
                我们的修改往往要改掉人物的OnSave保存和OnPreLoad预加载函数
                所以进了档了才调用到这个地方,那么加载时用的是没有修改前的系统的函数,简单地说,就是保存之后再打开,没有读取到我们存好的数据


                IP属地:浙江8楼2017-01-25 15:49
                回复
                  然后全局搜索了一下这个AddSimPostInit
                  因为理论上来说,类似的其他API应该是和它放在一起的
                  然后我搜索到了data/scripts/modutil.lua这个文件


                  IP属地:浙江9楼2017-01-25 15:52
                  回复
                    很多的mod接口都在这里


                    IP属地:浙江10楼2017-01-25 15:52
                    回复
                      问你个问题,用过做出来为啥没显示?但是可以收获到物品栏就能正常显示,


                      IP属地:四川11楼2017-01-26 09:35
                      收起回复
                        你这个其实可以稍微多解析一下,培养出只会抄的moder是没用的


                        来自Android客户端12楼2017-01-27 11:11
                        回复
                          有做好的文件没??


                          IP属地:河南来自Android客户端13楼2017-02-02 13:32
                          收起回复
                            lz,求注释


                            IP属地:广东来自Android客户端14楼2017-02-03 00:06
                            回复
                              支持全人物了吗?


                              IP属地:福建来自Android客户端15楼2017-02-04 12:27
                              回复