Jump to content

[SOLVED] Making a mod that requires a "Madness" meter/widget.


Recommended Posts

My issue is that I've been trying to implement a custom widget for "Madness" but I haven't been able to find any documentation on making a widget that would apply to all characters.
The principles of the widget are the following:
1 - Madness only starts when sanity reaches 0
2 - Lunacy and Sanity get disabled once Madness starts
3 - Madness climbs (becomes stronger and stronger if the player is holding a book called "necrobook")
4 - When the player becomes "Mad" (madness starts) they'll start seeing monsters
5 - When madness reaches 100% the player dies from "Getting to close to cthulhu"

So all those conditions make it very hard to find anything close to this in the workshop to study or in the forums. Most posts I see are about either replacing a meter's visuals or making a new one for a specific character... I will update this post with the code of what I'm currently working with but I'm still trying to find exemples that could get me to start closer to my goal. If anyone feels like helping me out I would gladly appreciate it. I love making mods and learning so please don't hesitate to point me in the right direction. Here's a link to my mod in developpement if you are interested in the idea.

The Cthulhu Mythos - (WIP)

Edited by AmanitaDST
Link to comment
Share on other sites

I have started looking into the code for the hunger meter, as that is the simplest of the three badges by a long shot. I noticed that a few components and prefabs are attached to it. So the following are the list of the lua scripts that I've found to be connected to each other as of now that make the hunger meter:

--Widget

-hungerbadge.lua

--Components

-hunger.lua -hunger_replica.lua -eater.lua -foodmemory.lua

--Prefabs
-hungerregenbuff.lua

I chose to ignore eater.lua and -foodmemory.lua to focus on the more pressing aspect of make a badge, mostly because I do not mind having the meter go back up as you eat (great for testing) so I proceeded to make a copy of each of every other files and to change their values to something of preference to match my mod. So most hunger terms were changed to madness and so on. This scripts bellow is what I have so far. Now if I'm lucky and I did everything right, this should mean that the next steps would be calling upon that badge to display it and also position it so that it covers the sanity meter or I could also try to put it in another spot to not block the visuals of sanity. But since I'm trying to disable sanity when madness is active. I might end up covering it later on. Time will tell.

If anyone wants to download these scripts and review them to help figure out if I've done things right, feel free to do so. Unfortunately for others looking to make widgets, I highly doubt that my code is informational or instructive. At best it might lead you to and understanding as to how widgets interact with other files but probably nothing more. (Removed the files from download due to them being pointless in this topic in light of instructive replies)

Thanks again for anyone who is willing to help me out!

 

Edited by AmanitaDST
  • Like 1
Link to comment
Share on other sites

1. Copy xxxbadge.lua and rename variables.

2. Add your badge to statusdisplays.

3. Hack statusdisplays to Show/Hide your badge properly.

4. Add a net variable to player_classified, if you are lazy just attach it to player.

5. Pass the value from server to client. Listen for value change and display the change.

 

assets:

Copy status_xxx.zip, and do a reskin.

 

In your case you need extra work:

Listen for sanity and sanity mode change, to properly Show/Hide your badge. For example, when sanity==0, Hide sanity Show madness.

Set opacity for monsters depending on madness (just copy the transparentonsanity.lua).

  • Big Ups 1
Link to comment
Share on other sites

Rickzzs beat me to it but I'll leave this here anyway.

 

Now this is a pretty ambitious idea.

Coding a custom meter and a badge can be pretty hard at times because you need to correctly code client-server communication for the value. De-syncing is a pretty common issue here. What you would need is:
- A custom badge file
- A custom component
- A custom component replica
- Madness net_vars for stuff like updating the badge or showing the drain arrow (probably the most difficult part)
- /\ That would require you to modify player_classified
- And to top it all of you'll probably need to override a bunch of stuff from the sanity component and statusdisplays

Just to test if your badge shows up would probably require you to code at least the badge file and modify statusdisplays to display it. A simple code to add a widget to statusdisplays looks something like this:

local CustomBadge = require("widgets/custombadge")
local StatusDisplays = require("widgets/statusdisplays")
local old_StatusDisplays_ctor = StatusDisplays._ctor
StatusDisplays._ctor = function(self, owner, ...)
    old_StatusDisplays_ctor(self, owner, ...)

    if owner.prefab == "custom_character" then
        self.imagination = self:AddChild(CustomBadge(owner))
        self.moisturemeter:SetPosition(self.column3, -115, 0)
    end
end

I'd say that's a good start.

  • Big Ups 1
Link to comment
Share on other sites

4 hours ago, Rickzzs said:

1. Copy xxxbadge.lua and rename variables.

2. Add your badge to statusdisplays.

3. Hack statusdisplays to Show/Hide your badge properly.

4. Add a net variable to player_classified, if you are lazy just attach it to player.

5. Pass the value from server to client. Listen for value change and display the change.

 

assets:

Copy status_xxx.zip, and do a reskin.

 

In your case you need extra work:

Listen for sanity and sanity mode change, to properly Show/Hide your badge. For example, when sanity==0, Hide sanity Show madness.

Set opacity for monsters depending on madness (just copy the transparentonsanity.lua).

 

4 hours ago, -LukaS- said:

Rickzzs beat me to it but I'll leave this here anyway.

 

Now this is a pretty ambitious idea.

Coding a custom meter and a badge can be pretty hard at times because you need to correctly code client-server communication for the value. De-syncing is a pretty common issue here. What you would need is:
- A custom badge file
- A custom component
- A custom component replica
- Madness net_vars for stuff like updating the badge or showing the drain arrow (probably the most difficult part)
- /\ That would require you to modify player_classified
- And to top it all of you'll probably need to override a bunch of stuff from the sanity component and statusdisplays

Just to test if your badge shows up would probably require you to code at least the badge file and modify statusdisplays to display it. A simple code to add a widget to statusdisplays looks something like this:

local CustomBadge = require("widgets/custombadge")
local StatusDisplays = require("widgets/statusdisplays")
local old_StatusDisplays_ctor = StatusDisplays._ctor
StatusDisplays._ctor = function(self, owner, ...)
    old_StatusDisplays_ctor(self, owner, ...)

    if owner.prefab == "custom_character" then
        self.imagination = self:AddChild(CustomBadge(owner))
        self.moisturemeter:SetPosition(self.column3, -115, 0)
    end
end

I'd say that's a good start.

Thank you guys for your input, I'll try to follow what you said, I'll post what I come up with later tonight or tomorrow, I think that those two suggestions will help me greatly. But first, Calculus exam... :(

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...