Jump to content

[Mod Help] Unique perk for custom character when wearing hat from vanilla DST?


Recommended Posts

I want to create a unique effect for a custom character when he wears an already in game hat. I want him to unlock the first magic tier when he wears the Feather Hat. He should only be able to craft from this tier when he has this hat equipped. Once equipped he can not craft or use any magic items. This turned out to be more complicated to create than anything I made previously. Not only was the basic hat nested inside a single prefab with all the other hats but I also needed to add some custom code that I haven’t seen the likes of anywhere else. I tried to make a duplicate of the feather hat first by breaking it out as a single prefab file since I figured it would make it easier to make and perk exclusive to my character with a new item. Turns out the asset's name wasn't the same as the spawn name for the Feather Hat. I tried a bunch of strings that I found for the Feather Hat by file searching with notepad++ but didn’t get the right combination since they are not consistent depending on the type of the asset. Neither could I get my new recipe for the item to actually spawn the item, the character simply made the animation and then nothing. In the end I have to say this is far beyond my knowledge. I also figured that in the end it is probably cleaner to write some codes in the modmain.lua instead, but I feel even more lost  trying that. 


Any help would be greatly appreciated since I'm back to square one from hours of tries that lead nowhere in the end and have no idea where to start.

 

Regards,

Joppy

Link to comment
Share on other sites

You need to study how everything works, before you can hope to create something that works properly. One wrongly capitalized letter and nothing works. Don't look at what you've done so far as a failure. You have had your eyes and brain focused on this big beast for a while now, so you must have learned something about it, right? ;)

It's tough to get started, but I've tried to make it easier on people with this newcomer post (do the Lua Crash Course; it will let you have more time with your loved ones in the end, trust me!) and the tutorial post.

To address some of your specific concerns, no it is not a good idea to edit the existing game files, nor is it a good idea to try to replace an existing prefab. We have Klei's modding API, which you should learn to use (all the modmain.lua stuff, yes).

It is VERY HARD to switch back an forth between which specific recipes your character has access to, because it depends on several TECH levels, which are changed and therefore updated for your character when you get close to machines, all of which has to be ignored to get the effect you're looking for. I wouldn't try it myself, TBH. That said, take a look at the builder.lua. I can't see a way to get your dude to ONLY be able to use level 1 SCIENCE, but you can make the hat restrict the character to ONLY be able to make SCIENCE stuff (I think), at least. Your player's builder-component has the function:

function Builder:CanBuild(recname)

If you EXTEND this function, and before you return what the original function would do, you check the recname (recipe name) against a list you have, and if the recname is not in your list, then you return false instead of returning what the original function would have done. That should work, but you'll have to indicate exactly which recipes your character can craft, instead of using the TECH-levels to figure it out. You can check inside that function whether it should work normally, or your special way.

It's just an idea. It's not the best idea, because it will then ONLY let you craft those specific items, so any custom items added by mods would have to be added manually to the list. There are some recipe-related tutorials in the tutorial post, as well. Study up a bit, and I'm sure you'll find a solution that works for you, but I don't think you can get exactly what you're describing here, without writing some serious code or becoming more knowledgeable about the game code than I am (in certain areas that's not hard to do, really :p).

Godspeed!

Link to comment
Share on other sites

Thanks for the help and motivation. I’ve done some programming in C and some other scripting when modding other games, but I've not used lua format. I’ve managed to make a character that can do quite a lot of things, but this more complex functionality for an item is hard. I'm not familiar with the many different pre-existing tags, names and variables (the API I guess) in DST and fail to find a good list of them. List like this: https://github.com/Nsy/dontstarvemods/wiki/Recipes,-Prefabs,-Craft-and-Tabs is helpful. These in particular are quite easy to find in existing .lua files, but it would be easier if I don't have to do it for every pre-existing variable etc. It also increases the likelihood that I misinterpret something and pick the wrong one. Are there more like them? It's hard to reverse engineer things just to get a picture of how things work so that one can reuse the existing variables in smart ways. 

I’ve a working character that uses Klei's mod API. He has a beard and hair that when it grows increases his strength. This comes at the cost of lowering his max hunger and sanity and increasing the drain of them a lot. Similar to Wolfgang in the “food for power” regard, but you have to dedicate days (21 for max) of penalty to gain the power instead of being able to gain boost up whenever you wish in a matter of seconds at the cost of some food with no other penalty. I have a modmain.lua and a few custom prefab-items with their own recipes that work. I also have restricted his access to some recipes completely since I want to limit his access to “electronics”, for a lack of better word, since he is primitive being. The first thing I tried when making this magic-tier-unlocking-hat was making a new prefab called primitive_featherhat.lua. I tried to copy the functionality of the original feather hat from the hat.lua by "breaking it out", since the hat.lua contains the functionality of the majority of hats. I used this as a base for the hat: 


When I could not get the new feather hat to work I abandon that idea and thought it would be better to do it in the modmain.lua instead. Your solution makes it sound like I’m the right track in terms of how I’m thinking  about the logic behind the functions needed. I always try to think about how the “core logic” should work before I program anything. The problem is that I don’t know “the language”, or API rather, well enough yet, and therefore can not express what I’m thinking. I’ve to practice more first I guess and build my knowledge up to this. Maybe instead of making a list of items that he can craft I make a list of items he can not craft. Then he would automatically gain access to mod items. As you said, theoretically it should be doable, but I’m not there yet in practice. I will continue to gradually build up a better understanding for all things by doing various trial and error functions and increasing the complexity until I reach my goal.


This: http://dontstarveapi.com/ site is useful for many things, but I since it's made for DS and not DST I have yet to explore it a lot since I know that things don't works exactly the same between the games and I don't want to learn "wrong" the first time around, but would you recommend some of it anyway? What also makes it harder for me is the client and host side of things in DST and I've not completely wrapped my head around how it affects how I write my code. It was easier in DS. :)

Edited by JonatannossreP
Link to comment
Share on other sites

Everything you say sounds exactly like what everyone else thinks when they start modding for DS/DST :D You just gotta look at the game code. "How does this work?" *searches game code for keyword or phrase* "Hmm...ok. They listen for this event." *search game code for event name* "Ah! When pushed, this event gets some data attached! We can use this. Now, how did those listeners work?" *goes and finds the listeners from before*

That's the process.

That's why I've done a bunch of write-ups about how different systems work. You can find a lot around the forum. Use the search tips in the newcomer post to find things. Even if the thread is about DS, most of it translates more or less painlessly. The networking-stuff is scary, but once you learn the basic rules, it's not that hard, but it does get complicated with client/server communication. But then, there's an API for that and plenty of examples on the forum.

Link to comment
Share on other sites

Currently I have this:

local function sanity_primitive(inst)

    if inst.components.sanity.current >= (40) then 
    
        inst.components.builder.science_bonus = (0)
        inst.components.builder.magic_bonus = (0)
        inst.components.builder.ancient_bonus = (0)
        inst.components.builder.volcanic_bonus = (0)
        
    elseif inst.components.sanity.current > (0) and inst.components.sanity.current < (40) then 
        
        inst.components.builder.science_bonus = (-1)
        inst.components.builder.magic_bonus = (-1)
        inst.components.builder.ancient_bonus = (-1)
        inst.components.builder.volcanic_bonus = (-1)
        
    elseif inst.components.sanity.current < (1) then 
        
        inst.components.builder.science_bonus = (-10)
        inst.components.builder.magic_bonus = (-10)
        inst.components.builder.ancient_bonus = (-10)
        inst.components.builder.volcanic_bonus = (-10)
    
    end
    
end

 

local master_postinit = function(inst)

    inst:ListenForEvent("sanitydelta", function(inst) sanity_primitive(inst) end)

    sanity_primitive(inst)

end

I don't really want it to be a -10 "bonus" however (that is just a placeholder) as it doesn't temporarily hide already learnt recipes. But I figured it might be easier to disable crafting by hiding the actual HUD element than adding and removing recipes. This lead me to this:

However, I do not understand how to implement it into my function. Any clues you can give me?

Edited by JonatannossreP
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...