Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local assets = {
- Asset("ANIM", "anim/sunlight_talisman.zip"),
- Asset("ANIM", "anim/sunlight_talisman_swap.zip"),
- }
- local mycharacter
- local function onFinished(inst)
- inst.SoundEmitter:PlaySound("dontstarve/common/gem_shatter")
- inst:Remove()
- end
- local function onAttack(inst)
- inst.SoundEmitter:PlaySound("dontstarve/music/thunder_close")
- inst:Remove()
- end
- local function onEquip(inst, owner)
- owner.AnimState:OverrideSymbol("swap_object", "sunlight_talisman_swap", "sunlight_talisman_swap")
- 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
- local function onAttack(inst, attacker, target)
- target.components.combat:GetAttacked(attacker, 20*3)
- end
- local function healHimSpell(inst, target)
- print (target)
- target.components.health:DoDelta(20*2)
- target.SoundEmitter:PlaySound("dontstarve/common/makeFriend")
- end
- local function healSpell(inst, target, pos)
- if target then --used on target
- healHimSpell(inst, target)
- else --used on some position or from inventory
- mycharacter = GetPlayer()
- healHimSpell(inst, mycharacter)
- end
- end
- local function canHeal(inst, caster, target)
- --target
- if target and target.components.health then return true end
- --no health targets
- if target and not target.components.health then return false end
- --inventory
- if not target then return true end
- end
- local function fn()
- local inst = CreateEntity()
- inst.entity:AddTransform()
- inst.entity:AddAnimState()
- inst.entity:AddSoundEmitter()
- --inst.entity:AddNetwork()
- MakeInventoryPhysics(inst)
- inst.AnimState:SetBank("sunlight_talisman")
- inst.AnimState:SetBuild("sunlight_talisman")
- inst.AnimState:PlayAnimation("idle")
- inst:AddTag("nopunch")
- --inst.entity:SetPristine()
- --[[
- if not TheWorld.ismastersim then
- return inst
- end
- ]]
- inst:AddComponent("finiteuses")
- inst.components.finiteuses:SetMaxUses(40)
- inst.components.finiteuses:SetUses(40)
- inst.components.finiteuses:SetConsumption(ACTIONS.CASTSPELL, 1)
- inst.components.finiteuses:SetOnFinished(onFinished)
- inst:AddComponent("inspectable")
- inst:AddComponent("weapon")
- inst.components.weapon:SetDamage(0)
- inst.components.weapon:SetRange(8, 10)
- inst.components.weapon:SetOnAttack(onAttack)
- inst.components.weapon:SetProjectile("lightning_projectile")
- inst:AddComponent("inventoryitem")
- inst.components.inventoryitem.atlasname = "images/inventoryimages/sunlight_talisman.xml"
- inst:AddComponent("equippable")
- inst.components.equippable:SetOnEquip(onEquip)
- inst.components.equippable:SetOnUnequip(onUnequip)
- inst:AddComponent("spellcaster")
- inst.components.spellcaster.canuseontargets = true
- inst.components.spellcaster.canuseonpoint = false
- inst.components.spellcaster.canusefrominventory = true
- inst.components.spellcaster:SetSpellTestFn(canHeal)
- inst.components.spellcaster:SetSpellFn(healSpell)
- return inst
- end
- return Prefab("common/inventory/sunlight_talisman", fn, assets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement