Jump to content

[HELP] Immunity to Charlie's hits?


Recommended Posts

Hello everyone! I am beginner programmer. So I would like to create a little mod as a gift to my brother. The character, I would like to create, has specific perks. Maybe you can help me with them...?

 

The main problem for me is to make immunity to Charlie's hits in the darkness. I looked through some custom characters and I saw that they had solved this problem via creating a light around their characters. Is making a little light around my character the only way to solve this problem? If not, can you send me a code of alternative solution and explain it, please? 

And one more perk I would like to make for my character is... When he is near the fire during night he loses his sanity f.e. three times faster.

 

Thank you for attention. Hope for soon answer~

Link to comment
Share on other sites

For immunity to charlie, In your character.lua master_postinit:

inst.components.grue:AddImmunity()

For losing sanity near a fire at night, in your character.lua:

local function sanityfn(inst)	if TheWorld.state.isnight() then		local x, y, z = inst.Transform:GetWorldPosition() 		local delta = 0		local max_rad = 10		local ents = TheSim:FindEntities(x, y, z, max_rad, { "fire" })		for i, v in ipairs(ents) do			if v.components.burnable ~= nil and v.components.burnable:IsBurning() then				local rad = v.components.burnable:GetLargestLightRadius() or 1				local sz = TUNING.SANITY_NIGHT_MID * 3 * math.min(max_rad, rad) / max_rad				local distsq = inst:GetDistanceSqToInst(v) - 9				-- shift the value so that a distance of 3 is the minimum				delta = delta + sz / math.max(1, distsq)			end		end		return delta	endend

In your character.lua master_postinit:

inst.components.sanity.custom_rate_fn = sanityfn
Link to comment
Share on other sites

@WingedHarbinger:

local function sanityfn(inst)    if TheWorld.state.isnight then        local x, y, z = inst.Transform:GetWorldPosition()         local mult = 0        local max_rad = 10		local a = -2/91		local b = 200/91        local ents = TheSim:FindEntities(x, y, z, max_rad, { "fire" })        for i, v in ipairs(ents) do            if v.components.burnable ~= nil and v.components.burnable:IsBurning() then                local distsq = inst:GetDistanceSqToInst(v)				distsq = math.max(9, distsq)                mult = mult + (a*distsq + b)            end        end        return -(mult*inst.components.sanity.rate)    end	return 0end
Link to comment
Share on other sites

Is making a little light around my character the only way to solve this problem?

 

Allow me to clarify that pretty much everything in this game can be modded however modders please.  Some modders just get 1 simple thing for their character then stick with it.  Other modders will look into another mod's code and just copy-paste what they saw.  But modders that know how everything works can do much much more.

 

Let me try to give an example of the scale, with my current experience I believe I could create a don't starve representation of the classic street fighter 2, everything from the side angled camera, the controls, the jumping, the special moves, all the way to even putting in the sound effects and sprites from the original game.  Granted outside of showing that I can, I wouldn't do that because that would be an excessive amount of work.

 

 

But if you ever think "Man I'd love to do that, but I don't think I can so I guess i'll try a workaround instead" ask us on the forum first.  Chances are what you think is impossible, is actually super easy to do.  And even if it isn't, it's probably still doable with a little bit of time and effort.  

 

And if your not sure how you would code in a feature, just describe how you want something done, we probably know a really clever way to implement it.

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