icantevenname Posted August 8, 2020 Share Posted August 8, 2020 Is it possible to give a character a multiplier to all changes to Sanity? I doubt it's as simple as taking inst.components.hunger.hungerrate = X.XX * TUNING.WILSON_HUNGER_RATE and replacing every instance of hunger with sanity. Link to comment Share on other sites More sharing options...
-LukaS- Posted August 9, 2020 Share Posted August 9, 2020 Add inst.components.sanity.rate_modifier = 'value' with value being the percantage. For example rate_modifier of 1.5 means your character will be losing sanity 50% faster. The default value is 1. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 9, 2020 Author Share Posted August 9, 2020 3 hours ago, IThatGuyI said: Add inst.components.sanity.rate_modifier = 'value' with value being the percantage. For example rate_modifier of 1.5 means your character will be losing sanity 50% faster. The default value is 1. Seems to only affect auras and rate. I want that, but also one-time things like picking normal or evil flowers, eating good or bad food, casting spells, ect... Link to comment Share on other sites More sharing options...
-LukaS- Posted August 9, 2020 Share Posted August 9, 2020 (edited) If you want to boost sanity gain from ALL sources then the best way to do it would be to modify the sanity component by adding a multiplier and putting it in DoDelta function. Edited August 9, 2020 by IThatGuyI 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 9, 2020 Author Share Posted August 9, 2020 1 hour ago, IThatGuyI said: If you want to boost sanity gain from ALL sources then the best way to do it would be to modify the sanity component by adding a multiplier and putting it in DoDelta function. I think I did it wrong inst.components.sanity:DoDelta(*1.5) Doesn't seem to like that the * is next to (. Link to comment Share on other sites More sharing options...
-LukaS- Posted August 9, 2020 Share Posted August 9, 2020 No no no. You need to edit the component using AddClassPostConstruct. You should add a new variable and name it something like 'moddedsanitymultiplier' and then add it to the DoDelta function so that it will multiply the final amount of sanity lost. Something like that (all of it needs to be in modmain.lua): local function SanityPostCons(self) self.moddedsanitymultiplier = 1 function Sanity:DoDelta(delta, overtime) if self.redirect ~= nil then self.redirect(self.inst, delta, overtime) return end if self.ignore then return end self.current = math.min(math.max(self.current + (delta*self.moddedsanitymultiplier), 0), self.max - (self.max * self.penalty)) -- Here you can see I added the multiplier -- must calculate it due to inducedinsanity ... local percent_ignoresinduced = self.current / self.max if self.mode == SANITY_MODE_INSANITY then if self.sane and percent_ignoresinduced <= TUNING.SANITY_BECOME_INSANE_THRESH then --30 self.sane = false elseif not self.sane and percent_ignoresinduced >= TUNING.SANITY_BECOME_SANE_THRESH then --35 self.sane = true end else if self.sane and percent_ignoresinduced >= TUNING.SANITY_BECOME_ENLIGHTENED_THRESH then self.sane = false elseif not self.sane and percent_ignoresinduced <= TUNING.SANITY_LOSE_ENLIGHTENMENT_THRESH then self.sane = true end end self.inst:PushEvent("sanitydelta", { oldpercent = self._oldpercent, newpercent = self:GetPercent(), overtime = overtime, sanitymode = self.mode }) self._oldpercent = self:GetPercent() if self:IsSane() ~= self._oldissane then self._oldissane = self:IsSane() if self._oldissane then if self.onSane ~= nil then self.onSane(self.inst) end self.inst:PushEvent("gosane") ProfileStatsSet("went_sane", true) else if self.mode == SANITY_MODE_INSANITY then if self.onInsane ~= nil then self.onInsane(self.inst) end self.inst:PushEvent("goinsane") ProfileStatsSet("went_insane", true) else --self.mode == SANITY_MODE_LUNACY if self.onEnlightened ~= nil then self.onEnlightened(self.inst) end self.inst:PushEvent("goenlightened") ProfileStatsSet("went_enlightened", true) end end end end end AddClassPostConstruct("components/sanity", SanityPostCons) And then just set the sanity drain by adding inst.components.sanity.moddedsanitymultiplier = 'value' to your character. For example setting this to 1.5 means your character will be losing sanity 50% faster than normal. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 9, 2020 Author Share Posted August 9, 2020 1 hour ago, IThatGuyI said: No no no. You need to edit the component using AddClassPostConstruct. You should add a new variable and name it something like 'moddedsanitymultiplier' and then add it to the DoDelta function so that it will multiply the final amount of sanity lost. Something like that (all of it needs to be in modmain.lua): local function SanityPostCons(self) self.moddedsanitymultiplier = 1 function Sanity:DoDelta(delta, overtime) if self.redirect ~= nil then self.redirect(self.inst, delta, overtime) return end if self.ignore then return end self.current = math.min(math.max(self.current + (delta*self.moddedsanitymultiplier), 0), self.max - (self.max * self.penalty)) -- Here you can see I added the multiplier -- must calculate it due to inducedinsanity ... local percent_ignoresinduced = self.current / self.max if self.mode == SANITY_MODE_INSANITY then if self.sane and percent_ignoresinduced <= TUNING.SANITY_BECOME_INSANE_THRESH then --30 self.sane = false elseif not self.sane and percent_ignoresinduced >= TUNING.SANITY_BECOME_SANE_THRESH then --35 self.sane = true end else if self.sane and percent_ignoresinduced >= TUNING.SANITY_BECOME_ENLIGHTENED_THRESH then self.sane = false elseif not self.sane and percent_ignoresinduced <= TUNING.SANITY_LOSE_ENLIGHTENMENT_THRESH then self.sane = true end end self.inst:PushEvent("sanitydelta", { oldpercent = self._oldpercent, newpercent = self:GetPercent(), overtime = overtime, sanitymode = self.mode }) self._oldpercent = self:GetPercent() if self:IsSane() ~= self._oldissane then self._oldissane = self:IsSane() if self._oldissane then if self.onSane ~= nil then self.onSane(self.inst) end self.inst:PushEvent("gosane") ProfileStatsSet("went_sane", true) else if self.mode == SANITY_MODE_INSANITY then if self.onInsane ~= nil then self.onInsane(self.inst) end self.inst:PushEvent("goinsane") ProfileStatsSet("went_insane", true) else --self.mode == SANITY_MODE_LUNACY if self.onEnlightened ~= nil then self.onEnlightened(self.inst) end self.inst:PushEvent("goenlightened") ProfileStatsSet("went_enlightened", true) end end end end end AddClassPostConstruct("components/sanity", SanityPostCons) And then just set the sanity drain by adding inst.components.sanity.moddedsanitymultiplier = 'value' to your character. For example setting this to 1.5 means your character will be losing sanity 50% faster than normal. Not sure if this'll work for me, since my modmain has information for two different characters... I didn't mention it cuz I didn't think it'd be relevant... Link to comment Share on other sites More sharing options...
-LukaS- Posted August 10, 2020 Share Posted August 10, 2020 It should work as long as it's in modmain. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 10, 2020 Author Share Posted August 10, 2020 (edited) 12 hours ago, IThatGuyI said: It should work as long as it's in modmain. By that I mean that I want it to affect one character, not the other. Sorry that it's one thing after the other with me. No, wait, now I see what you're telling me to do. Edited August 11, 2020 by icantevenname Added apology, then figured it out. Link to comment Share on other sites More sharing options...
icantevenname Posted August 11, 2020 Author Share Posted August 11, 2020 Am I missing something? It keeps showing an empty Character Select screen when starting the game and then kicking me back to Desktop when I click anything. I keep looking up and down the local function and it doesn't seem that you expect me to change anything there. Link to comment Share on other sites More sharing options...
-LukaS- Posted August 11, 2020 Share Posted August 11, 2020 An empty character select screen? Was this error present before you put in the code I showed you? 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 11, 2020 Author Share Posted August 11, 2020 10 hours ago, IThatGuyI said: An empty character select screen? Was this error present before you put in the code I showed you? Commented out that local function, worked fine. Wanna look at the modmain? Link to comment Share on other sites More sharing options...
-LukaS- Posted August 11, 2020 Share Posted August 11, 2020 Yeah, sure. There might be some errors with the implementation. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 11, 2020 Author Share Posted August 11, 2020 The function is still commented out. modmain.lua Link to comment Share on other sites More sharing options...
-LukaS- Posted August 11, 2020 Share Posted August 11, 2020 Ahh, my bad. I provided you with a wrong AddPostInit function. It should be AddComponentPostInit not AddClassPostInit. And use 'sanity' instead of 'components/sanity'. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 11, 2020 Author Share Posted August 11, 2020 (edited) 35 minutes ago, IThatGuyI said: Ahh, my bad. I provided you with a wrong AddPostInit function. It should be AddComponentPostInit not AddClassPostInit. And use 'sanity' instead of 'components/sanity'. Jus' double checking, is it supposed to look like this? AddComponentPostInit("sanity", SanityPostCons) Cuz now I'm getting this. Edited August 11, 2020 by icantevenname Link to comment Share on other sites More sharing options...
-LukaS- Posted August 11, 2020 Share Posted August 11, 2020 Ah, yes add 'local Sanity = require "components/sanity"' 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 11, 2020 Author Share Posted August 11, 2020 I've tried to place local Sanity = require "components/sanity" in all sorts of places, but nothing seems to work. Does it go in the SanityPost? Near local STRINGS? Link to comment Share on other sites More sharing options...
-LukaS- Posted August 11, 2020 Share Posted August 11, 2020 It should go before the SanityPostCons function. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 11, 2020 Author Share Posted August 11, 2020 (edited) I have it like this... local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS local Sanity = require "components/sanity" local function SanityPostCons(self) self.moddedsanitymultiplier = 1 And the blank CSS happens. In the character's luas, I have coding that changes the rate they lose sanity when wet. Think that's interfering with this? Edited August 11, 2020 by icantevenname Extra info Link to comment Share on other sites More sharing options...
-LukaS- Posted August 11, 2020 Share Posted August 11, 2020 Ok, remove everything and put this in your modmain. local require = GLOBAL.require local Sanity = require "components/sanity" local function SanityPostInit(self) self.moddedmultiplier = 1 function Sanity:DoDelta(delta, overtime) if self.redirect ~= nil then self.redirect(self.inst, delta, overtime) return end if self.ignore then return end self.current = math.min(math.max(self.current + (delta * self.moddedmultiplier), 0), self.max - (self.max * self.penalty)) -- must calculate it due to inducedinsanity ... local percent_ignoresinduced = self.current / self.max if self.mode == SANITY_MODE_INSANITY then if self.sane and percent_ignoresinduced <= TUNING.SANITY_BECOME_INSANE_THRESH then --30 self.sane = false elseif not self.sane and percent_ignoresinduced >= TUNING.SANITY_BECOME_SANE_THRESH then --35 self.sane = true end else if self.sane and percent_ignoresinduced >= TUNING.SANITY_BECOME_ENLIGHTENED_THRESH then self.sane = false elseif not self.sane and percent_ignoresinduced <= TUNING.SANITY_LOSE_ENLIGHTENMENT_THRESH then self.sane = true end end self.inst:PushEvent("sanitydelta", { oldpercent = self._oldpercent, newpercent = self:GetPercent(), overtime = overtime, sanitymode = self.mode }) self._oldpercent = self:GetPercent() if self:IsSane() ~= self._oldissane then self._oldissane = self:IsSane() if self._oldissane then if self.onSane ~= nil then self.onSane(self.inst) end self.inst:PushEvent("gosane") ProfileStatsSet("went_sane", true) else if self.mode == SANITY_MODE_INSANITY then if self.onInsane ~= nil then self.onInsane(self.inst) end self.inst:PushEvent("goinsane") ProfileStatsSet("went_insane", true) else --self.mode == SANITY_MODE_LUNACY if self.onEnlightened ~= nil then self.onEnlightened(self.inst) end self.inst:PushEvent("goenlightened") ProfileStatsSet("went_enlightened", true) end end end end end AddComponentPostInit("sanity", SanityPostInit) I tested this code and it didn't crash for me, so if it will crash your game then it's a problem outside of this code. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 11, 2020 Author Share Posted August 11, 2020 I used a template character and just imputed the code in the modmain and the multiplier in the character lua. And this happened. Link to comment Share on other sites More sharing options...
-LukaS- Posted August 12, 2020 Share Posted August 12, 2020 Sorry for all the false information. Turns out I'm terrible add overriding components, but I think this time is will work. Here's the code: local function SanityPostInit(component) -- Function to partially override the DoDelta function component.moddedmultiplier = 1 -- Your variable local old_DoDelta = component.DoDelta -- Old DoDelta function component.DoDelta = function(self, delta, overtime) -- New DoDelta function local moddeddelta = delta*component.moddedmultiplier -- Local variable which uses the default delta and the multiplies it by your multiplier return old_DoDelta(self, moddeddelta, overtime) -- Returning the function end end AddComponentPostInit("sanity", SanityPostInit) -- AddComponentPostInit And then set the moddedmultiplier value in your characters prefab file with: inst.components.sanity.moddedmultiplier = 'your_value' -- Percent e.g 1.5 = 150% 1 1 Link to comment Share on other sites More sharing options...
icantevenname Posted August 12, 2020 Author Share Posted August 12, 2020 7 hours ago, IThatGuyI said: Sorry for all the false information. Turns out I'm terrible add overriding components, but I think this time is will work. Here's the code: local function SanityPostInit(component) -- Function to partially override the DoDelta function component.moddedmultiplier = 1 -- Your variable local old_DoDelta = component.DoDelta -- Old DoDelta function component.DoDelta = function(self, delta, overtime) -- New DoDelta function local moddeddelta = delta*component.moddedmultiplier -- Local variable which uses the default delta and the multiplies it by your multiplier return old_DoDelta(self, moddeddelta, overtime) -- Returning the function end end AddComponentPostInit("sanity", SanityPostInit) -- AddComponentPostInit And then set the moddedmultiplier value in your characters prefab file with: inst.components.sanity.moddedmultiplier = 'your_value' -- Percent e.g 1.5 = 150% It all works fine! Thanks so much! 1 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