YoBro Posted April 13, 2017 Share Posted April 13, 2017 Hey all! I've been making mods for games for a few years now, and I've always just kinda self taught myself on what to do, but since I'm stuck on modding and I only know 1% of the code for DST, I was wondering if it was possible to have a sanity regen, but only if you're around with other players. In short, being around one player would have the same effect as wearing a garland, and the more players nearby the high the sanity increase rate, I'm also wondering if it's possible that if you aren't near a player, your sanity slowly drops (but doesn't double drop when it's dark at night or dusk, just regular dropping) Thanks for having a read, I'd love to see the results you can come up with! :'D (P.S. Bonus points if when you're near a player, the character says a line of text like "Hey bud!") Link to comment Share on other sites More sharing options...
Starlogy Posted April 13, 2017 Share Posted April 13, 2017 While I'm no wiz at it myself, I believe what you need to do is give a character a sanity aura, similar to entities like Deerclops or Treeguard. Since the playable characters are the only mob in the game affected by sanity, you shouldn't need to do anything else from there. Except of course if your own sanity aura affects you instead. Link to comment Share on other sites More sharing options...
. . . Posted April 14, 2017 Share Posted April 14, 2017 For sanity gain near other players Spoiler -- Sanity gain from nearby players local function sanityfn(inst) local x,y,z = inst.Transform:GetWorldPosition() local delta = 0 local rad = 10 local rad_sq = rad*rad for k,v in pairs(AllPlayers) do if v ~= inst then local distsq = inst:GetDistanceSqToInst(v) if distsq < rad_sq then local sz = TUNING.SANITYAURA_TINY * rad delta = delta + sz/math.max(1, distsq) end end end return delta end inst.components.sanity.custom_rate_fn = sanityfn Link to comment Share on other sites More sharing options...
YoBro Posted April 14, 2017 Author Share Posted April 14, 2017 3 hours ago, SuperDavid said: For sanity gain near other players Reveal hidden contents -- Sanity gain from nearby players local function sanityfn(inst) local x,y,z = inst.Transform:GetWorldPosition() local delta = 0 local rad = 10 local rad_sq = rad*rad for k,v in pairs(AllPlayers) do if v ~= inst then local distsq = inst:GetDistanceSqToInst(v) if distsq < rad_sq then local sz = TUNING.SANITYAURA_TINY * rad delta = delta + sz/math.max(1, distsq) end end end return delta end inst.components.sanity.custom_rate_fn = sanityfn Sweet dude, works awesomely well I noticed I didn't mention another attribute. The character (in this case, Sinky) is somewhat realistic, in the way of that if he's got healthy sanity, he'll happily gain/give some to other players, however, let's say his sanity is low (near borderline insane) he doesn't regain sanity, but instead, makes other players around him lose sanity, as if being insane is a bad impulse for other players. I calculated that when the max sanity is >15% then you'll go insane, so could I add some kind of code where it'll give sanity, else reduce sanity of others around him. Cheers again dude Link to comment Share on other sites More sharing options...
. . . Posted April 14, 2017 Share Posted April 14, 2017 in master_postinit inst:AddComponent("sanityaura") inst:ListenForEvent("gosane", function(inst, data) inst.components.sanityaura.aura = 0 end) inst:ListenForEvent("goinsane", function(inst, data) inst.components.sanityaura.aura = -TUNING.SANITYAURA_TINY end) replace old code (can't test if this'll work atm) -- Sanity gain from nearby players local function sanityfn(inst) if not inst.components.sanity:IsSane() then return end local x,y,z = inst.Transform:GetWorldPosition() local delta = 0 local rad = 10 local rad_sq = rad*rad for k,v in pairs(AllPlayers) do if v ~= inst then local distsq = inst:GetDistanceSqToInst(v) if distsq < rad_sq then local sz = TUNING.SANITYAURA_TINY * rad delta = delta + sz/math.max(1, distsq) end end end return delta end inst.components.sanity.custom_rate_fn = sanityfn 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