Augustusc Posted June 3, 2017 Share Posted June 3, 2017 Is it possible to gain a sanity aura depending on someone ELSE'S sanity? Example: there is a group of 3. Wendy, Wilson, and My character Wendy is at the level of sanity where she can be attacked by shadows Wilson is about middle of the road (he can see shadows, but not be attacked by them) My character is at max sanity My character walks to Wilson, nothing happens. My character walks up to Wendy and BOTH Wendy AND Wilson start gaining sanity Is this a possible thing to code? Or would this be a task too intense for the game? Link to comment Share on other sites More sharing options...
JohnWatson Posted June 3, 2017 Share Posted June 3, 2017 (edited) Place in the OnLoad or master_init function: local ic = inst.components if ic.sanityaura == nil then inst:AddComponent("sanityaura") ic.sanityaura.aura = TUNING.SANITYAURA_LARGE * ic.sanity:GetPercent() end inst:ListenForEvent("sanitydelta", function() if ic.sanityaura ~= nil then ic.sanityaura.aura = TUNING.SANITYAURA_LARGE * ic.sanity:GetPercent() end end) EDIT: Okay, I didn't quite understand what you meant the first time, but after reading your post again, I seem to have made a mistake. The code above gives you a sanity aura depending on your own character's sanity, however you asked for a sanity aura that depends on someone else's sanity. Edited June 3, 2017 by JohnWatson Link to comment Share on other sites More sharing options...
JohnWatson Posted June 3, 2017 Share Posted June 3, 2017 I haven't tested this yet, but try it anyway. OnLoad or master_init local restore_radius = 15 -- 'Check for players within this distance in metres' local ic = inst.components if ic.sanityaura == nil then inst:AddComponent("sanityaura") end if inst.checkForInsaneMates ~= nil then inst.checkForInsaneMates:Cancel() inst.checkForInsaneMates = nil end inst.checkForInsaneMates = inst:DoPeriodicTask(0.5, function() local x,y,z = inst.Transform:GetWorldPosition() local f = TheSim:FindEntities( x,y,z, restore_radius) local enableaura = false for k, v in ipairs(f) do local vc = v.components if vc ~= nil and vc.sanity ~= nil and (vc.sanity:GetPercent() <= 0.15) then enableaura = true end end ic.sanityaura.aura = TUNING.SANITYAURA_LARGE * ((enableaura==true and 1) or 0) end) Link to comment Share on other sites More sharing options...
Augustusc Posted June 5, 2017 Author Share Posted June 5, 2017 It worked perfectly! Thanks for your help! sorry if i caused any inconvenience from the way i phrased the question 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