Jump to content

Sanity loss and gain script problems


Recommended Posts

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
Share on other sites

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
Share on other sites

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
 Share

×
  • Create New...