Recommended Posts

-Penta-    2

Quick question: Is there a way to edit an item's properties in order to change its type and effects? I wanted to make the Beefalo Hat a head armor and lower its insulation, but I have no idea where to start.

Share this post


Link to post
Share on other sites
rawii22    3

This might be a tiny bit more complicated than most prefabs since all the hats are held in one file, but it could work. If you are familiar with AddPrefabPostInit, see if you can add a function to the prefab "beefalohat" that adds a certain tag or component. You can make a hat in game to see if your desired properties exist.

After thinking about it for a another minute, this should work since when the game loads up, all the hat prefabs are already compiled and considered their own entities.

In any case, the components you're looking for are the "armor" and "insulator" components.

Your function might look like this:

AddPrefabPostInit("beefalohat", function(prefab)
	prefab:AddComponent("armor")
 	prefab.components.armor:InitCondition(*health of the hat as a number*, *damage absorption number*)
 	--inst.components.armor:InitCondition(TUNING.ARMOR_WATHGRITHRHAT, TUNING.ARMOR_WATHGRITHRHAT_ABSORPTION)
 	--The line above is an example so you can look at what the numbers normally look like in tuning.lua
    
 	prefab:AddComponent("insulator")
 	inst.components.insulator:SetSummer() --not sure what this does; I copied it from hats.lua. You probably don't need it. Look in insulator.lua for more functions
 	inst.components.insulator:SetInsulation(TUNING.INSULATION_SMALL) --You can look in tuning.lua to see what value this is and put in your own.
end)

If you're interested in other properties or components, you can always look for examples in the prefabs folder for when they use AddTag or AddComponent. Also I don't know how much you know, but you can also use RemoveTag or RemoveComponent just as simply.

Share this post


Link to post
Share on other sites
-Penta-    2

I don't know much to be honest, I just got into modding this week, and most of what I'm doing is just personal stuff. I tried using AddTag and AddComponent before, but the game either just crashed as soon as I opened it, or nothing changed at all.

Also, I just tested what you proposed, and it crashed as soon as I crafted the hat.

AddPrefabPostInit("beefalohat", function(prefab)
    prefab:AddComponent("armor")
    prefab.components.armor:InitCondition(525, 80)
    inst.components.armor:InitCondition(TUNING.ARMOR_WATHGRITHRHAT, TUNING.ARMOR_WATHGRITHRHAT_ABSORPTION)
         
     prefab:AddComponent("insulator")
     inst.components.insulator:SetSummer()
inst.components.insulator:SetInsulation(TUNING.INSULATION_SMALL)
end)

Was it a mistake on my end, or are we to assume this approach doesn't work?
 

Edited by -Penta-

Share this post


Link to post
Share on other sites
rawii22    3

What did the crash screen say?

Also you can delete these lines:

inst.components.armor:InitCondition(TUNING.ARMOR_WATHGRITHRHAT, TUNING.ARMOR_WATHGRITHRHAT_ABSORPTION)

inst.components.insulator:SetSummer()

Also, change all the times you see the word "inst" to "prefab".

Also also, just to supplement what we're trying here, try to look for a simple mod that changes something about a prefab and check out its modmain file.

Edited by rawii22

Share this post


Link to post
Share on other sites
-Penta-    2

I don't remember what it said, actually, and the logs have already been deleted so I can't really check now :/

I tried looking for mods that did similar things to re-purpose the code, but I haven't found any so far. Still, I'll keep trying to make it work. There's still some things I didn't test, and the Beefalo Hat isn't the only clothing item whose properties I'm trying to change.

Also, as a side note, is there any way to change an item's name?

Edited by -Penta-

Share this post


Link to post
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