Jump to content

Gain sanity during day, and gain sanity on kill


Recommended Posts

I'm struggling on making the player get a sanity boost during the day, and when he kills any monsters or creatures, please help, been stuck for hours and tried putting in code from other topics but just doesn't work. 

 

Also, I literally have no idea what I'm doing with the code so if you could specify exactly where to put the code, that would be super, thanks!

Link to comment
Share on other sites

From (I believe rezecib's?) mod for vanilla characters, Wigfrid:

 

 

To get sanity on kill

In your character prefab:

local function onkill(inst, data)	if data.afflicter == inst 		and not data.inst:HasTag("prey") 		and not data.inst:HasTag("veggie") 		and not data.inst:HasTag("structure") then		local delta = (data.inst.components.combat.defaultdamage) * 0.25 		if data.inst:HasTag("player") then delta = TUNING.WILSON_HEALTH * 0.15 end		inst.components.health:DoDelta(delta, false, "battleborn")        inst.components.sanity:DoDelta(delta)        if math.random() < .1 and not data.inst.components.health.nofadeout then        	local time = data.inst.components.health.destroytime or 2        	inst:DoTaskInTime(time, function()        		local s = medScale        		if data.inst:HasTag("smallcreature") then        			s = smallScale    			elseif data.inst:HasTag("largecreature") then    				s = largeScale    			end        		local fx = SpawnPrefab("wathgrithr_spirit")        		fx.Transform:SetPosition(data.inst:GetPosition():Get())        		fx.Transform:SetScale(s,s,s)    		end)        end	endend

 

 

In your character's prefab master_postinit

inst:ListenForEvent("entity_death", function(wrld, data) onkill(inst, data) end, TheWorld)
From thana:

 

 

To gain sanity during the day

In your character's prefab master_postinit

inst.components.sanity.dapperness = TUNING.DAPPERNESS_MED * (1.2)
Basically just adds a passive regen. Increase the night_drain_mult if you want it to counteract during the night:

inst.components.sanity.night_drain_mult = 1.55
Edited by DrSmugleaf
Link to comment
Share on other sites

You fuc­ked up the comment, it should have 2 lines like --.

local function onkill(inst, data)    if data.afflicter == inst     and not data.inst:HasTag("prey")     and not data.inst:HasTag("veggie")     and not data.inst:HasTag("structure") then       local delta = (data.inst.components.combat.defaultdamage) * 0.25       if data.inst:HasTag("player") then           delta = TUNING.WILSON_HEALTH * 0.15        end       inst.components.health:DoDelta(delta, false, "battleborn")       inst.components.sanity:DoDelta(delta)    endend

is the function you want, and don't change "player" to "wrex".

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