AmanitaDST Posted November 9, 2023 Share Posted November 9, 2023 (edited) Hi, so I've been working on the widget for quite some time now and I never really understood why the value keeps dropping to 0 as soon as the world is loaded. Example: I already talked about widget making in an other post but that was before I started actually codding it. Now it's a scripting issue more than a "how to" issue. I have some files attached for anyone brave enough to surf through them but otherwise I'm open to suggestions as to how to fix this issue. So madness.lua is a component, it's got it's replica too. madplayer_classified.lua is a prefab that I'm using to declare net vars and to add the badge to all characters and then madnessbadge.lua which is a widget. All of these are their respective folders. (components,prefabs,widgets in that order) Thanks in advance for anyone who helps! madness.lua madness_replica.lua madplayer_classified.lua madnessbadge.lua Edited November 10, 2023 by AmanitaDST Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 9, 2023 Share Posted November 9, 2023 After a cursory look, I can't find the source of the issue. I think it'd help if you sent the whole mod, the problem could be elsewhere. It'd also let me actually test it and try printing some values in the console to more easily find the issue. Link to comment Share on other sites More sharing options...
AmanitaDST Posted November 9, 2023 Author Share Posted November 9, 2023 3 minutes ago, ariadnesGambit said: After a cursory look, I can't find the source of the issue. I think it'd help if you sent the whole mod, the problem could be elsewhere. It'd also let me actually test it and try printing some values in the console to more easily find the issue. Very well. Here it is: the cthulhu mythos.zip Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 9, 2023 Share Posted November 9, 2023 I can't look into it deeper right now, I should be able to later today though. But first thing I noticed is that you're adding the components "reader" and "madness" to the client too. You should only add them server side. Also, just use AddPlayerPostInit to add something to players, you don't need to go through the entire list of character prefabs. 1 Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 9, 2023 Share Posted November 9, 2023 (edited) Found the issue! The reason the meter was depleting like that was only a visual thing. The way these meters work is that they have a long animation of them depleting, but they're set to a certain frame based on how full the stat is. That's why it was depleting, it wasn't being set to any specific frame. In your "madplayer_classified" file, you were missing a bunch of code in your StatusDisplays _ctor hook to listen for certain events and such, but I made it for you (since I was testing around). I also made sure that the badge gets hidden if you're a ghost. local function OnSetPlayerMode(inst, self) self.madness_modetask = nil if self.owner.replica.madness ~= nil then if self.onmadnessdelta == nil then self.onmadnessdelta = function(owner, data) self:MadnessDelta(data) end self.inst:ListenForEvent("madnessdelta", self.onmadnessdelta, self.owner) self:SetMadnessPercent(self.owner.replica.madness:GetPercent()) end end end local function OnSetGhostMode(inst, self) self.madness_modetask = nil if self.owner.replica.madness ~= nil then if self.onmadnessdelta ~= nil then self.inst:RemoveEventCallback("madnessdelta", self.onmadnessdelta, self.owner) self.onmadnessdelta = nil end end end function self:SetMadnessPercent(pct) self.madbrain:SetPercent(pct, self.owner.replica.madness:Max()) if pct <= 0 then self.madbrain:StartWarning() else self.madbrain:StopWarning() end end function self:MadnessDelta(data) self:SetMadnessPercent(data.newpercent) if self.madbrain ~= nil and self.madbrain.MadnessDelta then self.madbrain:MadnessDelta(data) else if not data.overtime then if data.newpercent > data.oldpercent then self.madbrain:PulseGreen() GLOBAL.TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/sanity_up") elseif data.newpercent < data.oldpercent then self.madbrain:PulseRed() GLOBAL.TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/sanity_down") end end end end local _setghostmode_old = self.SetGhostMode function self:SetGhostMode(ghostmode, ...) _setghostmode_old(self, ghostmode, ...) if ghostmode then if self.madbrain ~= nil then self.madbrain:Hide() self.madbrain:StopWarning() end else if self.madbrain ~= nil then self.madbrain:Show() end end if self.madness_modetask ~= nil then self.madness_modetask:Cancel() end self.madness_modetask = self.inst:DoStaticTaskInTime(0, ghostmode and OnSetGhostMode or OnSetPlayerMode, self) end I'm not sure if this is everything you need, I've coded badges before and they can be a pain. But hopefully this will help you keep going! ALSO, unrelated thing I noticed while looking around your files. The way you're adding RECIPE_DESC is overriding the entire table, so every other recipe in the game has no description. Unfortunately you have to add each line manually, like you did for NAMES. Edited November 9, 2023 by ariadnesGambit 1 Link to comment Share on other sites More sharing options...
AmanitaDST Posted November 9, 2023 Author Share Posted November 9, 2023 Thanks for your input! 56 minutes ago, ariadnesGambit said: Found the issue! The reason the meter was depleting like that was only a visual thing. The way these meters work is that they have a long animation of them depleting, but they're set to a certain frame based on how full the stat is. That's why it was depleting, it wasn't being set to any specific frame. In your "madplayer_classified" file, you were missing a bunch of code in your StatusDisplays _ctor hook to listen for certain events and such, but I made it for you (since I was testing around). I also made sure that the badge gets hidden if you're a ghost. local function OnSetPlayerMode(inst, self) self.madness_modetask = nil if self.owner.replica.madness ~= nil then if self.onmadnessdelta == nil then self.onmadnessdelta = function(owner, data) self:MadnessDelta(data) end self.inst:ListenForEvent("madnessdelta", self.onmadnessdelta, self.owner) self:SetMadnessPercent(self.owner.replica.madness:GetPercent()) end end end local function OnSetGhostMode(inst, self) self.madness_modetask = nil if self.owner.replica.madness ~= nil then if self.onmadnessdelta ~= nil then self.inst:RemoveEventCallback("madnessdelta", self.onmadnessdelta, self.owner) self.onmadnessdelta = nil end end end function self:SetMadnessPercent(pct) self.madbrain:SetPercent(pct, self.owner.replica.madness:Max()) if pct <= 0 then self.madbrain:StartWarning() else self.madbrain:StopWarning() end end function self:MadnessDelta(data) self:SetMadnessPercent(data.newpercent) if self.madbrain ~= nil and self.madbrain.MadnessDelta then self.madbrain:MadnessDelta(data) else if not data.overtime then if data.newpercent > data.oldpercent then self.madbrain:PulseGreen() GLOBAL.TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/sanity_up") elseif data.newpercent < data.oldpercent then self.madbrain:PulseRed() GLOBAL.TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/sanity_down") end end end end local _setghostmode_old = self.SetGhostMode function self:SetGhostMode(ghostmode, ...) _setghostmode_old(self, ghostmode, ...) if ghostmode then if self.madbrain ~= nil then self.madbrain:Hide() self.madbrain:StopWarning() end else if self.madbrain ~= nil then self.madbrain:Show() end end if self.madness_modetask ~= nil then self.madness_modetask:Cancel() end self.madness_modetask = self.inst:DoStaticTaskInTime(0, ghostmode and OnSetGhostMode or OnSetPlayerMode, self) end I'll give this a try and see what happens 1 Link to comment Share on other sites More sharing options...
AmanitaDST Posted November 9, 2023 Author Share Posted November 9, 2023 (edited) I have some development, 3 hours ago, ariadnesGambit said: Found the issue! The reason the meter was depleting like that was only a visual thing. The way these meters work is that they have a long animation of them depleting, but they're set to a certain frame based on how full the stat is. That's why it was depleting, it wasn't being set to any specific frame. In your "madplayer_classified" file, you were missing a bunch of code in your StatusDisplays _ctor hook to listen for certain events and such, but I made it for you (since I was testing around). I also made sure that the badge gets hidden if you're a ghost. local function OnSetPlayerMode(inst, self) self.madness_modetask = nil if self.owner.replica.madness ~= nil then if self.onmadnessdelta == nil then self.onmadnessdelta = function(owner, data) self:MadnessDelta(data) end self.inst:ListenForEvent("madnessdelta", self.onmadnessdelta, self.owner) self:SetMadnessPercent(self.owner.replica.madness:GetPercent()) end end end local function OnSetGhostMode(inst, self) self.madness_modetask = nil if self.owner.replica.madness ~= nil then if self.onmadnessdelta ~= nil then self.inst:RemoveEventCallback("madnessdelta", self.onmadnessdelta, self.owner) self.onmadnessdelta = nil end end end function self:SetMadnessPercent(pct) self.madbrain:SetPercent(pct, self.owner.replica.madness:Max()) if pct <= 0 then self.madbrain:StartWarning() else self.madbrain:StopWarning() end end function self:MadnessDelta(data) self:SetMadnessPercent(data.newpercent) if self.madbrain ~= nil and self.madbrain.MadnessDelta then self.madbrain:MadnessDelta(data) else if not data.overtime then if data.newpercent > data.oldpercent then self.madbrain:PulseGreen() GLOBAL.TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/sanity_up") elseif data.newpercent < data.oldpercent then self.madbrain:PulseRed() GLOBAL.TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/sanity_down") end end end end local _setghostmode_old = self.SetGhostMode function self:SetGhostMode(ghostmode, ...) _setghostmode_old(self, ghostmode, ...) if ghostmode then if self.madbrain ~= nil then self.madbrain:Hide() self.madbrain:StopWarning() end else if self.madbrain ~= nil then self.madbrain:Show() end end if self.madness_modetask ~= nil then self.madness_modetask:Cancel() end self.madness_modetask = self.inst:DoStaticTaskInTime(0, ghostmode and OnSetGhostMode or OnSetPlayerMode, self) end I'm not sure if this is everything you need, I've coded badges before and they can be a pain. But hopefully this will help you keep going! ALSO, unrelated thing I noticed while looking around your files. The way you're adding RECIPE_DESC is overriding the entire table, so every other recipe in the game has no description. Unfortunately you have to add each line manually, like you did for NAMES. With your help and Lukas' help, I've managed to make it work. I got some adjustments to make in regards to making the badge reset it's value when the player respawns. I tried some things but it I could not figure out how to make the madness go back to max upon revival of the player. Although the rest seems to work perfectly fine. Here's the updated madplayer_classified.lua madplayer_classified.lua Edited November 9, 2023 by AmanitaDST Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 9, 2023 Share Posted November 9, 2023 26 minutes ago, AmanitaDST said: I tried some things but it I could not figure out how to make the madness go back to max upon revival of the player. Put this in your AddPlayerPostInit: inst:ListenForEvent("makeplayerghost",function(inst, data) if inst.components.madness ~= nil then inst.components.madness:SetPercent(1, true) isnt.components.madness:Pause() end end) inst:ListenForEvent("respawnfromghost", function(inst) if inst.components.madness ~= nil then inst.components.madness:Resume() end end) 1 Link to comment Share on other sites More sharing options...
AmanitaDST Posted November 9, 2023 Author Share Posted November 9, 2023 8 minutes ago, ariadnesGambit said: Put this in your AddPlayerPostInit: inst:ListenForEvent("makeplayerghost",function(inst, data) if inst.components.madness ~= nil then inst.components.madness:SetPercent(1, true) isnt.components.madness:Pause() end end) inst:ListenForEvent("respawnfromghost", function(inst) if inst.components.madness ~= nil then inst.components.madness:Resume() end end) Thank you so much! That does make perfect sense. I'm slowly learning the syntax of lua/dst. Thanks a lot again! 1 Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 9, 2023 Share Posted November 9, 2023 4 minutes ago, AmanitaDST said: Thank you so much! That does make perfect sense. I'm slowly learning the syntax of lua/dst. Thanks a lot again! No problem! Since you're making something really similar to an existing feature, it really helps to look at what Klei does, though it's not always easy to track it down. You did a pretty good job with your original code, now you're just missing some pieces here and there. I went through the same process when making my own badge and it took me days of work, so I'm happy to make someone else's job easier! 1 Link to comment Share on other sites More sharing options...
AmanitaDST Posted November 9, 2023 Author Share Posted November 9, 2023 21 minutes ago, ariadnesGambit said: No problem! Since you're making something really similar to an existing feature, it really helps to look at what Klei does, though it's not always easy to track it down. You did a pretty good job with your original code, now you're just missing some pieces here and there. I went through the same process when making my own badge and it took me days of work, so I'm happy to make someone else's job easier! I unfortunately ran into and error adding it in, I think I might've done smt wrong but here it is. This is inside modmain: AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return end if inst.components.reader == nil then inst:AddComponent("reader") end inst:AddComponent("madness") if inst.components.itemaffinity == nil then inst:AddComponent("itemaffinity") end inst.components.itemaffinity:AddAffinity("cursedstone", nil, -TUNING.DAPPERNESS_TINY, 1) inst.components.itemaffinity:AddAffinity("cursedcrystal", nil, -TUNING.DAPPERNESS_SMALL, 1) inst.components.itemaffinity:AddAffinity("cursedgem", nil, -TUNING.DAPPERNESS_SMALL, 1) inst.components.itemaffinity:AddAffinity("cursedorb", nil, -TUNING.DAPPERNESS_HUGE, 1) inst:ListenForEvent("makeplayerghost",function(inst, data) if inst.components.madness ~= nil then inst.components.madness:SetPercent(1, true) isnt.components.madness:Pause() end end) inst:ListenForEvent("respawnfromghost", function(inst) if inst.components.madness ~= nil then inst.components.madness:Resume() end end) end) Link to comment Share on other sites More sharing options...
AmanitaDST Posted November 9, 2023 Author Share Posted November 9, 2023 (edited) I think I found out how to solve it *checking* it was totally unrelated to the addition of your code Edited November 9, 2023 by AmanitaDST 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