The_Knife_Pie Posted February 6, 2021 Share Posted February 6, 2021 (edited) I'm making a character and my plan is for him to have a constant sanity drain, and then gain sanity depending on nearby player built structures. However I don't know how I would implement this on the character side as opposed to making every structure have a sanity aura. Any advice or tips is welcomed Edited February 6, 2021 by The_Knife_Pie Link to comment Share on other sites More sharing options...
Combustiblemon Posted February 7, 2021 Share Posted February 7, 2021 local function machinelover(inst) if inst:HasTag("playerghost") then return end if inst.components.health:IsDead() then return end --if dead then this will not work if not (inst and inst.components.sanity) then return end --if having no sanity somehow then it will not work local x,y,z = inst.Transform:GetWorldPosition() local pt = inst:GetPosition() local range = 8 local tags = {"structure"} --find "structures" local num_structures = 0 local check = TheSim:FindEntities(pt.x,pt.y,pt.z, range, nil, nil, tags) for _,v in ipairs(check) do num_structures = num_structures + 1 --counts every structures close to your character end inst.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-1 + (0.5 * num_structures)) --starts with sanity drain, but if close to more than 3 structures, your character will gain sanity end Add this function in your character.lua and inst:DoPeriodicTask(5, machinelover) add this line to your character's common_postinit. Value is set very low because you can have lots of chests. or, you could set max cap using math.min. Also, this will not count walls, fences, mini signs(arrow sign or big one will still work). And, unfortunally, this will count naturally spawning pig houses, merm houses etc. because they also have "structure" tag. 1 Link to comment Share on other sites More sharing options...
The_Knife_Pie Posted February 7, 2021 Author Share Posted February 7, 2021 (edited) 12 hours ago, Combustiblemon said: local function machinelover(inst) if inst:HasTag("playerghost") then return end if inst.components.health:IsDead() then return end --if dead then this will not work if not (inst and inst.components.sanity) then return end --if having no sanity somehow then it will not work local x,y,z = inst.Transform:GetWorldPosition() local pt = inst:GetPosition() local range = 8 local tags = {"structure"} --find "structures" local num_structures = 0 local check = TheSim:FindEntities(pt.x,pt.y,pt.z, range, nil, nil, tags) for _,v in ipairs(check) do num_structures = num_structures + 1 --counts every structures close to your character end inst.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-1 + (0.5 * num_structures)) --starts with sanity drain, but if close to more than 3 structures, your character will gain sanity end Add this function in your character.lua and inst:DoPeriodicTask(5, machinelover) add this line to your character's common_postinit. Value is set very low because you can have lots of chests. or, you could set max cap using math.min. Also, this will not count walls, fences, mini signs(arrow sign or big one will still work). And, unfortunally, this will count naturally spawning pig houses, merm houses etc. because they also have "structure" tag. Not sure if this is the correct way to reply to a message but I just want to say a huge thank you for this. Edited February 7, 2021 by The_Knife_Pie Found answer to question asked 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