Guest User

Untitled

a guest
May 18th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. require "prefabutil"
  2. require "recipe"
  3. require "modutil"
  4.  
  5. local assets=
  6. {
  7.     Asset("ANIM", "anim/myprefab_build.zip"),
  8.     Asset("ATLAS", "images/inventoryimages/myprefab.xml"),
  9.     Asset("IMAGE", "images/inventoryimages/myprefab.tex"),
  10. }
  11.  
  12. local prefabs = {}
  13.  
  14. local function onhammered(inst, worker)
  15.     inst.components.lootdropper:DropLoot()
  16.     inst.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
  17.     inst:Remove()
  18. end
  19.  
  20. local slotpos = {}
  21. for y = 2, 1, -1 do
  22.     for x = 0, 2 do
  23.         table.insert(slotpos, Vector3(80*x-80*2+80, 80*y-80*2+80,0))
  24.     end
  25. end
  26.  
  27. local myprefab =
  28. {
  29. }
  30.  
  31. local function onopen(inst)
  32.  
  33. end
  34.  
  35. local function onclose(inst)
  36.  
  37. end
  38.  
  39. local function onbuilt(inst)
  40.     inst.AnimState:PlayAnimation("idle")
  41.     inst.AnimState:PushAnimation("idle", false)
  42. end
  43.  
  44. local function fn(Sim)
  45.     local inst = CreateEntity()
  46.     inst.entity:AddTransform()
  47.     inst.entity:AddAnimState()
  48.     inst.entity:AddSoundEmitter()
  49.     inst.entity:AddNetwork()
  50.    
  51.     local minimap = inst.entity:AddMiniMapEntity()
  52.     minimap:SetIcon( "myprefab.tex" )
  53.    
  54.     inst:AddTag("structure")
  55.     MakeObstaclePhysics(inst, .5)
  56.    
  57.     inst.AnimState:SetBank("myprefab")
  58.     inst.AnimState:SetBuild("myprefab")
  59.     inst.AnimState:PlayAnimation("idle")
  60.  
  61.     if not TheWorld.ismastersim then
  62.         return inst
  63.     end
  64.    
  65.     inst.entity:SetPristine()
  66.    
  67.     inst:AddComponent("container")
  68.     inst.components.container:WidgetSetup("myprefab", myprefab)
  69.     inst.components.container.onopenfn = onopen
  70.     inst.components.container.onclosefn = onclose
  71.  
  72.  
  73.     inst:AddComponent("inspectable")
  74.     inst.components.inspectable.getstatus = getstatus
  75.  
  76.     inst:AddComponent("lootdropper")
  77.  
  78.     inst:AddComponent("workable")
  79.     inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
  80.     inst.components.workable:SetWorkLeft(4)
  81.     inst.components.workable:SetOnFinishCallback(onhammered)
  82.  
  83.     return inst
  84. end
  85.  
  86. return Prefab( "common/myprefab", fn, assets, prefabs),
  87.         MakePlacer( "common/myprefab", "myprefab", "myprefab", "idle" )
Advertisement
Add Comment
Please, Sign In to add comment