Jump to content

Recommended Posts

Let's say I want my character to passively absorb an amount of damage taken (let's say 25%) and deal the absorbed damage to the hunger bar.

Here's an example:

A source attacks my character for 40 base damage.

My character loses 30 Health and 10 Hunger.

Since Night Armor has a similar effect I don't think it should be too hard, but I have no experience in LUA, so I'm asking for help.

Any ideas on how to code it?

@jimmosio, the best way to learn about how a certain item works would be to look in its code.

 

In this case, "..\scripts\prefabs\armor_sanity.lua"

 

The following parts are relevant to what you need (copied from armor_sanity.lua).

local function OnTakeDamage(inst, damage_amount, absorbed, leftover)	local owner = inst.components.inventoryitem.owner	if owner then		local sanity = owner.components.sanity		if sanity then			local unsaneness = damage_amount * TUNING.ARMOR_SANITY_DMG_AS_SANITY			sanity:DoDelta(-unsaneness, false)		end	endendlocal function fn(Sim)	local inst = CreateEntity()	-- ...	inst:AddComponent("armor")	inst.components.armor:InitCondition(TUNING.ARMOR_SANITY, TUNING.ARMOR_SANITY_ABSORPTION)	inst.components.armor.ontakedamage = OnTakeDamage	-- ...	return instend

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