Jump to content

Anyway to make a character lose sanity by being near insane characters?


Recommended Posts

Hiya there, I was looking for some help with a character I'm creating.

He's gonna be sort of a therapist character, increasing sanity of nearby people. But, I also want it to be that insanity sort of rubs off on him. Like, making it so that if he's near someone who's below, let's say, 50% sanity, then he will start to lose sanity.

How would I go about doing this?

Link to comment
Share on other sites

I would suggest you take a look at this function:

TheSim:FindEntities(x, y, z, radius, musttags, canttags, mustoneoftags)

Since every player has the tag "player" you could use this to find players around your character.

Link to comment
Share on other sites

13 hours ago, WubbleWubble said:

Hiya there, I was looking for some help with a character I'm creating.

He's gonna be sort of a therapist character, increasing sanity of nearby people. But, I also want it to be that insanity sort of rubs off on him. Like, making it so that if he's near someone who's below, let's say, 50% sanity, then he will start to lose sanity.

How would I go about doing this?

5 hours ago, WubbleWubble said:

Thank you, is there anyway to check if the players around him are insane?

inst:DoPeriodicTask(
    1.0,
    function(inst)
        local x, y, z = inst.Transform:GetWorldPosition()
        local ents = TheSim:FindEntities(x, y, z, 4.0, {"player"}, {"playerghost"})
        local selfsanity = 1
        for _,v in pairs(ents)
        do
            if v~=inst
            then
                v.components.sanity:DoDelta(1)
                if v.components.sanity:IsCrazy()
                then
                    selfsanity = selfsanity - 1
                end
            end
        end
        inst.components.sanity:DoDelta(selfsanity)
    end
)

I commented out the 50% sanity thing and have the sane portion.

This would be in the master_postinit callback.

4.0 = radius of effect, and is 1 turf square in size for relative dimension comparing.

Edited by CarlZalph
'he' usage unclear, changed specification to mean 'other person'
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...