This component makes your item armor, reducing all or certain types of damage dealt to the player. Sadly, this component also implies durability.
Component Armor Fields
Type | Name | Description |
---|---|---|
table | tags | contains strings; when "tags" is there, but no tag matches attackers (or weapons) tags, the armor doesn't do anything. |
function | ontakedamage | Fires when the armor is used. Args: inst, dmg_total, dmg_absorbed, dmg_leftover |
function | onfinished | Fires when the armor breaks. Args: none |
Component Armor Methods
Name | Parameter | Returns | Description |
---|---|---|---|
InitCondition | amount, absorb_percent | nil | how many hits the armor takes, and how well it protects. |
SetCondition | amount | nil | sets the current durability. |
Component Armor Events
Name | Data | Fires in/when... |
---|---|---|
percentusedchange | percent (current condition) | SetCondition (when the armor loads or takes damage) |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
local function ruinshat_proc(inst, owner) -- forcefield when hit inst:AddTag("forcefield") inst.components.armor:SetAbsorption(TUNING.FULL_ABSORPTION) [....] inst.components.armor.ontakedamage = function(inst, damage_amount) if owner then local sanity = owner.components.sanity if sanity then local unsaneness = damage_amount * TUNING.ARMOR_RUINSHAT_DMG_AS_SANITY sanity:DoDelta(-unsaneness, false) end end end inst.active = true owner:DoTaskInTime(TUNING.ARMOR_RUINSHAT_DURATION, function() [...] if inst:IsValid() then inst:RemoveTag("forcefield") inst.components.armor.ontakedamage = nil inst.components.armor:SetAbsorption(TUNING.ARMOR_RUINSHAT_ABSORPTION) owner:DoTaskInTime(TUNING.ARMOR_RUINSHAT_COOLDOWN, function() inst.active = false end) end end) end local function tryproc(inst, owner) if not inst.active and math.random() < TUNING.ARMOR_RUINSHAT_PROC_CHANCE then ruinshat_proc(inst, owner) end end local function ruins_onunequip(inst, owner) [...] owner:RemoveEventCallback("attacked", inst.procfn) end local function ruins_onequip(inst, owner) [....] inst.procfn = function() tryproc(inst, owner) end owner:ListenForEvent("attacked", inst.procfn) end local function ruins() local inst = simple() inst:AddComponent("armor") inst.components.armor:InitCondition(TUNING.ARMOR_RUINSHAT, TUNING.ARMOR_RUINSHAT_ABSORPTION) inst.components.equippable:SetOnEquip(ruins_onequip) inst.components.equippable:SetOnUnequip(ruins_onunequip) return inst end |