Jump to content

[SOLVED] How to add dapperness based on moon phase?


Recommended Posts

Hello! I've ditched my previous two ideas in favor of something a little more manageable. Basically, I want to make my character gain sanity based on the phase of the moon, with the highest being during a full moon and the lowest being during a new moon. The code I currently have looks like this: 

local function Clock:GetMoonPhase()
	if --(whatever i would put for it being nighttime)
	 	if isfullmoon then
			--[insert dapperness thingy here]
		etc, etc.

Is what I have right now on the right track? And how would I reset the dapperness value after night, so that she isn't constantly gaining sanity while the sun"s out? Also, is it possible to make it like a sliding scale between the maximum and minimum sanity gain (basically it's like a smooth transition b/w full and new?? idk if i'm explaining this well enough) Thanks for any help!

Edited by poppychips
Link to comment
Share on other sites

Use this:
inst:WatchWorldState("moonphase", onmoonphasechagned)

local function onmoonphasechagned(inst,phase)
    --...
end

phase can be: "new", "quarter", "half", "threequarter", "full"
I guess this is enough to make it "smooth".

PS:
How did I find out about this, although I had no clue about moonphase? I simply used notepad++ search and searched all script lua files for "isfullmoon" there I found "inst:WatchWorldState("isfullmoon" . So I searched for "WatchWorldState" and found it with "moonphase" and the onmoonphasechagned. Then I searched for moonphase and found a line that contained "MOON_PHASE_NAMES". I searched for this and found inclock.lua all possible moon phases. Done.

 

Edited by Serpens
Link to comment
Share on other sites

3 minutes ago, Serpens said:

inst:WatchWorldState("moonphase", onmoonphasechagned)

local function onmoonphasechagned(inst,phase)
    --...

What would I add inside? (sorry, I really am new to this) also, would this go in the character.lua file?

Link to comment
Share on other sites

yes in character.lua file. The inst:Watch... should belong in the masterpostinit I guess.

I'm not sure about the sanity thing... do you know anything similar that is already in the game where we could look up in the files?
I only know things that have sanityaura, like evil flowers. But in this case an aura would not help.
There is "function Sanity:DoDelta(delta, overtime)" but I think it is also not exactly what we are looking for... The best I can imagine is that you reduce/increase the sanity eg. every x seconds by a fixed value as long as the moon phase eg full, but there must be a better way...

Edited by Serpens
Link to comment
Share on other sites

1 minute ago, Serpens said:

The best I can imagine is that you reduce/increase the balance eg. every x seconds by a fixed value as long as the moon phase eg full, but there must be a better way...

Hmm, perhaps I could alter the character's dapperness value somehow? Is it possible to use the DoDelta idea with my character's current dapperness value?

Link to comment
Share on other sites

1 minute ago, poppychips said:

Hmm, perhaps I could alter the character's dapperness value somehow? Is it possible to use the DoDelta idea with my character's current dapperness value?

what do you mean?
inst.components.sanity:DoDelta(5) would increase his sanity value by 5 one time. (I think dapperness and sanity means the same?)

Link to comment
Share on other sites

Just now, Serpens said:

(I think dapperness and sanity means the same?)

To my understanding, dapperness is the continual sanity gain you get from clothing items (like a garland, for example). So basically, if I were to increase it by 5, it would add on to the current value, instead of just increasing sanity by 5

Link to comment
Share on other sites

@serpens How does this look?

inst:WatchWorldState("moonphase", onmoonphasechagned)

local function onmoonphasechagned(inst,quarter)
	inst:AddComponent("dapperness")
	DoDelta(TUNING.DAPPERNESS_TINY
	
local function onmoonphasechagned(inst,half)
	inst:AddComponent("dapperness")
	DoDelta(TUNING.DAPPERNESS_SMALL
	
local function onmoonphasechagned(inst,threequarters)
	inst:AddComponent("dapperness")
	DoDelta(TUNING.DAPPERNESS_MEDIUM
	
local function onmoonphasechagned(inst,full)
	inst:AddComponent("dapperness")
	DoDelta(TUNING.DAPPERNESS_LARGE

 

Link to comment
Share on other sites

Ah I found the best solution. I saw in sanity.lua there is a "custom_rate_fn", where you can add/reduce dapperness for your specific character.

So all you do is in your masterpostinit:
inst.components.sanity.custom_rate_fn = Custom_Dapperness

and above your masterpostinit you do:
local function Custom_Dapperness(inst)
    if TheWorld.state.moonphase=="half" then
        return 5 -- +5 dapperness
    elseif --...

    end
end

So you do not need the WatchWorldState stuff.

edit: No your code is nonesense (sry =/) You only add a component once, never more. And the DoDelta is always called with inst.components.sanity:DoDelta(). And you only use one! onmoonphasechagned(inst,phase). In that you would do "if phase=="full" then ..."

Edited by Serpens
Link to comment
Share on other sites

1 minute ago, poppychips said:

@Serpens I tried to run the mod, but when I did, my game crashed. I attached a picture of the error screen. I think the problem is that there wasn't a dapperness value set beforehand, so perhaps I have to set it to zero the first time the character spawns in?

image.png

what is your code?

Link to comment
Share on other sites

Just now, Serpens said:

what is your code?

local function Custom_Dapperness(inst)
    if TheWorld.state.moonphase=="quarter" then
        return 5 -- +5 dapperness
    elseif TheWorld.state.moonphase=="half" then
        return 10 -- +10 dapperness
	elseif TheWorld.state.moonphase=="threequarters" then
        return 15 -- +15 dapperness
	elseif TheWorld.state.moonphase=="full" then
        return 20 -- +20 dapperness

    end
end

Here ya go! Is there anything in particular I'm doing wrong?

Link to comment
Share on other sites

you forgot the moon phase "new". Since you did not mention it, it returns automatically the value "nil". And then in sanity.lua the game tries to make dapperness+nil which gives you the error.

 

local function Custom_Dapperness(inst)
    if TheWorld.state.moonphase=="quarter" then
        return 5 -- +5 dapperness
    elseif TheWorld.state.moonphase=="half" then
        return 10 -- +10 dapperness
	elseif TheWorld.state.moonphase=="threequarters" then
        return 15 -- +15 dapperness
	elseif TheWorld.state.moonphase=="full" then
        return 20 -- +20 dapperness
    elseif TheWorld.state.moonphase=="new" then
        return 20 -- +20 dapperness
    end
    return 0 -- just in case something went wrong. add +0 dapperness and not "nil"
end

 

Edited by Serpens
Link to comment
Share on other sites

1 minute ago, poppychips said:

@Serpens While it didn't crash my game, which is always a good sign, my character's sanity rapidly went back up to the maximum value as soon as the next day started, which is certainly a problem.

try it with return TUNING.DAPPERNESS_TINY  and those values. The return 5 was only an example how you use it.

Link to comment
Share on other sites

4 minutes ago, poppychips said:

ok, I'll try that!

btw you can speed up the game with opening the console ingame and type in "LongUpdate(480)" this will make one whole day pass ;) (smaller numbers for less time, higher for more). This makes testing easier ;)

Link to comment
Share on other sites

Just now, Serpens said:

btw you can speed up the game with opening the console ingame and type in "LongUpdate(480)" this will make one whole day pass ;) (smaller numbers for less time, higher for more). This makes testing easier ;)

cool, thanks!

Link to comment
Share on other sites

@Serpens Ok, so no game crashes, and no crazy increase in sanity at daybreak. There is, however, the issue of how to stop the sanity increase once day rolls around, because the character's sanity continues to increase. Is there a TUNING.DAPPERNESS_DEFAULT that I don't know about? Or is there another way to solve this?

Link to comment
Share on other sites

Ah you only want the dapperness increase at night?
Then also use the TheWorld.state.isnight
As you see in my comments in the code, it is "+5". So if you want to go back to normal, simply "return 0".

local function Custom_Dapperness(inst)
    if TheWorld.state.isnight then    
        if TheWorld.state.moonphase=="quarter" then
            return 5 -- +5 dapperness
        elseif TheWorld.state.moonphase=="half" then
            return 10 -- +10 dapperness
	    elseif TheWorld.state.moonphase=="threequarters" then
            return 15 -- +15 dapperness
	    elseif TheWorld.state.moonphase=="full" then
            return 20 -- +20 dapperness
        elseif TheWorld.state.moonphase=="new" then
            return 20 -- +20 dapperness
        end
    end
    return 0 -- in all other cases, no dapperness bonus
end
Link to comment
Share on other sites

7 minutes ago, Serpens said:

Ah you only want the dapperness increase at night?
Then also use the TheWorld.state.isnight
As you see in my comments in the code, it is "+5". So if you want to go back to normal, simply "return 0".


local function Custom_Dapperness(inst)
    if TheWorld.state.isnight then    
        if TheWorld.state.moonphase=="quarter" then
            return 5 -- +5 dapperness
        elseif TheWorld.state.moonphase=="half" then
            return 10 -- +10 dapperness
	    elseif TheWorld.state.moonphase=="threequarters" then
            return 15 -- +15 dapperness
	    elseif TheWorld.state.moonphase=="full" then
            return 20 -- +20 dapperness
        elseif TheWorld.state.moonphase=="new" then
            return 20 -- +20 dapperness
        end
    end
    return 0 -- in all other cases, no dapperness bonus
end

sweet, thanks! I really appreciate all your help with this!!

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...