Jump to content

Make player lose sanity when near spiders


Recommended Posts

local function spidersanityaura(inst)
	local x, y, z = inst.Transform:GetWorldPosition()
	local delta = 0
	local ents = TheSim:FindEntities(x, y, z, 20, {"spider"}) -- you can change 20 if you want it happen near or far
	local bonus_sanity = nil
	local distsq = nil
    	local totalDelta = nil
  	
	for k, v in pairs(ents) do
		if v ~= inst then
			if v.prefab == "spider" then
				bonus_sanity = -TUNING.SANITYAURA_MEDIUM -- you can change medium to change amount of sanity your character lost 
				distsq = math.max(inst:GetDistanceSqToInst(v), 1)
				delta = delta + bonus_sanity / distsq
				
  			else
			end
		end
        totalDelta = totalDelta + delta
	end
    
    if #ents > 0 then
    	totalDelta = totalDelta / #ents
    else
    	totalDelta = 0
    end
    
	return totalDelta
end

im using this one for lose sanity near something (forgive my english its not my main language) put that in your character.lua

 

	inst.components.sanity.custom_rate_fn = spidersanityaura
	inst:DoPeriodicTask(1, spidersanityaura)

and this in master_postinit this must work

Link to comment
Share on other sites

4 hours ago, AkaiNight said:

local function spidersanityaura(inst)
	local x, y, z = inst.Transform:GetWorldPosition()
	local delta = 0
	local ents = TheSim:FindEntities(x, y, z, 20, {"spider"}) -- you can change 20 if you want it happen near or far
	local bonus_sanity = nil
	local distsq = nil
    	local totalDelta = nil
  	
	for k, v in pairs(ents) do
		if v ~= inst then
			if v.prefab == "spider" then
				bonus_sanity = -TUNING.SANITYAURA_MEDIUM -- you can change medium to change amount of sanity your character lost 
				distsq = math.max(inst:GetDistanceSqToInst(v), 1)
				delta = delta + bonus_sanity / distsq
				
  			else
			end
		end
        totalDelta = totalDelta + delta
	end
    
    if #ents > 0 then
    	totalDelta = totalDelta / #ents
    else
    	totalDelta = 0
    end
    
	return totalDelta
end

im using this one for lose sanity near something (forgive my english its not my main language) put that in your character.lua

 


	inst.components.sanity.custom_rate_fn = spidersanityaura
	inst:DoPeriodicTask(1, spidersanityaura)

and this in master_postinit this must work

Hey! I used this on my character, but now i get disconnected from my server everytime i come near a spider, even as a ghost.

I've also tried some code from the post below,

but it just crashes my game at the character select screen. I'm kinda lost.

Edited by Navii0
Link to comment
Share on other sites

local function spidersanityaura(inst)
	local x, y, z = inst.Transform:GetWorldPosition()
	local delta = 0
	local ents = TheSim:FindEntities(x, y, z, 20, {"critter_puppy", "spider" , "critter_kitten"})
	local bonus_sanity = nil
	local distsq = nil
    	local totalDelta = nil
	
	for k, v in pairs(ents) do
		if v ~= inst then

			if v:HasTag ("spider") then
				bonus_sanity = -TUNING.SANITYAURA_LARGE
				distsq = math.max(inst:GetDistanceSqToInst(v), 1)
				delta = delta + bonus_sanity / distsq
			
			else
			end
		end
        totalDelta = totalDelta + delta
	end
    
    if #ents > 0 then
    	totalDelta = totalDelta / #ents
    else
    	totalDelta = 0
    end
    
	return totalDelta
end

use this one and do not remove critters they're not doing anything but now it works fine

Link to comment
Share on other sites

7 hours ago, AkaiNight said:

local function spidersanityaura(inst)
	local x, y, z = inst.Transform:GetWorldPosition()
	local delta = 0
	local ents = TheSim:FindEntities(x, y, z, 20, {"critter_puppy", "spider" , "critter_kitten"})
	local bonus_sanity = nil
	local distsq = nil
    	local totalDelta = nil
	
	for k, v in pairs(ents) do
		if v ~= inst then

			if v:HasTag ("spider") then
				bonus_sanity = -TUNING.SANITYAURA_LARGE
				distsq = math.max(inst:GetDistanceSqToInst(v), 1)
				delta = delta + bonus_sanity / distsq
			
			else
			end
		end
        totalDelta = totalDelta + delta
	end
    
    if #ents > 0 then
    	totalDelta = totalDelta / #ents
    else
    	totalDelta = 0
    end
    
	return totalDelta
end

use this one and do not remove critters they're not doing anything but now it works fine

Thanks, im gonna check it out!

Link to comment
Share on other sites

10 hours ago, AkaiNight said:

I tested it and it works fine for me idk what is the problem but here is my test characters lua

esctemplate.lua 3.54 kB · 0 downloads

I tested the code by setting the sanity aura to a big positive number, and i still lost sanity like in the normal DST. I have no clue what's happening, Here's my character's lua. Im probably doing a dumb mistake and im not noticing it.

 

navii.lua

Link to comment
Share on other sites

27 minutes ago, Navii0 said:

I tested the code by setting the sanity aura to a big positive number, and i still lost sanity like in the normal DST. I have no clue what's happening, Here's my character's lua. Im probably doing a dumb mistake and im not noticing it.

 

navii.lua 4.02 kB · 1 download

Well you just need to change 

bonus_sanity = TUNING.SANITYAURA_SUPERHUGE

with this

bonus_sanity = -TUNING.SANITYAURA_SUPERHUGE

you miss the '-' lol also im not sure about "SUPERHUGE" you can change it with

bonus_sanity = -TUNING.SANITYAURA_LARGE * 2 --as example you will lose 2x large sanity now

 

Edited by AkaiNight
Link to comment
Share on other sites

33 minutes ago, AkaiNight said:

Well you just need to change 


bonus_sanity = TUNING.SANITYAURA_SUPERHUGE

with this


bonus_sanity = -TUNING.SANITYAURA_SUPERHUGE

you miss the '-' lol also im not sure about "SUPERHUGE" you can change it with


bonus_sanity = -TUNING.SANITYAURA_LARGE * 2 --as example you will lose 2x large sanity now

 

I i changed it to

bonus_sanity = TUNING.SANITYAURA_SUPERHUGE

on purpose, to check if it even works. I does not work with

bonus_sanity = -TUNING.SANITYAURA_SUPERHUGE

anyway :/

 

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...