Jump to content

Help with a custom code and tips on character creation


Recommended Posts

Hi all, I've posted a part of my question in the character guide tutorial using extended sample character template but people don't seem to be active there so I will try my luck here. I've recently started to make my first character mod and I wish to start doing the artwork at this point. But first I want to make my character not have a tail. The guide says that I'm supposed to replace the exsisting tail pictures with black (transparent) pictures in order to get rid of the tail. So I did do that and in spriter I can see the tail gone which is good but as soon as I check it ingame the tail is still there. If anyone has a guide that a 6 year old kid could follow regarding drawing to recommend or tips that would be great. I've made my character vegeterian but I wish to also have my character recieve additional sanity when wearing anything in the clothing tab (this also means that a walking cane would give a small amount sanity as well). I don't know of a character that at least has a similar code to this to even study this from nor well, the knowledge to know how to make my own codes. I would also like to note that if anyone has any general tips for me it would be much appreciated, thank you for your time. 

Link to comment
Share on other sites

51 minutes ago, mranon245 said:

I would also like to note that if anyone has any general tips for me it would be much appreciated, thank you for your time. 

Put the files from this thread in your mod, it makes life easier:

 

51 minutes ago, mranon245 said:

I wish to also have my character recieve additional sanity when wearing anything in the clothing tab (this also means that a walking cane would give a small amount sanity as well).

In your mod's character.lua, above common_postinit and master_postinit:

local function sanityfn(inst)
	for k,v in pairs(inst.components.inventory.equipslots) do
		if AllRecipes[v.prefab].tab == RECIPETABS.DRESS then
			return TUNING.DAPPERNESS_SMALL -- Change this value after the "return " to change the sanity amount
		end
	end
	return 0
end

 

In your character's master_postinit:

inst.components.sanity.custom_rate_fn = sanityfn

 

 

If you want to change the amount of sanity regen when an item from the dress tab is equipped, change the return value in the fourth line of the first piece of code, "return TUNING.DAPPERNESS_SMALL".

From the base game's data/scripts/tuning.lua:

		DAPPERNESS_TINY = 100/(day_time*15),
		DAPPERNESS_SMALL = 100/(day_time*10),
		DAPPERNESS_MED = 100/(day_time*6),
		DAPPERNESS_MED_LARGE = 100/(day_time*4.5),
		DAPPERNESS_LARGE = 100/(day_time*3),
		DAPPERNESS_HUGE = 100/(day_time),

day_time is seg_time * day_segs.

seg_time is 30.

day_segs is 10.

day_time therefore is 300.

 

TUNING.DAPPERNESS_TINY is 100/(300*15) = 0.02 sanity regen.

TUNING.DAPPERNESS_SMALL is 100/(300*10) = 0.03 sanity regen.

TUNING.DAPPERNESS_MED is 100/(300*6) = 0.05 sanity regen.

TUNING.DAPPERNESS_MED_LARGE is 100/(300*4.5) = 0.074 sanity regen.

TUNING.DAPPERNESS_LARGE is 100/(300*3) = 0.11 sanity regen.

TUNING.DAPPERNESS_HUGE is 100/(300) = 0.33 sanity regen.

print("TUNING.DAPPERNESS_TINY is " .. TUNING.DAPPERNESS_TINY)
print("TUNING.DAPPERNESS_SMALL is " .. TUNING.DAPPERNESS_SMALL)
print("TUNING.DAPPERNESS_MED is " .. TUNING.DAPPERNESS_MED)
print("TUNING.DAPPERNESS_MED_LARGE is " .. TUNING.DAPPERNESS_MED_LARGE)
print("TUNING.DAPPERNESS_LARGE is " .. TUNING.DAPPERNESS_LARGE)
print("TUNING.DAPPERNESS_HUGE is " .. TUNING.DAPPERNESS_HUGE)

[00:00:40]: TUNING.DAPPERNESS_TINY is 0.022222222222222    
[00:00:40]: TUNING.DAPPERNESS_SMALL is 0.033333333333333    
[00:00:40]: TUNING.DAPPERNESS_MED is 0.055555555555556    
[00:00:40]: TUNING.DAPPERNESS_MED_LARGE is 0.074074074074074    
[00:00:40]: TUNING.DAPPERNESS_LARGE is 0.11111111111111    
[00:00:40]: TUNING.DAPPERNESS_HUGE is 0.33333333333333    

 

If you dont use the engine.lua from the thread I linked before (and modimport it like the instructions say) you might have to write GLOBAL.TUNING instead of TUNING, and things like that.

 

Edited by DrSmugleaf
Link to comment
Share on other sites

had you used the autocompiler after deleting the tail? have you renamed those files? have you renamed your anim files? have you renamed all required files that were needed to be renamed? had you managed to recode all of the "esctemplates" to your characters name? if all answers to all these questions lead to 'yes', then, if possible, send me the zip file.

Edited by G
Link to comment
Share on other sites

I'm not sure, I have renamed all of the esctemplates to my character name from what I see but if I was supposed to rename the actual tail parts then no. I didn't try deleting the tail folder, just replacing the pictures within it with black transparent ones like the guide told me to. Won't there be issues with textures or something if I just delete the tail folder outright? I've heard someone mention this before somewhere (maybe).

13 hours ago, DrSmugleaf said:

Put the files from this thread in your mod, it makes life easier:

 

In your mod's character.lua, above common_postinit and master_postinit:


local function sanityfn(inst)
	for k,v in pairs(inst.components.inventory.equipslots) do
		if AllRecipes[v.prefab].tab == RECIPETABS.DRESS then
			return TUNING.DAPPERNESS_SMALL -- Change this value after the "return " to change the sanity amount
		end
	end
	return 0
end

 

In your character's master_postinit:


inst.components.sanity.custom_rate_fn = sanityfn

 

 

If you want to change the amount of sanity regen when an item from the dress tab is equipped, change the return value in the fourth line of the first piece of code, "return TUNING.DAPPERNESS_SMALL".

From the base game's data/scripts/tuning.lua:


		DAPPERNESS_TINY = 100/(day_time*15),
		DAPPERNESS_SMALL = 100/(day_time*10),
		DAPPERNESS_MED = 100/(day_time*6),
		DAPPERNESS_MED_LARGE = 100/(day_time*4.5),
		DAPPERNESS_LARGE = 100/(day_time*3),
		DAPPERNESS_HUGE = 100/(day_time),

day_time is seg_time * day_segs.

seg_time is 30.

day_segs is 10.

day_time therefore is 300.

 

TUNING.DAPPERNESS_TINY is 100/(300*15) = 0.02 sanity regen.

TUNING.DAPPERNESS_SMALL is 100/(300*10) = 0.03 sanity regen.

TUNING.DAPPERNESS_MED is 100/(300*6) = 0.05 sanity regen.

TUNING.DAPPERNESS_MED_LARGE is 100/(300*4.5) = 0.074 sanity regen.

TUNING.DAPPERNESS_LARGE is 100/(300*3) = 0.11 sanity regen.

TUNING.DAPPERNESS_HUGE is 100/(300) = 0.33 sanity regen.


print("TUNING.DAPPERNESS_TINY is " .. TUNING.DAPPERNESS_TINY)
print("TUNING.DAPPERNESS_SMALL is " .. TUNING.DAPPERNESS_SMALL)
print("TUNING.DAPPERNESS_MED is " .. TUNING.DAPPERNESS_MED)
print("TUNING.DAPPERNESS_MED_LARGE is " .. TUNING.DAPPERNESS_MED_LARGE)
print("TUNING.DAPPERNESS_LARGE is " .. TUNING.DAPPERNESS_LARGE)
print("TUNING.DAPPERNESS_HUGE is " .. TUNING.DAPPERNESS_HUGE)

[00:00:40]: TUNING.DAPPERNESS_TINY is 0.022222222222222    
[00:00:40]: TUNING.DAPPERNESS_SMALL is 0.033333333333333    
[00:00:40]: TUNING.DAPPERNESS_MED is 0.055555555555556    
[00:00:40]: TUNING.DAPPERNESS_MED_LARGE is 0.074074074074074    
[00:00:40]: TUNING.DAPPERNESS_LARGE is 0.11111111111111    
[00:00:40]: TUNING.DAPPERNESS_HUGE is 0.33333333333333    

 

If you dont use the engine.lua from the thread I linked before (and modimport it like the instructions say) you might have to write GLOBAL.TUNING instead of TUNING, and things like that.

 

I will give this a shot asap. Can you please link the thread you are referring to?

Link to comment
Share on other sites

51 minutes ago, DrSmugleaf said:

It is linked in the first post, but the forums automatically change the link to be the embedded image thing. http://forums.kleientertainment.com/topic/63754-tutorial-character-transformation

Thank you, I've tried doing the code but dress clothings don't give any sanity at all now and the game crashes when I wear a tam. Was I supposed to change something else that I forgot? 7e7fabb876.png

Link to comment
Share on other sites

6 hours ago, mranon245 said:

 

I'm not sure, I have renamed all of the esctemplates to my character name from what I see but if I was supposed to rename the actual tail parts then no. I didn't try deleting the tail folder, just replacing the pictures within it with black transparent ones like the guide told me to. Won't there be issues with textures or something if I just delete the tail folder outright? I've heard someone mention this before somewhere (maybe).

 

i didn't mean it in a way of literally deleting the file entirely, i meant replacing it, so, my bad. but if unsure of which or what file to rename, i shalst show the required files (red = rename, blue = delete then autocompile, black = ignore) make sure to look at what folder i'm in to see the location and such: 

files1.png

files2.png

files3.png

files4.png

files5.png

files6.png

files7.png

files8.png

files9.png

Edited by G
Link to comment
Share on other sites

42 minutes ago, G said:

i didn't mean it in a way for deleting the file entirely, i meant replacing it, so, my bad. but if unsure of which or what file to rename, i shalst show the required files (red = rename, blue = delete then autocompile, black = ignore) make sure to look at what folder i'm in to see the location and such: 

files1.png

files2.png

files3.png

files4.png

files5.png

files6.png

files7.png

files8.png

files9.png

The tail is gone now, I did most of this before except for deleting all of the tex and xml files and also not deleting the anim zip file which I should have done. I don't suppose you would know the most optimal way to start drawing the artwork? I'm no artist so this should be interesting. Oh and thank you.

Link to comment
Share on other sites

why, if it comes to art, then you've come to the right person, for i do all art for all of my mods. not to say i'd call my art "amazing" or such. but i would say rather decent. as you saw, the character dubbed 'War' is my newest project see. intense coding is done by DarkXero, but let's not get too far into my mod. but the way i'd do my art is by using a software called 'sai'. now, what i'd recommend is just to use whatever art software you're most used too, to be honest. nothing much really. just make sure to save it as a .png is all.

Edited by G
Link to comment
Share on other sites

6 hours ago, G said:

why, if it comes to art, then you've come to the right person, for i do all art for all of my mods. not to say i'd call my art "amazing" or such. but i would say rather decent. as you saw, the character dubbed 'War' is my newest project see. intense coding is done by DarkXero, but let's not get too far into my mod. but the way i'd do my art is by using a software called 'sai'. now, what i'd recommend is just to use whatever art software you're most used too, to be honest. nothing much really. just make sure to save it as a .png is all.

That is very convenient I have to say. I will give paint tool sai a go then, thank you for your time.

Link to comment
Share on other sites

13 minutes ago, mranon245 said:

That is very convenient I have to say. I will give paint tool sai a go then, thank you for your time.

Paint Tool Sai is a great Program specialy for anime and Comic drawing, i wounder if Paint Tool Sai 2 is already out . -.

Greetings

Edited by SenpaiArtorias
Link to comment
Share on other sites

9 hours ago, mranon245 said:

Thank you, I've tried doing the code but dress clothings don't give any sanity at all now and the game crashes when I wear a tam. Was I supposed to change something else that I forgot? 7e7fabb876.png

I still need help with this, don't know what to do.

 

1 hour ago, G said:

welp, wish ya good luck on your mod, eh? see ya's

 Thanks, cheers.

Link to comment
Share on other sites

9 hours ago, mranon245 said:

Thank you, I've tried doing the code but dress clothings don't give any sanity at all now and the game crashes when I wear a tam. Was I supposed to change something else that I forgot? 7e7fabb876.png

If you didn't add the engine.lua I linked it might be because you need to write GLOBAL.AllRecipes in line 48 instead of AllRecipes, GLOBAL.TUNING in line 49 instead of TUNING and GLOBAL.RECIPETABS.DRESS instead of RECIPETABS.DRESS in line 48. Again, I use it so I have never been arsed to learn globals.

If you have a crash go to:

  • C:\Users\(YOUR-USER)\Documents\Klei\DoNotStarveTogether\client_log.txt if you are hosting without caves through the client.
  • C:\Users\(YOUR-USER)\Documents\Klei\DoNotStarveTogether\Cluster_1\Master\server_log.txt and C:\Users\Javier\Documents\Klei\DoNotStarveTogether\Cluster_1\Caves\server_log.txt if hosting with caves through the client
  • And the same structure but wherever you have your dedicated server installed if you are running a dedicated server

and paste the log inside a spoiler or upload the file to the forums.

Also upload your entire mod along with it, so we can see the crash and fix it.

 

As for what the code did since I didn't explain that in the previous post:

local function sanityfn(inst) -- Defines the function with the arguments
	for k,v in pairs(inst.components.inventory.equipslots) do -- Loop through the equipslots table (see below)
		if AllRecipes[v.prefab].tab == RECIPETABS.DRESS then
			return TUNING.DAPPERNESS_SMALL -- Change this value after the "return " to change the sanity amount
		end -- Ends the if statement
	end -- Ends the for loop
	return 0 -- Returns 0 if nothing with that recipetab is found so it doesn't crash because of nil (nothing being returned)
end -- Ends the function

The for loop in that piece of code looks through the table equipslots, which is HEAD, BODY, HANDS, and some other things if you have something like the Extra Equip Slots mod installed, which shouldn't crash it.

Looping through that table will return 2 values which we have assigned to k and v (for k,v): the key of the value, and the value of the key in that position in the table, so it could for example return that k is HANDS and v is spear, or that k is BODY and v is armorwood.

Then with the if check it checks if in the AllRecipes table, for the recipe v.prefab, which would be the prefab of v, so for example "spear" or "armorwood" for the previous example, it's AllRecipes tab value is RECIPETABS.DRESS. If it is, it returns TUNING.DAPPERNESS.SMALL to the sanity component when this function is called to update the sanity rate of the character, similar to Willow's sanity near fire thing.

And then the function is assigned to the sanity component's custom_rate_fn:

inst.components.sanity.custom_rate_fn = sanityfn

 

Link to comment
Share on other sites

8 minutes ago, DrSmugleaf said:

If you didn't add the engine.lua I linked it might be because you need to write GLOBAL.AllRecipes in line 48 instead of AllRecipes, GLOBAL.TUNING in line 49 instead of TUNING and GLOBAL.RECIPETABS.DRESS instead of RECIPETABS.DRESS in line 48. Again, I use it so I have never been arsed to learn globals.

You only need the GLOBAL stuff for modmain.lua, with or without the "engine".

Link to comment
Share on other sites

the issue is that non recipe items crash the game i guess

if AllRecipes[v.prefab] and AllRecipes[v.prefab].tab == RECIPETABS.DRESS then

change it to this instead, and yes in the sanityfn

Edited by Aquaterion
Link to comment
Share on other sites

2 minutes ago, Aquaterion said:

Actually it does seem like an issue with walrus hat

That doesen't sound good. Still doesen't explain why I don't get any additional sanity at all though. Should I upload my mod?

Link to comment
Share on other sites

3 minutes ago, mranon245 said:

That doesen't sound good. Still doesen't explain why I don't get any additional sanity at all though. Should I upload my mod?

nah I edited the post, replace that 1 line with the new 1, in sanityfn, and it should work fine

Link to comment
Share on other sites

25 minutes ago, Aquaterion said:

nah I edited the post, replace that 1 line with the new 1, in sanityfn, and it should work fine

The good news is that the tam doesen't crash the game now but I'm still not getting any sanity from anything.

Link to comment
Share on other sites

1 hour ago, mranon245 said:

I'm still not getting any sanity from anything.

I used

local function sanityfn(inst)
	for k, v in pairs(inst.components.inventory.equipslots) do
		if AllRecipes[v.prefab] and AllRecipes[v.prefab].tab == RECIPETABS.DRESS then
			return TUNING.DAPPERNESS_SMALL
		end
	end
	return 0
end



local function master_postinit(inst)
	
	inst.components.sanity.custom_rate_fn = sanityfn

end

and it worked.

 

Items from the dress tab give some sanity, although it doesn't stack.

(It's the same to equip 1 or 3 items from the dress tab.)

 

If you are testing during dusk/night, then that sanityfn isn't enough to counteract the drain, so if may seem like it doesn't work.

Link to comment
Share on other sites

if you want it to work for each equipped item, replace the sanityfn with this;

local function sanityfn(inst)
	local dresscount = 0
	for k, v in pairs(inst.components.inventory.equipslots) do
		if AllRecipes[v.prefab] and AllRecipes[v.prefab].tab == RECIPETABS.DRESS then
			dresscount = dresscount + 1
		end
	end
	return TUNING.DAPPERNESS_MED * dresscount
end

 

Link to comment
Share on other sites

30 minutes ago, Aquaterion said:

if you want it to work for each equipped item, replace the sanityfn with this;


local function sanityfn(inst)
	local dresscount = 0
	for k, v in pairs(inst.components.inventory.equipslots) do
		if AllRecipes[v.prefab] and AllRecipes[v.prefab].tab == RECIPETABS.DRESS then
			dresscount = dresscount + 1
		end
	end
	return TUNING.DAPPERNESS_MED * dresscount
end

 

Amazing, works like a charm. It's a shame that a tophat and a tam give the same amount of sanity now though but I'm really happy with the code. Thank you so much.

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