Scolip3de Posted October 7, 2021 Share Posted October 7, 2021 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! Link to comment https://forums.kleientertainment.com/forums/topic/134298-i-need-help-making-a-specific-perk/ Share on other sites More sharing options...
bnutters Posted October 10, 2021 Share Posted October 10, 2021 (edited) 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 October 10, 2021 by bnutters Link to comment https://forums.kleientertainment.com/forums/topic/134298-i-need-help-making-a-specific-perk/#findComment-1503430 Share on other sites More sharing options...
Scolip3de Posted October 10, 2021 Author Share Posted October 10, 2021 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? Link to comment https://forums.kleientertainment.com/forums/topic/134298-i-need-help-making-a-specific-perk/#findComment-1503503 Share on other sites More sharing options...
TemporarySolutn Posted October 10, 2021 Share Posted October 10, 2021 (edited) 5 hours ago, Scolip3de said: Would I just paste these into the mentioned files? Yes (or better yet, try it for yourself) Edited October 10, 2021 by TemporarySolutn Link to comment https://forums.kleientertainment.com/forums/topic/134298-i-need-help-making-a-specific-perk/#findComment-1503567 Share on other sites More sharing options...
Sneaky Axolxtl Posted October 20, 2021 Share Posted October 20, 2021 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) Link to comment https://forums.kleientertainment.com/forums/topic/134298-i-need-help-making-a-specific-perk/#findComment-1505578 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now