Ran Posted March 7, 2015 Share Posted March 7, 2015 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 Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 @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 Link to comment Share on other sites More sharing options...
Ran Posted March 7, 2015 Author Share Posted March 7, 2015 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? Link to comment Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 Here's a very, very simple sample mod I just made to demonstrate one approach to doing something similar to what you want.crazymoon.zip Link to comment Share on other sites More sharing options...
Ran Posted March 7, 2015 Author Share Posted March 7, 2015 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? Link to comment Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 local n = #moonphases-1The # 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 = 2Since 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). Link to comment Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 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. Link to comment Share on other sites More sharing options...
Ran Posted March 7, 2015 Author Share Posted March 7, 2015 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 Link to comment Share on other sites More sharing options...
Ran Posted March 7, 2015 Author Share Posted March 7, 2015 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. Link to comment Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 @Ran, The easiest way to test this stuff is to pop open a console and test!print(math.floor(-5))print(math.floor(-5.5))print(math.floor(.5))numcycles is the current day. I believe day 1 is "0", so it lags behind what is displayed on the clock by 1. Link to comment Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 Oh holy balls I think I got it. Bah! You beat me by like 2 seconds Yeahp, that's it! Edit: http://www.lua.org/manual/5.2/manual.html#6.6 Link to comment Share on other sites More sharing options...
Ran Posted March 7, 2015 Author Share Posted March 7, 2015 Hah, shoulda refreshed the page before editing 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. Link to comment Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 @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 Link to comment Share on other sites More sharing options...
Ran Posted March 7, 2015 Author Share Posted March 7, 2015 Wait, you mean this would actually work fine? I thought it was just to see how messing with the phases would screw everything up, lol. Link to comment Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 Nah you should be fine modifying the phases, I would just recommend highly against doing it in the actual game files Link to comment Share on other sites More sharing options...
Ran Posted March 7, 2015 Author Share Posted March 7, 2015 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) Link to comment Share on other sites More sharing options...
Corrosive Posted March 7, 2015 Share Posted March 7, 2015 By the way, I don't see the "half" phase anywhere in that mod, was that intentional? Err... yes "totally intentional" and "not in any way oversight!" <.< I was uhhh, testing you! Good job! (fixed version attached)crazymoon.zip Link to comment Share on other sites More sharing options...
Ran Posted March 7, 2015 Author Share Posted March 7, 2015 Lol, alrighty then, thanks for the update 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. Link to comment Share on other sites More sharing options...
randowcann Posted March 8, 2015 Share Posted March 8, 2015 taking advantage of the poster could help me with ascript? does anyone know how to make a button with code type: StartKey Link to comment Share on other sites More sharing options...
Corrosive Posted March 8, 2015 Share Posted March 8, 2015 @randowcann, If you can't find a solution for what you want to do using the forum search function, create a new post and give all the details of what you are trying to accomplish. Link to comment Share on other sites More sharing options...
randowcann Posted March 8, 2015 Share Posted March 8, 2015 @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 Link to comment Share on other sites More sharing options...
Corrosive Posted March 8, 2015 Share Posted March 8, 2015 @randowcann, You have only posted topics in the Don't Starve Together forum. I have not tried modding DST, so I don't know if I would be able to help you. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.