bunlux Posted September 16, 2017 Share Posted September 16, 2017 (reposted due to originally misplacing this thread in the singleplayer forum; sorry about that!) Original: --- Hello! I'm currently working on a custom DST character mod, and I have everything working except for the perk(s), which I have... next to no idea how to code. Basically, I was hoping to have my character gain sanity from being near catcoons, similarly to how most monsters' auras drain sanity, but with a positive effect. I've tried looking in various .lua files to study the other characters' perks, but I'm not finding much of use, and I'm afraid to fiddle with any code when I have literally no idea what works and what doesn't. My first thought was to look in Wolfgang's .lua because of the drain he gets at night and around monsters, but... "inst.components.sanity.night_drain_mult = 1.1" I don't know if this is what I'm looking for, nor do I know how I would change this to fit what I need. "inst.components.sanity.catcoon_gain_mult = 1.3" ? I feel like that wouldn't work, but if it does, can someone please let me know? Any and all help is appreciated, thank you! --- I've since been told that the sanity aura is from the mobs themselves, not in the character files, but I still don't know where to go from there. I've also been told that coding this might be a bit complex, but I'm willing to put the time and effort in if I can get a little more help. Does anyone have a clue as to how to approach this? Thank you. Link to comment https://forums.kleientertainment.com/forums/topic/82069-help-w-catcoon-sanity-gain-perk/ Share on other sites More sharing options...
Lumina Posted September 16, 2017 Share Posted September 16, 2017 local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, {"mole"}) local delta = 0 for k, v in pairs(ents) do local distsq = math.max(inst:GetDistanceSqToInst(v), 1) delta = delta - TUNING.SANITYAURA_SMALL / distsq end return delta end This is the code i'm using to lose sanity near moles. Maybe by changing the prefab and changing the negative delta for a positive one, you could have something like you want ? inst.components.sanity.custom_rate_fn = sanityfn This line goes in masterpostinit. Link to comment https://forums.kleientertainment.com/forums/topic/82069-help-w-catcoon-sanity-gain-perk/#findComment-954809 Share on other sites More sharing options...
bunlux Posted September 16, 2017 Author Share Posted September 16, 2017 (edited) Oh! Thank you so much @Lumina! Though I'm a little fuzzy on how exactly to change the delta to positive. Would it be something like: local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, {"catcoon"}) local delta = 0 for k, v in pairs(ents) do local distsq = math.max(inst:GetDistanceSqToInst(v), 1) delta = delta + TUNING.SANITYAURA_SMALL / distsq end return delta end (delta + TUNING.SANITYAURA_SMALL) or: local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, {"catcoon"}) local delta = 1 for k, v in pairs(ents) do local distsq = math.max(inst:GetDistanceSqToInst(v), 1) delta = delta - TUNING.SANITYAURA_SMALL / distsq end return delta end (local delta = 1)? Edited September 16, 2017 by bunlux Link to comment https://forums.kleientertainment.com/forums/topic/82069-help-w-catcoon-sanity-gain-perk/#findComment-954826 Share on other sites More sharing options...
Lumina Posted September 16, 2017 Share Posted September 16, 2017 I would try the first solution. See if it works and if the result fit your taste. Link to comment https://forums.kleientertainment.com/forums/topic/82069-help-w-catcoon-sanity-gain-perk/#findComment-954830 Share on other sites More sharing options...
bunlux Posted September 16, 2017 Author Share Posted September 16, 2017 Uh, well. Is this an error due to misplacement? Here's where I put the code, under "local prefabs = {": local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), } local prefabs = { local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, {"catcoon"}) local delta = 0 for k, v in pairs(ents) do local distsq = math.max(inst:GetDistanceSqToInst(v), 1) delta = delta + TUNING.SANITYAURA_SMALL / distsq end return delta end } If it is misplaced, where should I move it/what should I tweak? If it isn't, how can I fix this? Link to comment https://forums.kleientertainment.com/forums/topic/82069-help-w-catcoon-sanity-gain-perk/#findComment-954836 Share on other sites More sharing options...
Lumina Posted September 16, 2017 Share Posted September 16, 2017 It shouldn't be into the prefabs. Mine is here : local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, {"mole"}) local delta = 0 for k, v in pairs(ents) do local distsq = math.max(inst:GetDistanceSqToInst(v), 1) delta = delta - TUNING.SANITYAURA_SMALL / distsq end return delta end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) inst:AddTag("mycharactertag") -- Minimap icon inst.MiniMapEntity:SetIcon( "mycharactername.tex" ) end Link to comment https://forums.kleientertainment.com/forums/topic/82069-help-w-catcoon-sanity-gain-perk/#findComment-954844 Share on other sites More sharing options...
bunlux Posted September 16, 2017 Author Share Posted September 16, 2017 It works perfectly now! Thank you sososo much!!! You've been a huge help :') Link to comment https://forums.kleientertainment.com/forums/topic/82069-help-w-catcoon-sanity-gain-perk/#findComment-954853 Share on other sites More sharing options...
Lumina Posted September 16, 2017 Share Posted September 16, 2017 Great Link to comment https://forums.kleientertainment.com/forums/topic/82069-help-w-catcoon-sanity-gain-perk/#findComment-954854 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