Jump to content

Recommended Posts

Hello. I have this custom revival item called soul that you're supposed to haunt and get revived. After revival it's supposed to destroy itself. But it doesn't I would really apreciate it if someone could help me.

soul.lua attached

 

thanks in advance

soul.lua

Edited by igel69

The thing you want to do looks like something Life-Giving Amulet does

taking a look at it's code:
this looks like something you want
 

local function red()
    local inst = commonfn("redamulet", "resurrector", true)

    if not TheWorld.ismastersim then
        return inst
    end

    -- red amulet now falls off on death, so you HAVE to haunt it
    -- This is more straightforward for prototype purposes, but has side effect of allowing amulet steals
    -- inst.components.inventoryitem.keepondeath = true

    inst.components.equippable:SetOnEquip(onequip_red)
    inst.components.equippable:SetOnUnequip(onunequip_red)

    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetOnFinished(inst.Remove)
    inst.components.finiteuses:SetMaxUses(TUNING.REDAMULET_USES)
    inst.components.finiteuses:SetUses(TUNING.REDAMULET_USES)

    inst:AddComponent("hauntable")
    inst.components.hauntable:SetHauntValue(TUNING.HAUNT_INSTANT_REZ)

    return inst
end

 

  • Like 1

The problem probably lies in the fact that the game checks if it's a lifeamulet or not and then destroys it, as nothing else is destroying it.

You could try adding a SetOnHauntFn to your prefab that checks if the haunter is a ghost and then removes it in the next frame.

local function OnHaunt(inst,doer)
  if doer:HasTag("playerghost") then
    	inst:DoTaskInTime(0,function(inst) inst:Remove() end)
    	return true
    end
end

inst.components.hauntable:SetOnHauntFn(OnHaunt)

 

  • Like 1
1 hour ago, Monti18 said:

The problem probably lies in the fact that the game checks if it's a lifeamulet or not and then destroys it, as nothing else is destroying it.

You could try adding a SetOnHauntFn to your prefab that checks if the haunter is a ghost and then removes it in the next frame.


local function OnHaunt(inst,doer)
  if doer:HasTag("playerghost") then
    	inst:DoTaskInTime(0,function(inst) inst:Remove() end)
    	return true
    end
end

inst.components.hauntable:SetOnHauntFn(OnHaunt)

 

Wow, thanks so much. I have posted 3 times in this forum and every single time it was you helping me out and fixing it. I reallly apreciate it :)

  • Like 1

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
×
  • Create New...