Gian383 Posted January 13, 2015 Share Posted January 13, 2015 I'm trying to work out a character that would gain sanity during nighttime and lose sanity during the day. So far I've compiled a few changes in the sanity component into another component. Here's the snippet with the changes I've made [codesyntax] local light_delta = 0local lightval = self.inst.LightWatcher:GetLightValue()local day = TheWorld.state.isday and not TheWorld:HasTag("cave")if night thenlight_delta = TUNING.SANITY_DAY_GAINelseif dusklocal highval = TUNING.SANITY_HIGH_LIGHTlocal lowval = TUNING.SANITY_LOW_LIGHTif lightval < highval thenlight_delta = TUNING.SANITY_NIGHT_LIGHTelseif lightval > lowval thenlight_delta = TUNING.SANITY_NIGHT_DARKelseif day light_delta = TUNING.SANITY_NIGHT_MIDendelse day light_delta = light_delta*self.night_drain_multendend[/codesyntax] I tried adding it to my character's modmain to replace the normal sanity but making this true and the original sanity component false didn't work. I'd appreciate the help. Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/ Share on other sites More sharing options...
rezecib Posted January 13, 2015 Share Posted January 13, 2015 I tried adding it to my character's modmain to replace the normal sanity but making this true and the original sanity component false didn't work. I'd appreciate the help. Huh?? Not sure what you were trying to do, but it does not sound like the right thing ("making this true"?). But I wouldn't replace the sanity component, as it's a replicable component (and tied to player_classified) and we can't mod those yet. There are a couple of approaches you could take... you could override Sanity:Recalc(dt) like this:inst.components.sanity.Recalc = function(self, inst) --your version of the recalc function hereend Alternatively, you could use sanity.dapperness, and tie it to the phase change event like so:inst:WatchWorldState("isday", function(inst, val) local mult = val and 1 or -2 inst.components.sanity.dapperness = mult*TUNING.SANITY_NIGHT_LIGHTend)I think that should make it gain sanity equivalent to the dusk/night sanity drain during the dusk/night, but lose the same amount during the day. The multiplier for not-day is -2 so that it both cancels out the normal night drain (-1) and gives that amount on top of it. The way you have yours written right now, if you were using the overriding Recalc approach, would negate sanity loss from being completely in the dark. Not sure if that's what you intended. Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/#findComment-601246 Share on other sites More sharing options...
Gian383 Posted January 13, 2015 Author Share Posted January 13, 2015 Huh?? Not sure what you were trying to do, but it does not sound like the right thing ("making this true"?). But I wouldn't replace the sanity component, as it's a replicable component (and tied to player_classified) and we can't mod those yet. There are a couple of approaches you could take... you could override Sanity:Recalc(dt) like this:inst.components.sanity.Recalc = function(self, inst) --your version of the recalc function hereend Alternatively, you could use sanity.dapperness, and tie it to the phase change event like so:inst:WatchWorldState("isday", function(inst, val) local mult = val and 1 or -2 inst.components.sanity.dapperness = mult*TUNING.SANITY_NIGHT_LIGHTend)I think that should make it gain sanity equivalent to the dusk/night sanity drain during the dusk/night, but lose the same amount during the day. The multiplier for not-day is -2 so that it both cancels out the normal night drain (-1) and gives that amount on top of it. The way you have yours written right now, if you were using the overriding Recalc approach, would negate sanity loss from being completely in the dark. Not sure if that's what you intended. Thank you for the help. With true/false I was trying to get the game to recognize my custom sanity file instead of the original one but if it can't be overwritten then that won't work. I'll try out your suggestions and post results here. Side note: Yes, I was trying to negate sanity loss in the dark and have daytime drain his sanity instead. Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/#findComment-601547 Share on other sites More sharing options...
Gian383 Posted January 13, 2015 Author Share Posted January 13, 2015 As of right now the game crashes when I try to apply either or with my mod (The mod works without the changes). I'll keep looking into what I can do and trying things out and I'll post any results here In case you're interested in the crash log: http://pastebin.com/V4h9ymWm Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/#findComment-601563 Share on other sites More sharing options...
ArashiOtter Posted January 14, 2015 Share Posted January 14, 2015 @Gian383 Might not be exactly what your looking for but I managed to get my character to do what your looking for with a function. Kinda based on Willow's.local function sanityfn(inst)local delta = 0if TheWorld.state.isday thendelta = -0.25elseif TheWorld.state.isdusk thendelta = 0.5elseif TheWorld.state.isnight thendelta = 0.95endreturn deltaendwith ainst.components.sanity.custom_rate_fn = sanityfnin the master post.init Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/#findComment-601704 Share on other sites More sharing options...
MattDoesnt Posted January 14, 2015 Share Posted January 14, 2015 Not sure what you were trying to do, but you only need these two lines for sanity swap:inst.components.sanity.night_drain_mult = -14 --Sanity gained at night.inst.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-8) --Sanity lost during the day.Those number are major gain/drain numbers I use in my mod, you'll probably want to lower them a bit. Make sure both numbers stay negative, otherwise you'll gain during the day, and lose at night. Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/#findComment-601709 Share on other sites More sharing options...
Pyrobolser Posted January 14, 2015 Share Posted January 14, 2015 Here :local function updatestats(inst) if TheWorld.state.phase == "day" then inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * -5) elseif TheWorld.state.phase == "dusk" then inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * 3) elseif TheWorld.state.phase == "night" then inst.components.sanity.dapperness = (TUNING.DAPPERNESS_SMALL * 8) endend Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/#findComment-601864 Share on other sites More sharing options...
Pyrobolser Posted January 14, 2015 Share Posted January 14, 2015 Don't forget to call it on your fontion, like this :inst:WatchWorldState( "startday", function(inst) updatestats(inst) end )inst:WatchWorldState( "startdusk", function(inst) updatestats(inst) end )inst:WatchWorldState( "startnight", function(inst) updatestats(inst) end ) updatestats(inst)return instPlace this at the end of the fonction where "inst.soundsname" is called =)Cya ! Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/#findComment-601867 Share on other sites More sharing options...
Gian383 Posted January 14, 2015 Author Share Posted January 14, 2015 @Gian383 Might not be exactly what your looking for but I managed to get my character to do what your looking for with a function. Kinda based on Willow's.local function sanityfn(inst)local delta = 0if TheWorld.state.isday thendelta = -0.25elseif TheWorld.state.isdusk thendelta = 0.5elseif TheWorld.state.isnight thendelta = 0.95endreturn deltaendwith ainst.components.sanity.custom_rate_fn = sanityfnin the master post.init thank you very much, this is exactly what I was looking for!Also thanks to everyone who provided answers for me, I appreciate it very much so. I can confirm that all of the code you've provided works, though the one I'm quoting above does exactly what I intended to make out of it. Once more, thanks. Link to comment https://forums.kleientertainment.com/forums/topic/49048-gain-sanity-at-night-lose-sanity-at-day/#findComment-601879 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