饥荒
饥荒
平台PCPS4SwitchPS Vita
发售时间PC 2013-04-24+3
时长34小时(主线)
类型冒险游戏
官方中文支持
制作发行Klei Entertainment / Klei Entertainment
评分8.5和基友一起挨饿吧!
标签生存沙盒冒险单人探索

《饥荒》MOD制作图文教程 饥荒怎么制作MOD

类型:攻略发布日期:2015-11-19来源:饥荒游戏吧作者:首字母G🏷 饥荒 / MOD指南 / 攻略

  自己制作《饥荒》MOD是一件不简单的事,如果不懂代码那就更难了,不用担心!今天小编就为大家带来的《饥荒》制作MOD的图文教程,非常详细,代码部分都有解析,再也不用担心看不懂代码啦!下面就让我们一起看看《饥荒》是如何制作MOD吧。

第一部:工具下载

  1.官方mod工具

  有steam的童鞋可以在steam的库中找到工具一栏进入后下载安装

游民星空

游民星空

  PS:有了这个工具基本上就可以制作了。下面的工具都是为了方便。

  2.Textool

游民星空

游民星空

  tex文件编辑器下载地址:点击进入

  3.BuildRenamer-1.0

游民星空

  下载地址:ht请tp自://觉pan删.ba除idu.c中om/s文/1内zn容KF8

  用途:改mod(非自制)时修改动画内build文件的名称

第二步:确认mod的作用

  此部分全看自身的创意

  由于本帖结合楼主的自制mod‘goldcoin’讲解,撸主先说说goldcoin的设计思路吧。

  在易宁修改中,易宁哥提出了金融体系,货币这一说法。因此撸主想要制作饥荒的流通货币,并加入初步的交易系统(食物买卖)。

第三部:文件夹初步创建

  1.创建mod文件夹 goldcoin

  2.在goldcoin中创建文件夹

  ‘anim’(动画)

  ‘exported’(动画源文件)

  ‘images’(图标)

  ‘scripts’(代码)

  3.在exported中创建文件夹

  ‘exchange’(交易所)

  ‘goldcoin’(金币)

  4.在images中创建文件夹

  ‘inventoryimages’(图标)

  5.在scripts中创建文件夹

  ‘prefabs’(物件)

第四步:动画的创设

  1.寻找你所需要的图片素材

游民星空

游民星空

游民星空

游民星空

游民星空

游民星空

  把相应的图片素材放入相应的文件夹中

  比如

游民星空

  放入exported中的goldcoin。其余的放入exchange。

2.创建scml文件(动画的源文件)

  现在各个文件夹状态

游民星空

游民星空

游民星空

游民星空

游民星空

游民星空

游民星空

游民星空

游民星空

  然后打开Don't Starve Mod Tools\mod_tools\Spriter\Spriter

游民星空

  新建scml文件

游民星空

  选择OK

游民星空

  选择如图路径

游民星空

  点击选择文件夹

  修改下图位置

游民星空

  双击把entity_000改为exchange, NewAnimation改成idle,(即‘闲置’动画)

游民星空

  拖动右上角素材至灰色区域并组装好你的动画。这样子你的建筑物在建造后的成像就做好了。注意图中黑色细线交叉处基本就是你的动画在游戏时显示的显示图片的中心。尽量让左右对称,下部超出横线一点距离。如图所示。

游民星空

  点击上图第三个图标新建动画并改名为place,(即建造时预览的绿色部分)

游民星空

  拖动素材,拼接好你的place动画。

  然后

游民星空

  另存为

游民星空

  exchange

  对于goldcoin做相同处理,

游民星空

  注意这里没有place动画。另存为goldcoin.scml。

游民星空

  然后移动

游民星空

  整个Mod(而不是exported中的goldcoin。

  )至SteamLibrary\SteamApps\common\dont_starve\mods。

游民星空

  打卡Don't Starve Mod Tools\mod_tools中的autocompiler

游民星空

  稍等片刻后

游民星空

  结束后该程序会自动关闭。

  这时你会发现

游民星空

  anim中已有做好的动画文件了。

第五步:图标创设

  随便找个你已经有的mod,找到\images\inventoryimages

游民星空

  复制一组文件名对应的TEX和XML文件至我们做的mod的\images\inventoryimages(由于我们的mod中有exchange和goldcoin两个物件所以我们直接黏贴两下)

游民星空

  修改文件名与exchange和goldcoin对应。

游民星空

  打开xml文件,将原来的candycane分别对应修改成exchange和goldcoin。

游民星空

游民星空

游民星空

  打开textool中的TEXTool

游民星空

  用它打开exchange.tex

游民星空

  单击save按钮

游民星空

  另存到桌面

游民星空

  使用photoshop一类的图像制作软件打开你另存好的文件。

游民星空

  将原图标修改成你要的图标后储存为PNG格式

游民星空

游民星空

  打开TEXTool中的TEXCreator

游民星空

  勾选这两个方框

游民星空

  点击Add后选择修改好的文件

游民星空

  点击output下文字框后的.按钮选择输出路径

游民星空

  点击Convert后在输出路径中找到你的TEX文件

游民星空

  改名为exchang后移动到goldcoin\images\inventoryimages并选择替换。

游民星空

  以同样方式处理好goldcoin.tex

第六步:代码制作

  打开goldcoin\scripts\prefabs新建goldcoin和exchange的文本文档。

游民星空

  点击工具-文件夹选项-查看,去除勾选的隐藏已知文件类型的拓展名

游民星空

  然后把exchange和goldcoin的拓展名改为

游民星空

  双击打开goldcoin.lua写入

  local assets=

  {

  Asset("ANIM", "anim/goldcoin.zip"),

  Asset("ATLAS", "images/inventoryimages/goldcoin.xml"),

  }

  local function fn(Sim)

  local inst = CreateEntity()

  inst.entity:AddTransform()

  inst.entity:AddAnimState()

  inst.entity:AddSoundEmitter()

  inst.entity:AddPhysics()

  MakeInventoryPhysics(inst)

  inst.AnimState:SetBank("goldcoin")

  inst.AnimState:SetBuild("goldcoin")

  inst.AnimState:PlayAnimation("idle")

  inst:AddComponent("edible")

  inst.components.edible.foodtype = "ELEMENTAL"

  inst.components.edible.hungervalue = 2

  inst:AddComponent("tradable")

  inst:AddComponent("inspectable")

  inst:AddComponent("stackable")

  inst:AddComponent("inventoryitem")

  inst.components.inventoryitem.atlasname = "images/inventoryimages/goldcoin.xml"

  return inst

  end

  return Prefab( "common/inventory/goldcoin", fn, assets)

同样在exchange.lua中写入

  exchange.lua

  require "prefabutil"

  local assets =

  {

  Asset("ANIM", "anim/exchange.zip"),

  Asset("IMAGE", "images/inventoryimages/exchange.tex"),

  Asset("ATLAS", "images/inventoryimages/exchange.xml"),

  }

  local prefabs =

  {

  "exchange",

  }

  local function getstatus(inst)

  end

  local function onhammered(inst, worker)

  inst.components.lootdropper:DropLoot()

  SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())

  inst.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")

  inst:Remove()

  end

  local function onhit(inst, worker)

  inst.AnimState:PlayAnimation("hit")

  inst.AnimState:PushAnimation("idle", true)

  end

  local function onbuilt(inst)

  inst.AnimState:PlayAnimation("place")

  inst.AnimState:PushAnimation("idle")

  end

  local function fn(Sim)

  local inst = CreateEntity()

  local trans = inst.entity:AddTransform()

  local anim = inst.entity:AddAnimState()

  inst.entity:AddSoundEmitter()

  MakeObstaclePhysics(inst, 1)

  anim:SetBank("exchange")

  anim:SetBuild("exchange")

  anim:PlayAnimation("idle", true)

  inst:AddTag("structure")

  inst:AddTag("structure")

  inst:AddComponent("lootdropper")

  inst:AddComponent("workable")

  inst.components.workable:SetWorkAction(ACTIONS.HAMMER)

  inst.components.workable:SetWorkLeft(4)

  inst.components.workable:SetOnFinishCallback(onhammered)

  inst.components.workable:SetOnWorkCallback(onhit)

  inst:AddComponent("inspectable")

  local function ShouldAcceptItem(inst, item)

  if item:HasTag("hat") then

  return false

  end

  if item.components.edible.foodtype == "SEEDS" then

  return false

  end

  return true

  end

  local function OnGetItemFromPlayer(inst, giver, item)

  local names = {"cave_banana","carrot","corn","pumpkin","eggplant","durian","pomegranate","dragonfruit","berries","meat","smallmeat","fish","eel","drumstick","bird_egg","froglegs"}

  inst.name = names[math.random(#names)]

  local veggie = SpawnPrefab(inst.name)

  local goldcoin = SpawnPrefab("goldcoin")

  if item.components.edible.foodtype == "VEGGIE" then

  giver.components.inventory:GiveItem(goldcoin)

  end

  if item.components.edible.foodtype == "MEAT" then

  giver.components.inventory:GiveItem(goldcoin)

  end

  if item.prefab == "goldcoin" then

  giver.components.inventory:GiveItem(veggie or meat)

  end

  end

  inst:AddComponent("trader")

  inst.components.trader.onaccept = OnGetItemFromPlayer

  inst.components.trader:SetAcceptTest(ShouldAcceptItem)

  inst.components.inspectable.getstatus = getstatus

  return inst

  end

  return Prefab( "common/exchange", fn, assets, prefabs ),

  MakePlacer("common/exchange_placer", "exchange", "exchange", "idle")

第七步:完成MOD信息补录

  随便打开一个你已经有的MOD复制以下四个文件至咱的MOD。

游民星空

游民星空

  用TEXTool和Photoshop编辑好modicon.tex 这个文件就是你的mod在MOD界面显示的图标。因为无关紧要在这撸主就不改了。

  Modicon.xml不用修改。

  打开modinfo.lua

  name = "MOD的名字ˮ"

  description = "MOD的描述"

  author = "作者"

  version = "MOD的版本,随便填写"

  forumthread = "论坛地址"

  api_version = 当前MOD的版本(现在最新的应该是填写 5)

  icon_atlas = "modicon.xml"(不用修改)

  icon = "modicon.tex"(不用修改)

  打开modmain.lua

删除原有内容写入

  PrefabFiles = {

  "goldcoin",

  "exchange",

  }

  Assets=

  {

  Asset("ANIM", "anim/goldcoin.zip"),

  Asset("ATLAS", "images/inventoryimages/goldcoin.xml"),

  Asset("IMAGE", "images/inventoryimages/goldcoin.tex"),

  Asset("ANIM", "anim/exchange.zip"),

  Asset("ATLAS", "images/inventoryimages/exchange.xml"),

  Asset("IMAGE", "images/inventoryimages/exchange.tex"),

  }

  local STRINGS = GLOBAL.STRINGS

  local Recipe = GLOBAL.Recipe

  local Ingredient = GLOBAL.Ingredient

  local RECIPETABS = GLOBAL.RECIPETABS

  local TECH = GLOBAL.TECH

  STRINGS.NAMES.GOLDCOIN = "Goldcoin"

  STRINGS.RECIPE_DESC.GOLDCOIN = "For trade."

  STRINGS.CHARACTERS.GENERIC.DESCRIBE.GOLDCOIN = {"This is a goldcoin."}

  STRINGS.NAMES.EXCHANGE = "Exchange"

  STRINGS.RECIPE_DESC.EXCHANGE = "A place to recycle."

  STRINGS.CHARACTERS.GENERIC.DESCRIBE.EXCHANGE = {"An exchange."}

  local function ex()

  local exchange = Recipe("exchange", { Ingredient("cutstone", 8), Ingredient("goldnugget", 4), Ingredient("boards", 2) }, RECIPETABS.TOWN, TECH.SCIENCE_TWO, "exchange_placer")

  exchange.atlas = "images/inventoryimages/exchange.xml"

  end

  AddGamePostInit(ex)

  这样MOD就做好了,就可以拿去玩咯~

代码讲解

  goldcoin.lua部分

  local assets=

  {

  Asset("ANIM", "anim/goldcoin.zip"),

  Asset("ATLAS", "images/inventoryimages/goldcoin.xml"),

  }

  这部分的作用是读取动画和图标,可套用格式。(注意替换其中的goldcoin)

  local function fn(Sim)

  local inst = CreateEntity()

  inst.entity:AddTransform()

  inst.entity:AddAnimState()

  inst.entity:AddSoundEmitter()

  inst.entity:AddPhysics()

  MakeInventoryPhysics(inst)

  这部分的作用是创设物理性,可直接套用。

  inst.AnimState:SetBank("goldcoin")

  inst.AnimState:SetBuild("goldcoin")

  inst.AnimState:PlayAnimation("idle")

  这部分是引用动画,第一个goldcoin指的是的框架,第二个是模型,idle是播放的动画,为idle。请结合教程中的spriter软件的使用。

  inst:AddComponent("edible")

  inst.components.edible.foodtype = "ELEMENTAL"

  inst.components.edible.hungervalue = 2

  这部分是表示金币(goldcoin)可以作为一种元素类型的食物,参考金子(goldnugget)。

  inst:AddComponent("tradable")

  这部分表示金币(goldcoin)可以用来交易。交易的内容涵盖很多,给猪王玩具和肉获得金块也是一种交易。

  inst:AddComponent("inspectable")

  这部分表示金币(goldcoin)可以检阅。即右击物件后人物会说话。

  inst:AddComponent("stackable")

  这部分表示金币(goldcoin)可以叠加。

  inst:AddComponent("inventoryitem")

  inst.components.inventoryitem.atlasname = "images/inventoryimages/goldcoin.xml"

  这部分表示金币(goldcoin)在物品栏中显示的图标。套用时请修改其中的goldcoin。

  return inst

  end

  这部分return inst是对上面所有inst语句的终结。end是对上面local function fn(Sim)的终结。

  return Prefab( "common/inventory/goldcoin", fn, assets)

  这部分是返回物件的值。套用时请修改goldcoin。

exchange.lua代码详解

  require "prefabutil"

  需要prefabutil.lua建筑相关,所有建筑的lua直接引用。

  local assets =

  {

  Asset("ANIM", "anim/exchange.zip"),

  Asset("IMAGE", "images/inventoryimages/exchange.tex"),

  Asset("ATLAS", "images/inventoryimages/exchange.xml"),

  }

  读取动画和图标,可套用格式。(注意替换其中的exchange)

  local prefabs =

  {

  "exchange",

  }

  与exchange所有有关的物件都有写上。比如树苗的lua,不仅要写树苗的,还要写树枝,灰烬,这些产物。

  local function getstatus(inst)

  end

  使物件具有状态。

  local function onhammered(inst, worker)

  inst.components.lootdropper:DropLoot()

  SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())

  inst.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")

  inst:Remove()

  end

  使物件可以被锤子拆掉,并播放相关声音。

  local function onhit(inst, worker)

  inst.AnimState:PlayAnimation("hit")

  inst.AnimState:PushAnimation("idle", true)

  end

  可以打击,并播放相关动画。

  local function onbuilt(inst)

  inst.AnimState:PlayAnimation("place")

  inst.AnimState:PushAnimation("idle")

  end

  可以建筑,并调用建筑预览。

  local function fn(Sim)

  local inst = CreateEntity()

  local trans = inst.entity:AddTransform()

  local anim = inst.entity:AddAnimState()

  inst.entity:AddSoundEmitter()

  MakeObstaclePhysics(inst, 1) ---建筑物的占地大小

  设置物理性。

  anim:SetBank("exchange")

  anim:SetBuild("exchange")

  anim:PlayAnimation("idle", true)

  设置闲置时的动画

  inst:AddTag("structure")

  加入结构标签

  inst:AddComponent("lootdropper")

  加入战利品掉落功能

  inst:AddComponent("workable")

  inst.components.workable:SetWorkAction(ACTIONS.HAMMER)

  inst.components.workable:SetWorkLeft(4)

  inst.components.workable:SetOnFinishCallback(onhammered)

  inst.components.workable:SetOnWorkCallback(onhit)

  加入可被锤子砸和打击的功能。与上文呼应使用。

  inst:AddComponent("inspectable")

  可以检阅。

  local function ShouldAcceptItem(inst, item)

  可接受物品。

  if item:HasTag("hat") then

  return false

  end

  不接受有标签有hat的物品。

  if item.components.edible.foodtype == "SEEDS" then

  return false

  end

  不接受seeds。

  return true

  接受其他物件。

  end

  local function OnGetItemFromPlayer(inst, giver, item)

  local names = {"cave_banana","carrot","corn","pumpkin","eggplant","durian","pomegranate","dragonfruit","berries","meat","smallmeat","fish","eel","drumstick","bird_egg","froglegs"}

  inst.name = names[math.random(#names)]

  接受如上物件。

  local veggie = SpawnPrefab(inst.name)

  local goldcoin = SpawnPrefab("goldcoin")

  if item.components.edible.foodtype == "VEGGIE" then

  giver.components.inventory:GiveItem(goldcoin)

  end

  接受蔬菜后回馈一个goldcoin。

  if item.components.edible.foodtype == "MEAT" then

  giver.components.inventory:GiveItem(goldcoin)

  end

  接受肉后回馈一个goldcoin。

  giver.components.inventory:GiveItem(veggie or meat)

  接受goldcoin后回馈一个肉或者蔬菜

  end

  end

  inst:AddComponent("trader")

  加入交易功能

  inst.components.trader.onaccept = OnGetItemFromPlayer

  inst.components.trader:SetAcceptTest(ShouldAcceptItem)

  inst.components.inspectable.getstatus = getstatus

  可接受物件。

  return inst

  结束inst

  end

  结束function

  return Prefab( "common/exchange", fn, assets, prefabs ),

  返回物件的值

  MakePlacer("common/exchange_placer", "exchange", "exchange", "idle")

  返回建筑预览时的动画

  modmain部分代码

  PrefabFiles = {

  "goldcoin",

  "exchange",

  }

  固定格式,请输入相关物件名称。

  Assets=

  {

  Asset("ANIM", "anim/goldcoin.zip"),

  Asset("ATLAS", "images/inventoryimages/goldcoin.xml"),

  Asset("IMAGE", "images/inventoryimages/goldcoin.tex"),

  Asset("ANIM", "anim/exchange.zip"),

  Asset("ATLAS", "images/inventoryimages/exchange.xml"),

  Asset("IMAGE", "images/inventoryimages/exchange.tex"),

  }

  动画和图标路径设置。

  local STRINGS = GLOBAL.STRINGS

  local Recipe = GLOBAL.Recipe

  local Ingredient = GLOBAL.Ingredient

  local RECIPETABS = GLOBAL.RECIPETABS

  local TECH = GLOBAL.TECH

  整体参数设置,直接复制黏贴就行。

  STRINGS.NAMES.GOLDCOIN = "Goldcoin" 物件名称

  STRINGS.RECIPE_DESC.GOLDCOIN = "For trade."建造栏描述

  STRINGS.CHARACTERS.GENERIC.DESCRIBE.GOLDCOIN = {"This is a goldcoin."} 检阅时描述。

  STRINGS.NAMES.EXCHANGE = "Exchange"

  STRINGS.RECIPE_DESC.EXCHANGE = "A place to recycle."

  STRINGS.CHARACTERS.GENERIC.DESCRIBE.EXCHANGE = {"An exchange."}

  同上。

  local function ex() 固定格式,ex可任意跟换,不要和and,or 这些术语一样就行。

  local exchange = Recipe("exchange", { Ingredient("cutstone", 8), Ingredient("goldnugget", 4), Ingredient("boards", 2) }, RECIPETABS.TOWN, TECH.SCIENCE_TWO, "exchange_placer") 设置建造时的材料,分类,科技需求,调用的建筑预览动画

  exchange.atlas = "images/inventoryimages/exchange.xml"

  设置建造栏显示的图标

  end

  AddGamePostInit(ex) 固定格式,ex与上文的ex一致。

本文内容来自网络收集整理,版权归原作者所有。 · 所属游戏:饥荒
← 返回 饥荒 攻略列表

同游戏其他攻略共 2368 篇

《饥荒》8.14幕间休息更新公告攻略2026-08-14《饥荒》发条骑士之年活动说明攻略2026-02-24《饥荒》建筑自燃解决方法 夏天家具自燃怎么办攻略2026-01-13《饥荒》夏天地震解决方法 夏天地震怎么办攻略2026-01-13《饥荒》降温食物一览 哪些食物能够降温攻略2026-01-13《饥荒》哈姆雷特温和季玩法教学攻略2026-01-13《饥荒》季节BOSS打法技巧 冬季BOSS独眼巨鹿怎么打攻略2026-01-13《饥荒》哈姆雷特毁灭季机制介绍 猪镇大灾变怎么结束攻略2026-01-12《饥荒》海难飓风季玩法教程 飓风季怎么过攻略2026-01-12《饥荒》海难雨季玩法教程 海难雨季怎么防水攻略2026-01-12《饥荒》海难温和季生存教学 海难开局怎么玩攻略2026-01-12《饥荒》远古织影者召唤方法 远古织影者在哪打攻略2026-01-12《饥荒》海难火山季生存教学 火山季怎么玩攻略2026-01-12《饥荒》梦魇疯猪位置及打法分享 梦魇疯猪怎么打攻略2026-01-12《饥荒》食物保鲜手段汇总 怎么降低食物腐烂速度攻略2026-01-11《饥荒》哈姆雷特日晷寻找技巧 日晷在哪个岛攻略2026-01-11《饥荒》沃利特性及调味料加成介绍 大厨调味料有什么效果攻略2026-01-11《饥荒》角色饱食度特殊设定汇总攻略2026-01-11《饥荒》全角色喜爱食物一览攻略2026-01-11《饥荒》哈姆雷特全岛屿介绍 哈姆雷特地形一览攻略2026-01-11《饥荒》天体英雄打法参考 天体英雄怎么打攻略2026-01-11《饥荒》启蒙值机制介绍 启蒙值怎么降低攻略2026-01-11《饥荒》过冬准备说明 冬天怎么保暖攻略2026-01-11《饥荒》绝望石套装介绍 绝望石套装适合谁攻略2026-01-11《饥荒》下雨应对方法 春天下雨怎么解决攻略2026-01-11《饥荒》夏季降温方法 饥荒夏季温度怎么降低攻略2026-01-11《饥荒》夏季玩法教学 夏季怎么降温攻略2026-01-11《饥荒》猪王交易表 猪王要什么攻略2026-01-11《饥荒》兔人介绍与招募方法 毛毛王怎么出现攻略2026-01-11《饥荒》洞穴探索知识讲解攻略2026-01-08