Jump to content

Recommended Posts

Hello experienced modders of the Don't Starve Community! So I've been thinking about trying my hand at creating a little something of my own, but admittedly, my experience with coding and such is rather limited. (I've taken a couple classes, but that was years ago) So as I'm looking into it, I wanted to ask a few of the more knowledgeable folks if what I'm trying to do would be very difficult or not.

 

Basically what I'm aiming for is to create a mod that makes it so that when you build a wall, it spawns at full health instead of half health and can then be repaired. I don't think something like that would be too complicated, but I like I said I really wouldn't know, so if I could get an estimate from someone who does know what they're doing, I would very much appreciate it!

Link to comment
https://forums.kleientertainment.com/forums/topic/104144-may-i-get-an-estimate/
Share on other sites

Walls do spawn at half health and can be repaired to full health, and if they get damaged down from full health they can be repaired. This uses the health-component (the same one player characters and creatures use) in combination with the repairable-component.

It is immensely easy to do what you want :) Put this in the modmain.lua of your mod.

local affected_prefabs = 
{
	"walls_stone",
	"walls_wood",
	"walls_hay",
	"walls_ruins",
	"walls_moonrock"
}

for i, v in ipairs(affected_prefabs) do
    AddPrefabPostInit(v, function(inst)
		if inst.components.health then
			inst.components.health:SetPercent(1)
		end
	end)
end

 

Thank you very much for not only answering my question but also offering help on how to actually make it! :wilson_love: I figured that it would be a rather simple thing to implement, but like I said it's been a hot minute since I've touched any coding stuff so this is very much appreciated~

You're welcome :)

Take a look at my newcomer post. It includes sources and a few ultra-simple example mods, as well as links to the best sources for more tutorials and information about DST modding (by shamelessly linking to the big pinned threads on this forum which no-one ever looks at).

You can use the mod "Metabolizer" which I link to in the post as the base for your mod, simply replace the code in the modmain.lua with the code I wrote, correct the modinfo.lua (see the link to my other thread about how the modinfo.lua works, also in the newcomer post) and create a new preview image (use the TEXTool).

If you have further questions, don't be shy.

Edited by Ultroman

Again, thank you very much! And I do have a question actually.. Am I required to set configuration options in order for the mod to run properly? Or can I just leave them blank if the mod isn't meant to have them? (Which I think is the case for this mod?) I'm having a little trouble getting it work, though maybe I just copied the code you wrote wrong?

I thought this might come up. You can remove the entire configuration options bit, or leave it empty e.g.


configuration_options =
{
}

 

I would need to know which problems you are seeing, if I am to help troubleshooting. Are you getting errors, or is nothing happening?

I'm sorry to trouble you, but yeah nothing is happening. I place the wall and it still spawns at half health. On the plus side though, I was able to get the mod info stuff to say what I wanted it to, so at least I didn't mess that up! ^_^"

I took some screenshots of the code I have in the mod folder, does anything look out of the ordinary? I'm sorry to trouble you like this..

https://drive.google.com/open?id=1ai8nhU4Ak4JxVaDPZRAsQrkgD_-BDN7w

https://drive.google.com/open?id=1pqkUkGfSEO1NwNBvm6LEigkNTlYRkO-G

local affected_prefabs = 
{
	"wall_stone",
	"wall_wood",
	"wall_hay",
	"wall_ruins",
	"wall_moonrock"
}

for i, v in ipairs(affected_prefabs) do
    AddPrefabPostInit(v, function(inst)
		if inst.components.health then
			inst.components.health:SetPercent(1)
		end
	end)
end

 

Sorry, I had an "s" in the prefab names, as in "walls_stone" instead of "wall_stone".

Edited by Ultroman

Yes it does, though I haven't done anything to change the icon and some other things.

https://drive.google.com/open?id=1CcfoedMrp40ArKK0cj46ih0GB-VGppun

Ah yes, it works now! Thank you very much for you time! If I upload this to the steam workshop, is it all right if I leave you as the author seeing as how I really didn't do anything? :p I'm not even sure if anyone would be interested in such a simple tweak and if it's worth uploading at all ha ha.

If I'm to be put as author, I'd rather upload it myself, so I can keep it up-to-date.

I think you should take this little victory, since you did do some work here. Also, you have shown great appreciation for my time, so I'm "all payed up", so to speak ^^

It's your choice, really, whether you want to upload it to the workshop. If you just want to use it on your servers, you don't have to upload it. It's a server-mod after all, so clients do not need it, and so do not need to be able to download it when joining the server.

If you do want to share it, you should also be ready to keep it up-to-date. If a new wall comes along, the mod won't affect it if it isn't updated. If you're thinking about venturing into the world of modding, it could be a good first exercise for you, to create the preview image, and learn how to use the Mod Tools to upload a mod.

Your call, really.

P.S. You can remove the silly copyright line at the top of the modinfo.lua :)

Edited by Ultroman

Thank you, thank you~ I actually just got finished changing the little modicon thing, and I'll consider uploading it to the workshop if only to more easily share it with friends. To update it with new walls, all I'd really have to do would be to add them to that list of prefabs, correct?

Yep.

Finding the prefab names wasn't as straightforward as I thought it would be, though. They try to do as much as they can with batch-jobs and for-loops and references to global variables, so they can save lines of code and make things easily changeable after the fact, so it took some extra leaps to find them all. I could just have looked them up on the DS Wikia page, but if new walls come along in an update, the Wikia might not be updated right away, so you need to know how to figure it out from the code.

At the bottom of walls.lua (which creates ALL the wall prefabs) you can see a variable being created called "walldata" at the bottom. Each entry has a "name", and one such as "ruins" is easy enough since it's written out, but the rest reference the names from somewhere else e.g. MATERIALS.STONE. They use a global called MATERIALS to get the names, so I had to find them there. The MATERIALS variable / list is declared in the constants.lua, so you can go there and see the names of the materials. That's not all, though. The wall-generation code prefixes the prefab names with "wall_" so it becomes e.g. "wall_stone".

Those are the places you need to look, unless they for some odd reason decide to give a new wall its own prefab file (which they shouldn't).

Good luck in your ventures! Happy to help :D

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