Jump to content

Sanityaura on equipped weapon


Recommended Posts

I was hoping to make a weapon that would grant sanity to all players nearby at a cost of hunger and speed to the player equipping it.  I've got it working on the user by using a modified version of the red amulet code, but changing inst.components.sanityaura.aura on equip doesn't seem to be having any effect. Thoughts anyone?  Full code below

 

local assets ={    Asset("ANIM", "anim/violin.zip"),    Asset("ANIM", "anim/swap_violin.zip"),        Asset("ATLAS", "images/inventoryimages/violin.xml"),    Asset("IMAGE", "images/inventoryimages/violin.tex"),}local function playviolin(inst, owner)    if (owner.components.sanity and owner.components.sanity.current < owner.components.sanity.max)    and (owner.components.hunger and owner.components.hunger.current > 5) then        owner.components.sanity:DoDelta(TUNING.REDAMULET_CONVERSION,false,"violin")        owner.components.hunger:DoDelta(-TUNING.REDAMULET_CONVERSION)    endendlocal function onequip(inst, owner)    owner.AnimState:OverrideSymbol("swap_object", "swap_violin", "swap_violin")    owner.AnimState:Show("ARM_carry")    owner.AnimState:Hide("ARM_normal")    inst.components.sanityaura.aura = TUNING.SANITYAURA_TINY    inst.task = inst:DoPeriodicTask(20, playviolin, nil, owner)endlocal function onunequip(inst, owner)    owner.AnimState:Hide("ARM_carry")    owner.AnimState:Show("ARM_normal")    inst.components.sanityaura.aura = 0    if inst.task ~= nil then        inst.task:Cancel()        inst.task = nil    endendlocal function fn()    local inst = CreateEntity()    inst.entity:AddTransform()    inst.entity:AddAnimState()    inst.entity:AddSoundEmitter()    inst.entity:AddNetwork()    MakeInventoryPhysics(inst)    inst.AnimState:SetBank("violin")    inst.AnimState:SetBuild("violin")    inst.AnimState:PlayAnimation("idle")    inst.entity:SetPristine()    if not TheWorld.ismastersim then        return inst    end        inst:AddComponent("sanityaura")    inst.components.sanityaura.aura = 0        inst:AddComponent("weapon")    inst.components.weapon:SetDamage(TUNING.CANE_DAMAGE)    inst:AddComponent("inspectable")    inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "violin"    inst.components.inventoryitem.atlasname = "images/inventoryimages/violin.xml"    inst.components.inventoryitem.keepondeath = true    inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip(onequip)    inst.components.equippable:SetOnUnequip(onunequip)    inst.components.equippable.walkspeedmult = 0.5    MakeHauntableLaunch(inst)    return instendreturn Prefab("common/inventory/violin", fn, assets)
 
Link to comment
Share on other sites

 

I was hoping to make a weapon that would grant sanity to all players nearby at a cost of hunger and speed to the player equipping it.  I've got it working on the user by using a modified version of the red amulet code, but changing inst.components.sanityaura.aura on equip doesn't seem to be having any effect. Thoughts anyone?  Full code below

 

local assets ={    Asset("ANIM", "anim/violin.zip"),    Asset("ANIM", "anim/swap_violin.zip"),        Asset("ATLAS", "images/inventoryimages/violin.xml"),    Asset("IMAGE", "images/inventoryimages/violin.tex"),}local function playviolin(inst, owner)    if (owner.components.sanity and owner.components.sanity.current < owner.components.sanity.max)    and (owner.components.hunger and owner.components.hunger.current > 5) then        owner.components.sanity:DoDelta(TUNING.REDAMULET_CONVERSION,false,"violin")        owner.components.hunger:DoDelta(-TUNING.REDAMULET_CONVERSION)    endendlocal function onequip(inst, owner)    owner.AnimState:OverrideSymbol("swap_object", "swap_violin", "swap_violin")    owner.AnimState:Show("ARM_carry")    owner.AnimState:Hide("ARM_normal")    inst.components.sanityaura.aura = TUNING.SANITYAURA_TINY    inst.task = inst:DoPeriodicTask(20, playviolin, nil, owner)endlocal function onunequip(inst, owner)    owner.AnimState:Hide("ARM_carry")    owner.AnimState:Show("ARM_normal")    inst.components.sanityaura.aura = 0    if inst.task ~= nil then        inst.task:Cancel()        inst.task = nil    endendlocal function fn()    local inst = CreateEntity()    inst.entity:AddTransform()    inst.entity:AddAnimState()    inst.entity:AddSoundEmitter()    inst.entity:AddNetwork()    MakeInventoryPhysics(inst)    inst.AnimState:SetBank("violin")    inst.AnimState:SetBuild("violin")    inst.AnimState:PlayAnimation("idle")    inst.entity:SetPristine()    if not TheWorld.ismastersim then        return inst    end        inst:AddComponent("sanityaura")    inst.components.sanityaura.aura = 0        inst:AddComponent("weapon")    inst.components.weapon:SetDamage(TUNING.CANE_DAMAGE)    inst:AddComponent("inspectable")    inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "violin"    inst.components.inventoryitem.atlasname = "images/inventoryimages/violin.xml"    inst.components.inventoryitem.keepondeath = true    inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip(onequip)    inst.components.equippable:SetOnUnequip(onunequip)    inst.components.equippable.walkspeedmult = 0.5    MakeHauntableLaunch(inst)    return instendreturn Prefab("common/inventory/violin", fn, assets)

 

You need to add sanity aura to owner of the item, not to the item itself.

If its only added to the item it works only on the player that wears it.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...