Jump to content

Recommended Posts

Well, back here to try and clear my ignorance on modding.

 

This time I wanted to know if it's possible to modify two things. First, what I imagine is simpler, Glommer's health and regen. They don't seem to be in tuning.lua, and I can't find exactly where they are.

 

Second, the moon cycle. I'd like to know if it's possible to modify how many days each phase lasts, or even remove some phases. I love full moons but I play with modded, much longer days, so there's a looong time between each full moon.

 

So there, any information is appreciated.

Link to comment
https://forums.kleientertainment.com/forums/topic/51808-moon-stuff-questions/
Share on other sites

@Ran,

 

Moon phases are defined in clock.lua.

 

 

I'm not sure if you know anything about modding, but I wouldn't recommend changing code in there directly.

local moonphases = {    "new",    "quarter",    "half",    "threequarter",    "full",}function Clock:GetMoonPhase()    local phaselength = 2    local n = #moonphases-1        local idx = math.floor(self.numcycles/phaselength) % (2*n)        if idx >= n then        idx = n*2 - idx    end        return moonphases[idx+1]end

I have somewhat of an idea of modding. Not much, but enough to not do any irreversible damage. Probably.

 

Anyway, that's a much shorter piece of code than I imagined for the whole moon cycle, hmm... I guess I could make all phases last 1 day changing "phaselength", but I was hoping I could change them individually. Guess not. Maybe I can simply delete some phases from the first part? Doesn't seem like they are referenced specifically by name, so it shouldn't break anything, right?

Lol, I'm afraid to check. Guess I was right to wait. Yeah, I don't know enough lua but after a bit I started thinking maybe the change in number of phases would mess up the whole function down there. Been trying to figure out exactly how it works but I can't decipher what some things are, like "math.floor". Something about rounding a number I think, but really dunno.

 

So I suppose I can at least make phases last 1 day each safely?

 

Also, any idea on the Glommer health thing?

    local n = #moonphases-1

The # symbol tells lua to count the number of items in the table.  Here, n is being set to "1 less than the number of phases."  The reason for this will be clear at the end.

    local idx = math.floor(self.numcycles/phaselength) % (2*n)

math.floor is function that rounds a number down to the nearest whole integer.  It does this because this number is being used as the index to look up which phase to return, and table/array indices have to be integers.

 

The % symbol is the modulus (or mod) operator.  Modulus is normally explained using a clock analogy, but I think it's easier to think of it this way:

 

% takes the first number, and repeatedly subtracts the second number until it can't anymore(without going below 0).  The remainder is what gets returned.  For example:

 

8 % 3 would do this:

 

8 - 3 = 5

 

5 - 3 = 2

Since you can't take 3 away from 2 without going into the negatives, 2 is returned.

    return moonphases[idx+1]

Since modulus can return 0 if there's no remainder, and arrays start at 1 in lua, the index is incremented by 1  (this is why n = #moonphases-1).

Edited by Corrosive

As for glommer, I believe he gets the default amount of health when the health component gets added, which is 100. Like most other things, he doesn't have innate health regeneration.

 

You could make a mod to change these values easily, though.

 

In modmain.lua:

AddPrefabPostInit("glommer", function(inst)    inst.components.health:SetMaxHealth( <max health here> )    inst.components.health:StartRegen( <health gained per tick here>, <tick period here> )end)

You can append this to that mod I attached earlier if you want.  The period for chester, for example is 3.

Wow, okay, I never thought that % meant something other than "percentage of", lol. I figured the #moonphases part, yeah. So I guess n is initially set to 4. Read somewhere about that math.floor rounding but wasn't sure exactly how. Does it round stuff down no matter what? As in, can it round down to 0, or to negatives? And what about numcycles? I assume it's how many times the function went in a loop, but does it start at 1, or 0?

 

I get that in the end, idx has to be 0 to 4, so that the return is one of the 1 to 5 phases. I think I'll try doing the math backwards, see if I figure some more out :p

Oh holy balls I think I got it.

 

numcycles is the number of days that have passed, right? So it starts at 0, on day 1. And since it's dividing that by phaselength (which is always 2) and then rounding it down, then every even day (which is an uneven numcycle), will end up in .5, which gets rounded down, so it doesn't change the moonphases on even days. Right?

 

Edit: So if all my math is correct, I think I can indeed make the moon change every day by just changing phaselength to 1.

Edited by Ran

Hah, shoulda refreshed the page before editing :razz: Well, this coding thing is pretty cool, I can't imagine how someone managed to think up a function like that, so that it always keeps going back and forth between 1 and 5. I mean, one thing is to understand it, another is to come up with it from scratch.

 

Now I kinda wanna try and do a different one to make full moons last 2 days, but the rest last only 1 (which would be the ideal for me), or something like that, but I really think that's out of my reach for now, heh.

 

Oh, and thanks for all the help, by the way, lol.

 

Don't have any ideas about the other thing I wanted to change, I suppose?

Asadf nevermind, missed the part where you talked about that.

Edited by Ran

@Ran,

 

Sorry for late response, I had to go buy/cook dinner.

 

Here's an updated version that lets you specify the duration in days for each phase.

 

 

Edit:  I left in the phaselength variable so you can play around with it if you'd like.

crazymoon.zip

Edited by Corrosive

Oooh, yeah okay, I get it. Yeah when I started tweaking the game I did modify some game files, but that was before I knew how to do a mod for it. I don't know enough to make something new from scratch but at least I know I can just copy the file into a mod folder and modify that. What I discovered recently is that I should be copying the DLC files rather than the base game ones, lol.

 

By the way, I don't see the "half" phase anywhere in that mod, was that intentional? Would I be fine adding it myself? I figure I can just copy the code of one of the other phases and edit the name and numbers accordingly.

 

Edit: Hmm, actually, I'm not sure how to modify modmain.lua accordingly to add a phase in there... Like, in the for and the function, not sure if I should be changing some number there (maybe I gotta change the 1, 4, 1, to 1, 5, 1? Dunno xD)

Edited by Ran

Lol, alrighty then, thanks for the update :razz:

 

By the way, you could totally upload this to the workshop or something, there's nothing like this around. Closest I found is something to display the moon icon during day/dusk, and that was literally the only moon-related mod I found.

Edited by Ran

@Corrosivo

 

already opened a poll anyone else answer
 
would you assist me?
 
I would like to take the time this script!
 
----------------------------------------------------------------
 
         inst: AddComponent ("periodicspawner")
         inst.components.periodicspawner: SetPrefab ("nightmarefuel")
         inst.components.periodicspawner: SetRandomTimes (120, 240) <- team
         inst.components.periodicspawner: SetDensityInRange (-100, 5000000)
         inst.components.periodicspawner: SetMinimumSpacing (50000)
         inst.components.periodicspawner: Start ()
-----------------------------------------------------------------
 
 
in place to make it It starts when I apertase a button

 

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
×
  • Create New...