Jump to content

Character Insanity Mod Help!


Recommended Posts

Hello everyone! I might want to skip to the point here, I'm making a character based on myself and I wanted to do some buffs for him involving Insanity and the like. I'll just post the perks that I currently have for him here:

1. Hates Spoilage - Caleb (My Character) will refuse to eat anything that is below the stale ranking of food, and will not eat rot either.

2. Benefits From Insanity - I'm planning that my character will get a health and damage boost when he starts to go insane. However to counteract this, he might slow down a bit.

3. Healthy but Hungry - Um, self explanatory?

Stats are as follows

Health (By default) - 200

Hunger - 100

Sanity - 150

I haven't done much to change his character besides adding quotes for him, hit me up if you have a guide to adding those perks in though! I would really love the help! :wilson_love:

Link to comment
Share on other sites

Welcome to the world of DS / DST modding :D

How proficient are you at coding Lua? If you are completely new, you should look through the newcomer post and at the very least do the Lua Crash Course and read the tips in the newcomer post. That'll avoid many headaches while trying to help you do these things.

1 is not difficult. For 2, I think we'll need more specifics. Coding is a very precise artform, so we need to know exactly what you want. I'm guessing you've already done 3?

Link to comment
Share on other sites

2 hours ago, Ultroman said:

Welcome to the world of DS / DST modding :D

How proficient are you at coding Lua? If you are completely new, you should look through the newcomer post and at the very least do the Lua Crash Course and read the tips in the newcomer post. That'll avoid many headaches while trying to help you do these things.

1 is not difficult. For 2, I think we'll need more specifics. Coding is a very precise artform, so we need to know exactly what you want. I'm guessing you've already done 3?

Alright, thank you for posting that link here. Anyways, let me list specifics, and yes, I have done 3.

2. I'm planning on Caleb to start to get his buffs when the shadow monsters start to attack him like a 5-10% (7% maybe so we don't go crazy

) increase to health and a 25% increase to damage, and maybe slow him down about 10%.

Link to comment
Share on other sites

To do this kind of thing, in the past I would have used ListenForEvent to listen for any changes in the sanity (the sanitydelta" event), but since that event is fired any time a sanity change is applied, it is actually fired every single frame during dusk and night and when you're close to monsters with a negative sanity aura. Instead, I'd make it a task which handles all of this, that only runs every 0.5 to 1.0 seconds. In the template below, it runs every 0.5 seconds.

Here is a template for a buff that activates and deactivates around 7% sanity. If anyone else finds this and wants their buff to activate due to other factors, it's as easy as changing the two if-statements at the bottom.

inst.mybuffisapplied = false

local applybuff = function(inst)
	-- Apply all your buff stuff here
end

local removebuff = function(inst)
	-- Remove all your buff stuff here
end

inst:DoPeriodicTask(0.5, function(inst)
	if inst == nil or not inst:IsValid() or inst.components.health:IsDead() then
		-- If the player instance is invalid or they're dead, then we don't want to do anything.
		return
	end
	
	-- If our buff is applied and our measurements say it should not be applied anymore, we remove it.
	-- Else, if our buff is not applied and our measurements say it should be, we apply it.
	if inst.mybuffisapplied and inst.components.sanity:GetPercentWithPenalty() > 0.07 then
		removebuff(inst)
	elseif not inst.mybuffisapplied and inst.components.sanity:GetPercentWithPenalty() <= 0.07 then
		applybuff(inst)
	end
end)


Now for the things you can put in the applybuff and removebuff functions.

Change Movement Speed

-- Add +20% speed boost in all situations
inst.components.locomotor:SetExternalSpeedMultiplier(inst, "myuniquemodifierkey", 1.20)

To remove it again, remove the multiplier.

-- Remove speed bonus.
inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "myuniquemodifierkey")

Change Max Health

-- Store the current maxhealth in a variable.
inst.normalmaxhealth = inst.components.health.maxhealth
-- Add 50 to max health
inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 50)
-- Changing the max health does not change the current health.
-- If you want to give the character the extra health immediately, do the following.
inst.components.health:DoDelta(50, false)

To remove it again, reset the max health back to normal.

-- Set the max health back to normal, using the value we stored above.
inst.components.health:SetMaxHealth(inst.normalmaxhealth)

Add a damage modifier

-- Add 10% damage bonus.
inst.components.combat.externaldamagemultipliers:SetModifier(inst, 1.10, "myuniquemodifierkey")

To remove it again, remove the modifier.

-- Remove damage bonus.
inst.components.combat.externaldamagemultipliers:RemoveModifier(inst, "myuniquemodifierkey")

Substitute myuniquemodifierkey with a unique modifer key (a string) of your own.

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