Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local assets =
- {
- Asset("ANIM", "anim/warhammer.zip"),
- Asset("ANIM", "anim/swap_warhammer.zip"),
- Asset("ATLAS", "images/inventoryimages/warhammer.xml"),
- Asset("IMAGE", "images/inventoryimages/warhammer.tex"),
- }
- local function onfinished(inst)
- inst:Remove()
- end
- local function onequip(inst, owner)
- owner.AnimState:OverrideSymbol("swap_object", "swap_warhammer", "swap_warhammer")
- owner.SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")
- owner.AnimState:Show("ARM_carry")
- owner.AnimState:Hide("ARM_normal")
- end
- local function onunequip(inst, owner)
- owner.AnimState:Hide("ARM_carry")
- owner.AnimState:Show("ARM_normal")
- end
- -------------------------------------------
- -- List of ingredients to return.
- local ingredients = {
- "spear",
- "spear",
- }
- -- Give player ingredients.
- local function returningredients(inst)
- for k,ingredient in pairs(ingredients) do
- GetPlayer().components.inventory:GiveItem(ingredient)
- end
- end
- -- OnSave and OnLoad, so that we only give ingredients once.
- local function onload(inst, data)
- if data and data.wascrafted then
- inst.wascrafted = data.wascrafted
- end
- end
- local function onsave(inst, data)
- if inst.wascrafted then
- data.wascrafted = inst.wascrafted
- end
- end
- -------------------------------------------
- local function fn(Sim)
- local inst = CreateEntity()
- local trans = inst.entity:AddTransform()
- local anim = inst.entity:AddAnimState()
- MakeInventoryPhysics(inst)
- inst.AnimState:SetBank("warhammer")
- inst.AnimState:SetBuild("warhammer")
- inst.AnimState:PushAnimation("idle")
- inst:AddTag("sharp")
- inst:AddComponent("weapon")
- inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE)
- inst:AddComponent("finiteuses")
- inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES*2)
- inst.components.finiteuses:SetUses(TUNING.SPEAR_USES*2)
- inst.components.finiteuses:SetOnFinished( onfinished )
- inst:AddComponent("inspectable")
- inst:AddComponent("inventoryitem")
- inst.components.inventoryitem.imagename = "warhammer"
- inst.components.inventoryitem.atlasname = "images/inventoryimages/warhammer.xml"
- inst:AddComponent("equippable")
- inst.components.equippable:SetOnEquip( onequip )
- inst.components.equippable:SetOnUnequip( onunequip )
- ----------------------------------
- -- Save so that we don't do this more than once.
- inst.OnSave = onsave
- inst.OnLoad = onload
- -- Return ingredients.
- if not inst.wascrafted then
- returningredients()
- end
- ----------------------------------
- return inst
- end
- return Prefab( "common/warhammer", fn, assets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement