Navii0 Posted September 11, 2020 Share Posted September 11, 2020 How can i make the player lose sanity when near spiders? I have searched around and tried some things, but i have no idea what to really do. Any help? Link to comment Share on other sites More sharing options...
krylincy Posted September 11, 2020 Share Posted September 11, 2020 For every player? Then you can add a higher sanity aura to the spiders with "inst:AddComponent("sanityaura") .... " Link to comment Share on other sites More sharing options...
AkaiNight Posted September 12, 2020 Share Posted September 12, 2020 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 More sharing options...
Navii0 Posted September 12, 2020 Author Share Posted September 12, 2020 (edited) 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 September 12, 2020 by Navii0 Link to comment Share on other sites More sharing options...
AkaiNight Posted September 13, 2020 Share Posted September 13, 2020 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 More sharing options...
Navii0 Posted September 13, 2020 Author Share Posted September 13, 2020 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 More sharing options...
Navii0 Posted September 13, 2020 Author Share Posted September 13, 2020 I played around with the script, but it didn't do anything. The game didn't crash, but the sanity loss remained the same. I have no idea why it didnt work. Link to comment Share on other sites More sharing options...
AkaiNight Posted September 14, 2020 Share Posted September 14, 2020 12 hours ago, Navii0 said: I played around with the script, but it didn't do anything. The game didn't crash, but the sanity loss remained the same. I have no idea why it didnt work. I tested it and it works fine for me idk what is the problem but here is my test characters lua esctemplate.lua Link to comment Share on other sites More sharing options...
Navii0 Posted September 14, 2020 Author Share Posted September 14, 2020 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 More sharing options...
AkaiNight Posted September 14, 2020 Share Posted September 14, 2020 (edited) 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 September 14, 2020 by AkaiNight Link to comment Share on other sites More sharing options...
Navii0 Posted September 14, 2020 Author Share Posted September 14, 2020 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 More sharing options...
Navii0 Posted September 14, 2020 Author Share Posted September 14, 2020 In simpler words, theres already a negative sanity aura from spiders in the original game, i just want it to be much bigger for my character. I cant figure it out. Link to comment 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