游民星空 > 攻略秘籍 > 攻略 > 正文

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

2015-11-19 14:20:43 来源:饥荒游戏吧 作者:首字母G 我要投稿

第10页:第六步代码制作(2)

展开

同样在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")

更多相关内容请关注:饥荒专区

责任编辑:修凡客

上一页 1 2 3 4 5 6 7 8 9 10 11 下一页
友情提示:支持键盘左右键“← →”翻页

本文是否解决了您的问题

游民星空APP
随手浏览游戏攻略
code
攻略合集
单机游戏下载
休闲娱乐
综合热点资讯
游民星空联运游戏