Mobbstar Posted May 18, 2014 Share Posted May 18, 2014 I want to make a custom character with the perk of gaining sanity when near shadow creatures (and maybe night light) rather than losing it. I want spiders and such to make you insane like normal though. I started by copying Willows perk of gaining sanity by fire and removing the burning bits and replacing "fire" with "flower_evil" (for testing purposes). This is what the code looks like:local function sanityfn(inst) local x,y,z = inst.Transform:GetWorldPosition() local delta = 0 local rad = 5 local ents = TheSim:FindEntities(x,y,z, rad, {"flower_evil"}) for k,v in pairs(ents) do local sz = TUNING.SANITYAURA_MED-- local rad = 1-- sz = sz * ( math.min(max_rad, rad) / max_rad ) I don't think those two lines are necessary. local distsq = inst:GetDistanceSqToInst(v) delta = delta + sz/math.max(1, distsq) end return deltaendlocal fn = function(inst) --cut out some unrelated pieces. inst.components.sanity:SetMax(TUNING.WILSON_SANITY * 0.8 ) inst.components.sanity.custom_rate_fn = sanityfnendUnfortunately, something (maybe the line outside the function) makes the presence of evil flowers not raise my current sanity, but rather slightly drop my maximum sanity (the effect never goes away). I don't quite understand the sanity code yet, not at all to be honest. I am thankful for any code suggestions, constructive questions or explanations. Link to comment https://forums.kleientertainment.com/forums/topic/36573-help-sanity-influence-of-objects/ Share on other sites More sharing options...
Rincevvind Posted May 18, 2014 Share Posted May 18, 2014 (edited) probably you have to change evil flowers instead of player local function MakeGood(inst) if inst and inst.components then if not inst.components.sanityaura then inst:AddComponent("sanityaura") end inst.components.sanityaura.aura = GLOBAL.TUNING.SANITYAURA_MED endend AddPrefabPostInit("flower_evil", MakeGood)--AddPrefabPostInit("someotherprefab", MakeGood)-- add more prefabs here but tbh MED is too much Edited May 18, 2014 by Rincevvind Link to comment https://forums.kleientertainment.com/forums/topic/36573-help-sanity-influence-of-objects/#findComment-483391 Share on other sites More sharing options...
Mobbstar Posted May 18, 2014 Author Share Posted May 18, 2014 That was a quick reply... Sadly, now the game crashes. I've attached the log.txt, it says that AddPrefabPostInit is not declared. I've tried to put the line alone and in fn. Am I supposed to declare it earlier in the file? I am not even sure what's going on anymore Link to comment https://forums.kleientertainment.com/forums/topic/36573-help-sanity-influence-of-objects/#findComment-483395 Share on other sites More sharing options...
Rincevvind Posted May 18, 2014 Share Posted May 18, 2014 (edited) you trying to add this in prefabs/wilfre.lua but you have to put this code in modmain.lua Edited May 18, 2014 by Rincevvind Link to comment https://forums.kleientertainment.com/forums/topic/36573-help-sanity-influence-of-objects/#findComment-483398 Share on other sites More sharing options...
Rincevvind Posted May 18, 2014 Share Posted May 18, 2014 (edited) well bad side of this method - code will work for all characters, so better to test it with local function MakeGood(inst) local p = GLOBAL.GetPlayer() if inst and inst.components and p and p.prefab=="wilfre" then if not inst.components.sanityaura then inst:AddComponent("sanityaura") end inst.components.sanityaura.aura = GLOBAL.TUNING.SANITYAURA_MED endendbut i am unsure about it Edited May 18, 2014 by Rincevvind Link to comment https://forums.kleientertainment.com/forums/topic/36573-help-sanity-influence-of-objects/#findComment-483400 Share on other sites More sharing options...
Mobbstar Posted May 18, 2014 Author Share Posted May 18, 2014 Now it makes sense, duh. Thank you so very much, mr modding magician. This code of yours is worth its weight in gold. And I get it for free! = ) Link to comment https://forums.kleientertainment.com/forums/topic/36573-help-sanity-influence-of-objects/#findComment-483404 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