MarilouXD Posted April 11, 2018 Share Posted April 11, 2018 Hey, I wanted my character to lose sanity near fire and gain sanity near animals. I added two functions for both of the but only the one ( specifically the gain sanity one) works. I tried to add both in one function but since I'm still learning how to work with scripts (blame my teachers and my laziness) I made a mess and none of them worked. I believe that it's the "inst.components.sanity.custom_rate_fn = " command that I used twice that cause's the problem. Any ideas or help I could use both. alice.lua Link to comment https://forums.kleientertainment.com/forums/topic/89741-sanity-loss-and-gain-script-problems/ Share on other sites More sharing options...
K1NGT1GER609 Posted April 12, 2018 Share Posted April 12, 2018 Eh this maybe lazy and sloppy but: local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, nil, nil, {"Goose", "mossling", "bearger", "chester", "grassgekko", "pigman", "werepig", "merm", "pigguard", "butterfly", "beefalo", "babybeefalo", "robin", "robin_winter", "fireflies", "perd", "koalefant_summer", "koalefant_winter", "penguin", "rabbit","bunnyman", "monkey", -- RoG "catcoon", "mole", "lightninggoat", "lavae", --Chess piece and minotaur "bishop", "rook", "knight", -- SW "parrot", "parrot_pirate", "seagull", "toucan", "whale_blue", "ballphin", "primeape", "ox", "doydoy", "doydoybaby"}) local things = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, nil, nil, {"fire"}) --lol things local delta = 0 for k, v in pairs(ents) do local distsq = math.max(inst:GetDistanceSqToInst(v),1) delta = TUNING.SANITYAURA_MED end for k, v in pairs(things) do local distsq = math.max(inst:GetDistanceSqToInst(v),1) delta = delta - TUNING.SANITYAURA_LARGE / distsq end return delta end local master_postinit = function(inst) inst.components.sanity.custom_rate_fn = sanityfn --THATS ALL YOU NEED I hope I didn't make any errors while I'm half awake. Link to comment https://forums.kleientertainment.com/forums/topic/89741-sanity-loss-and-gain-script-problems/#findComment-1025758 Share on other sites More sharing options...
MarilouXD Posted April 13, 2018 Author Share Posted April 13, 2018 Thanks it works nice. I had tried to add both elements in one function but with if-else. Link to comment https://forums.kleientertainment.com/forums/topic/89741-sanity-loss-and-gain-script-problems/#findComment-1026025 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