Jump to content

Recommended Posts

Hi everyone! I'm new to modding this game, so forgive me if I don't understand a lot yet. :D

Would it be possible to make a character passively gain or lose hunger depending on light levels? So, for example, on a sunny day they would gain hunger the fastest, on a cloudy/rainy/snowy day there would be less of a gain, at dusk there would be a slight hunger loss, and at night in complete darkness they would be at risk of starving. I'd also like food to be much less filling as a result, and for light sources to help restore hunger.

Thanks in advance for any help!

Edited by Adipup

For 

Quote

passively gain or lose hunger depending on light levels? So, for example, on a sunny day they would gain hunger the fastest, on a cloudy/rainy/snowy day there would be less of a gain, at dusk there would be a slight hunger loss, and at night in complete darkness they would be at risk of starving

add this: ((inside master_postinit) (in your [charactername].lua (mod->scripts->prefabs->...))

local function gluttony(inst)
	--NIGHT
	if TheWorld.state.isnight then  
		inst.components.hunger.hungerrate = 7.5 * TUNING.WILSON_HUNGER_RATE
	end
	
	--DUSK
	if TheWorld.state.isdusk then 
		inst.components.hunger.hungerrate = 3 * TUNING.WILSON_HUNGER_RATE
	end
	
	--DAY
	if TheWorld.state.isday then 
		inst.components.hunger.hungerrate = -2 * TUNING.WILSON_HUNGER_RATE		
	end
	
	--SUNNY DAY
	if TheWorld.state.issummer and TheWorld.state.isday then 
		inst.components.hunger.hungerrate = -3 * TUNING.WILSON_HUNGER_RATE	
	end
	
	---SNOWY DAY
	if TheWorld.state.issnowing and TheWorld.state.isday then 
		inst.components.hunger.hungerrate = -1.5 * TUNING.WILSON_HUNGER_RATE
	end
	
	--RAINY DAY
	if TheWorld.state.israining and TheWorld.state.isday then 
		inst.components.hunger.hungerrate = -1.5 * TUNING.WILSON_HUNGER_RATE
	end

end

and for:

Quote

light sources to help restore hunger.

this:

local function sootinglight(inst)
	local x,y,z = inst.Transform:GetWorldPosition()
	local range = 4 -- HUNGER RESTORATION RANGE
	local tags = { "lighter", "campfire", "lamp" }
	local lightsources = TheSim:FindEntities(x,y,z, range, nil, nil, tags)
	
	for k,v in pairs(lightsources) do
		inst.components.hunger:DoDelta(1,1) -- +1 HUNGER
	end
end

You will also need

inst:DoPeriodicTask(15, gluttony, nil, inst)  
inst:DoPeriodicTask(1.5, sootinglight, nil, inst)  -- TIME INTERVALS BETWEEN +1 HUNGER EVENTS

under those functions above.

Second function works with: campfires, torch, willow's lighter, mushlight, glowcap.

I suck at lua and logical thinking :D  , but it should work... at least until someone competent will show up.
Cheers!

Edited by Yakuzashi
  • Like 2

Thank you so much! I had to tweak the multipliers a bit to get it right where I wanted it, but this works like a charm. :D

Do you perhaps also know how to make it so that all hunger gained from food is (for example) halved, but the character still gains all the health from it?

  • Like 1
if inst.components.eater ~= nil then
    --inst.components.eater:SetAbsorptionModifiers(Health, Hunger, Sanity)
    inst.components.eater:SetAbsorptionModifiers(1, 0.5, 1)
end

your boi wortox got this figured out
they use them in a decimal percentage e.g 0.5 equals 50%

Edited by thomas4846
  • Like 2

Thank you! Didn't realize it was going to be that simple.

There's one more thing I want to do with this character, but I feel like it would take a lot more than a few lines of code. I want them to spawn with a custom weapon that behaves like a whip, but with custom sprites (drawn by me) and infinite durability. I found a tutorial on how to make a custom weapon, but that only seems to cover ones that behave like swords. :confused:

I have made template for custom weapons: https://forums.kleientertainment.com/forums/topic/115694-templatetutorial-custom-crafting-tab-and-items/

You need to compare weapon.lua from template with whip.lua from DST and decide what to change.

You can take whip.zip and decompile it with ktools (I have done that it's in .rar format in attachments, just in case you don't know how to do it) and modify acquired sprites.

whip.rar

  • Like 2

I'm trying to follow your template, but I can't really figure it out. The whip item seems a lot different to a normal weapon (it only has one .scml file instead of two as an example found the other zip and converted it with krane, but I'm still having issues). Would you mind if I send you my mod so you can take a look at it and maybe tell me where I went wrong?

Edited by Adipup
11 hours ago, Adipup said:

I'm trying to follow your template, but I can't really figure it out. The whip item seems a lot different to a normal weapon (it only has one .scml file instead of two as an example found the other zip and converted it with krane, but I'm still having issues). Would you mind if I send you my mod so you can take a look at it and maybe tell me where I went wrong?

Ok, send it.

6 minutes ago, Yakuzashi said:

Ok, send it.

 I think it's working now, actually! :D I just forgot to include this bit in the weapon's lua file:

inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "weapon"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/weapon.xml"

Thanks for all your help!

@Yakuzashi @thomas4846

My character is up on the Steam workshop now if you want to see: https://steamcommunity.com/sharedfiles/filedetails/?id=2272337557

Couldn't have done much of this without you, so thanks again!

  • Like 3

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