Jump to content

I want to make a "hunger shield" for a character. How can I do that?


jimmosio

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?

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...