Jump to content

Recommended Posts

Hi! I'm trying to make an item that will be able to be used to revive a specific character after a specific time frame. I have made it so it's only hauntable after a certain amount of time, and I can make it revive on haunt, but have no idea how to make it so it only revives one specific character and then is destroyed. Is this easier done but making it so only the one character is able to haunt it or so the item will only revive in response to that one character haunting it? either would be a viable solution but I'm at a complete loss. Any help is appreciated!

Link to comment
https://forums.kleientertainment.com/forums/topic/162860-exclusionary-revive-item/
Share on other sites

You can use something like that

local assets =
{
    Asset("ANIM", "anim/yourprefab.zip"),
}

-- You can use it in modmain.lua
local VALID_CHARACTERS = {
    "wilson",
    "wendy",
    "wortox",
}

local function IsValidCharacter(victim) -- Checks for character
    if victim ~= nil and victim.prefab ~= nil then
        for _, character in ipairs(VALID_CHARACTERS) do
            if victim.prefab == character then -- If not, then ghost just haunts it and nothing happens, like if you'd haunt grass
                return true
            end
        end
    end
    return false
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    inst.entity:AddSoundEmitter()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("yourprefab")
    inst.AnimState:SetBuild("yourprefab")
    inst.AnimState:PlayAnimation("idle")

    inst:AddTag("resurrector")
    inst:AddTag("magical")

    inst.foleysound = "dontstarve/movement/foley/jewlery"

    MakeInventoryFloatable(inst, "med", nil, 0.6)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem:SetSinks(true)

    inst:AddComponent("hauntable")
    inst.components.hauntable:SetOnHauntFn(function(inst, haunter)
        if IsValidCharacter(haunter) then
            if haunter.DeathResurrectionPending then
                haunter:PushEvent("respawnfromghost", { source = inst })
                inst:Remove()
                return true
            end
        end
        return false
    end)

    return inst
end

return Prefab("yourprefab", fn, assets)

 

7 hours ago, Mr.CrazyPotato said:

You can use something like that

local assets =
{
    Asset("ANIM", "anim/yourprefab.zip"),
}

-- You can use it in modmain.lua
local VALID_CHARACTERS = {
    "wilson",
    "wendy",
    "wortox",
}

local function IsValidCharacter(victim) -- Checks for character
    if victim ~= nil and victim.prefab ~= nil then
        for _, character in ipairs(VALID_CHARACTERS) do
            if victim.prefab == character then -- If not, then ghost just haunts it and nothing happens, like if you'd haunt grass
                return true
            end
        end
    end
    return false
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    inst.entity:AddSoundEmitter()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("yourprefab")
    inst.AnimState:SetBuild("yourprefab")
    inst.AnimState:PlayAnimation("idle")

    inst:AddTag("resurrector")
    inst:AddTag("magical")

    inst.foleysound = "dontstarve/movement/foley/jewlery"

    MakeInventoryFloatable(inst, "med", nil, 0.6)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem:SetSinks(true)

    inst:AddComponent("hauntable")
    inst.components.hauntable:SetOnHauntFn(function(inst, haunter)
        if IsValidCharacter(haunter) then
            if haunter.DeathResurrectionPending then
                haunter:PushEvent("respawnfromghost", { source = inst })
                inst:Remove()
                return true
            end
        end
        return false
    end)

    return inst
end

return Prefab("yourprefab", fn, assets)

 

Wow thanks so much! Worked like a charm!

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...