Jump to content

Recommended Posts

So I've made my very first mod with the Extended Sample Character, now I'd like to add perks. The character I made is an embalmer/undertaker, and doesn't fear the dead. Is there any way to remove/lower sanity drain when digging graves and being around ghosts? Thank you! 

I'm making a character mod that does the same thing and I do have an answer for whenever the character digs up graves!
In my modmain.lua I have this:

local LOOTS =
{
    nightmarefuel = 1,
    amulet = 1,
    gears = 1,
    redgem = 5,
    bluegem = 5,
}

local function spawnghost(inst, chance)
    if inst.ghost == nil and math.random() <= (chance or 1) then
        inst.ghost = GLOBAL.SpawnPrefab("ghost")
        if inst.ghost ~= nil then
            local x, y, z = inst.Transform:GetWorldPosition()
            inst.ghost.Transform:SetPosition(x - .3, y, z - .3)
            inst:ListenForEvent("onremove", function() inst.ghost = nil end, inst.ghost)
            return true
        end
    end
    return false
end


local function onfinishcallback(inst, worker)
    inst.AnimState:PlayAnimation("dug")
    inst:RemoveComponent("workable")
	
    if worker ~= nil then
        if worker.components.sanity ~= nil and worker:HasTag("custom_character_tag") then
            worker.components.sanity:DoDelta(grave_rob_sanity)
        elseif worker.components.sanity ~= nil then
			worker.components.sanity:DoDelta(-TUNING.SANITY_SMALL)
		end
        if not spawnghost(inst, .1) and worker.components.inventory ~= nil then
            local item = nil
            if math.random() < .5 then
                item = GLOBAL.weighted_random_choice(LOOTS)
            else
                item = "trinket_"..tostring(math.random(12))
            end

            if item ~= nil then
                inst.components.lootdropper:SpawnLootPrefab(item)
            end
        end
    end
end

AddPrefabPostInit("mound", function(inst)
	if GLOBAL.TheWorld.ismastersim then
		inst.components.workable:SetOnFinishCallback(onfinishcallback)
	end
end)

And then in my character's lua file, I give it the tag in it's common postinit that makes this happen when the grave is dug
 

inst:AddTag("custom_character_tag")

Hope this helps! This is my first time helping someone on the forum and will clarify anything if necessary

Edited by bnutters
5 hours ago, bnutters said:

I'm making a character mod that does the same thing and I do have an answer for whenever the character digs up graves!
In my modmain.lua I have this:


local LOOTS =
{
    nightmarefuel = 1,
    amulet = 1,
    gears = 1,
    redgem = 5,
    bluegem = 5,
}

local function spawnghost(inst, chance)
    if inst.ghost == nil and math.random() <= (chance or 1) then
        inst.ghost = GLOBAL.SpawnPrefab("ghost")
        if inst.ghost ~= nil then
            local x, y, z = inst.Transform:GetWorldPosition()
            inst.ghost.Transform:SetPosition(x - .3, y, z - .3)
            inst:ListenForEvent("onremove", function() inst.ghost = nil end, inst.ghost)
            return true
        end
    end
    return false
end


local function onfinishcallback(inst, worker)
    inst.AnimState:PlayAnimation("dug")
    inst:RemoveComponent("workable")
	
    if worker ~= nil then
        if worker.components.sanity ~= nil and worker:HasTag("custom_character_tag") then
            worker.components.sanity:DoDelta(grave_rob_sanity)
        elseif worker.components.sanity ~= nil then
			worker.components.sanity:DoDelta(-TUNING.SANITY_SMALL)
		end
        if not spawnghost(inst, .1) and worker.components.inventory ~= nil then
            local item = nil
            if math.random() < .5 then
                item = GLOBAL.weighted_random_choice(LOOTS)
            else
                item = "trinket_"..tostring(math.random(12))
            end

            if item ~= nil then
                inst.components.lootdropper:SpawnLootPrefab(item)
            end
        end
    end
end

AddPrefabPostInit("mound", function(inst)
	if GLOBAL.TheWorld.ismastersim then
		inst.components.workable:SetOnFinishCallback(onfinishcallback)
	end
end)

And then in my character's lua file, I give it the tag in it's common postinit that makes this happen when the grave is dug
 


inst:AddTag("custom_character_tag")

Hope this helps! This is my first time helping someone on the forum and will clarify anything if necessary

Would I just paste these into the mentioned files?

On 10/10/2021 at 7:14 AM, bnutters said:

I'm making a character mod that does the same thing and I do have an answer for whenever the character digs up graves!
In my modmain.lua I have this:


local LOOTS =
{
    nightmarefuel = 1,
    amulet = 1,
    gears = 1,
    redgem = 5,
    bluegem = 5,
}

local function spawnghost(inst, chance)
    if inst.ghost == nil and math.random() <= (chance or 1) then
        inst.ghost = GLOBAL.SpawnPrefab("ghost")
        if inst.ghost ~= nil then
            local x, y, z = inst.Transform:GetWorldPosition()
            inst.ghost.Transform:SetPosition(x - .3, y, z - .3)
            inst:ListenForEvent("onremove", function() inst.ghost = nil end, inst.ghost)
            return true
        end
    end
    return false
end


local function onfinishcallback(inst, worker)
    inst.AnimState:PlayAnimation("dug")
    inst:RemoveComponent("workable")
	
    if worker ~= nil then
        if worker.components.sanity ~= nil and worker:HasTag("custom_character_tag") then
            worker.components.sanity:DoDelta(grave_rob_sanity)
        elseif worker.components.sanity ~= nil then
			worker.components.sanity:DoDelta(-TUNING.SANITY_SMALL)
		end
        if not spawnghost(inst, .1) and worker.components.inventory ~= nil then
            local item = nil
            if math.random() < .5 then
                item = GLOBAL.weighted_random_choice(LOOTS)
            else
                item = "trinket_"..tostring(math.random(12))
            end

            if item ~= nil then
                inst.components.lootdropper:SpawnLootPrefab(item)
            end
        end
    end
end

AddPrefabPostInit("mound", function(inst)
	if GLOBAL.TheWorld.ismastersim then
		inst.components.workable:SetOnFinishCallback(onfinishcallback)
	end
end)

And then in my character's lua file, I give it the tag in it's common postinit that makes this happen when the grave is dug
 


inst:AddTag("custom_character_tag")

Hope this helps! This is my first time helping someone on the forum and will clarify anything if necessary

Hey I know you weren't talking to me, but i have trouble with this. I paste these into my character mod's modmain.lua but whenever i dig it crashes the game. How do I fix this?

(Yes, I gave my character the tag)

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