Jump to content

Recommended Posts

local innocents = {	rabbit = true,	crow = true,	robin = true,	robin_winter = true}AddPrefabPostInitAny(function(inst)	if inst and innocents[inst.prefab] and inst.components.inventoryitem then		inst.wasininventory = false		local old1 = inst.components.inventoryitem.ondropfn		local old2 = inst.components.inventoryitem.onputininventoryfn		inst.components.inventoryitem:SetOnDroppedFn(function(inst)			if old1 then				old1(inst)			end			inst.wasininventory = false		end)		inst.components.inventoryitem:SetOnPutInInventoryFn(function(inst)			if old2 then				old2(inst)			end			inst.wasininventory = true		end)	endend)AddPrefabPostInit("MyCharacter", function(inst)	inst:ListenForEvent("killed", function(inst, data)		if data and data.victim and innocents[data.victim.prefab] then			if not data.victim.wasininventory and inst.components.sanity then				inst.components.sanity:DoDelta(-15)			end		end	end)end)

In modmain.lua, replace MyCharacter for your character's name.

 

You can try to implement parts of this inside your character's lua file.

 

This takes sanity away from you when what you kill is not in your inventory.

This was tricky because if you check for owner after the push event, the owner is nil because the creature is dead, and the only argument given is victim.

I looked at the combat component and noticed other things I could use.

local innocents = {    rabbit = true,    crow = true,    robin = true,    robin_winter = true}AddPrefabPostInit("MyCharacter", function(inst)	inst.components.combat.onhitotherfn = function(attacker, target, damage)		if innocents[target.prefab] and attacker.components.sanity then			if target.components.health and target.components.health:IsDead() then				attacker.components.sanity:DoDelta(-15)			end		end	endend)

This is more simple. And it affects things you kill without using the "Murder" option in the inventory.

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