Danielance Posted November 4, 2017 Share Posted November 4, 2017 So far i've been trying to add a hat exclusive damage multiplier, but it's not working so far. I've tried adding "inst.components.combat.damagemultiplier = 1.2" into the "OnEquip" and "OnUnequip" area (lines 21 and 38), but that crashes the game (nil value). This is how the .lua file's looking so far... local assets= { Asset("ANIM", "anim/brewinghat.zip"), Asset("ANIM", "anim/brewinghat_swap.zip"), Asset("ATLAS", "images/inventoryimages/brewinghat.xml"), Asset("IMAGE", "images/inventoryimages/brewinghat.tex"), } local prefabs = { } local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_hat", "brewinghat", "swap_hat") if inst.components.fueled then inst.components.fueled:StartConsuming() end inst.components.combat.damagemultiplier = 1.2 owner.AnimState:Show("HAT") owner.AnimState:Show("HAT_HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAT") end end local function OnUnequip(inst, owner) if inst.components.fueled then inst.components.fueled:StopConsuming() end inst.components.combat.damagemultiplier = 1 owner.AnimState:Hide("HAT") owner.AnimState:Hide("HAT_HAIR") owner.AnimState:Show("HAIR_NOHAT") owner.AnimState:Show("HAIR") if owner:HasTag("player") then owner.AnimState:Show("HEAD") owner.AnimState:Hide("HEAD_HAT") end end local function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst:AddTag("hat") if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst.AnimState:SetBank("brewinghat") inst.AnimState:SetBuild("brewinghat") inst.AnimState:PlayAnimation("idle") MakeHauntableLaunch(inst) inst:AddComponent("inspectable") inst:AddComponent("waterproofer") inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL) inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "brewinghat" inst.components.inventoryitem.atlasname = "images/inventoryimages/brewinghat.xml" inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.HEAD inst.components.equippable:SetOnEquip( OnEquip ) inst.components.equippable:SetOnUnequip( OnUnequip ) inst:AddComponent("fueled") inst.components.fueled.fueltype = FUELTYPE.USAGE inst.components.fueled:InitializeFuelLevel(TUNING.TOPHAT_PERISHTIME * 0.25) inst.components.fueled:SetDepletedFn(inst.Remove) return inst end return Prefab("common/inventory/brewinghat", fn, assets, prefabs) Any help is appreciated, and sorry in advance if the answer is obvious. Quote Link to comment Share on other sites More sharing options...
Lumina Posted November 4, 2017 Share Posted November 4, 2017 Not sure but maybe the damage should be for the owner, not the inst. Also, not sure again, but if the character has already a custom value, he/she will have a new value of 1 hour ago, Danielance said: inst.components.combat.damagemultiplier = 1 after removing the hat. I think this topic discuss about this subject, maybe you can find clues in it. Link to comment Share on other sites More sharing options...
Serpens Posted November 4, 2017 Share Posted November 4, 2017 (edited) yes, as lumina sad, "owner" is the player, while inst is the hat. And "damagemultiplier" does only exist for players. In addtion to that, you should not change damagemultipler for players during a game. Use the solution lumina linked instead. Because just imagine another mod that does the same like yours, except with an armor instead of a hat. Unequipping the hat would set damagemultiplier to 1, but what about the armor that is still equipped? And equipping both would set it both times to 1.2, while it should be higher when both are equipped. so instead of changing the damagemultiplier, you should add this code in modmain: --*****************************************************************************************************************************************-- ------------------------------------------------- Combat Component Adjustments by ZupaleX -------------------------------------------------------------- -------------------------------------------------------- to add/remove damagemodifier ------------------------------------------------- --*****************************************************************************************************************************************-- local function AddDamageModifier(self, key, mod) self.attack_damage_modifiers[key] = mod end local function RemoveDamageModifier(self, key) self.attack_damage_modifiers[key] = nil end local function GetDamageModifier(self) local mod = 1 for k,v in pairs(self.attack_damage_modifiers) do mod = mod * v end return mod end local function RegisterNewCombatMembers(self) self.attack_damage_modifiers = {} -- % modifiers on self:CalcDamage() self.AddDamageModifier = AddDamageModifier self.RemoveDamageModifier = RemoveDamageModifier self.GetDamageModifier = GetDamageModifier end AddComponentPostInit("combat", function(self) if self.attack_damage_modifiers == nil then -- check if another mod already added this. cause we should not add this twice RegisterNewCombatMembers(self) local CalcDamageOld = self.CalcDamage self.CalcDamage = function(self, target, weapon, multiplier) local dmg = CalcDamageOld(self, target, weapon, multiplier) local bonus = self.damagebonus or 0 --not affected by multipliers return (dmg-bonus) * self:GetDamageModifier() + bonus end end end ) then you can use in your OnEquip function: owner.components.combat:AddDamageModifier("brewinghatbonus",1.2) -- multiplies the damage with 1.2 and in your OnUnequip function: owner.components.combat.RemoveDamageModifier("brewinghatbonus") -- remove the bons and only this bonus, no other boni. Edited December 10, 2017 by Serpens Link to comment Share on other sites More sharing options...
Danielance Posted November 28, 2017 Author Share Posted November 28, 2017 On 11/4/2017 at 3:44 PM, Serpens said: yes, as lumina sad, "owner" is the player, while inst is the hat. And "damagemultiplier" does only exist for players. In addtion to that, you should not change damagemultipler for players during a game. Use the solution lumina linked instead. Because just imagine another mod that does the same like yours, except with an armor instead of a hat. Unequipping the hat would set damagemultiplier to 1, but what about the armor that is still equipped? And equipping both would set it both times to 1.2, while it should be higher when both are equipped. so instead of changing the damagemultiplier, you should add this code in modmain: --*****************************************************************************************************************************************-- ------------------------------------------------- Combat Component Adjustments by ZupaleX -------------------------------------------------------------- -------------------------------------------------------- to add/remove damagemodifier ------------------------------------------------- --*****************************************************************************************************************************************-- local function AddDamageModifier(self, key, mod) self.attack_damage_modifiers[key] = mod end local function RemoveDamageModifier(self, key) self.attack_damage_modifiers[key] = nil end local function GetDamageModifier(self) local mod = 1 for k,v in pairs(self.attack_damage_modifiers) do mod = mod + v end return mod end local function RegisterNewCombatMembers(self) self.attack_damage_modifiers = {} -- % modifiers on self:CalcDamage() self.AddDamageModifier = AddDamageModifier self.RemoveDamageModifier = RemoveDamageModifier self.GetDamageModifier = GetDamageModifier end AddComponentPostInit("combat", function(self) if self.attack_damage_modifiers == nil then -- check if another mod already added this. cause we should not add this twice RegisterNewCombatMembers(self) local CalcDamageOld = self.CalcDamage self.CalcDamage = function(self, target, weapon, multiplier) local dmg = CalcDamageOld(self, target, weapon, multiplier) local bonus = self.damagebonus or 0 --not affected by multipliers return (dmg-bonus) * self:GetDamageModifier() + bonus end end end ) then you can use in your OnEquip function: owner.components.combat:AddDamageModifier("brewinghatbonus",1.2) -- multiplies the damage with 1.2 and in your OnUnequip function: owner.components.combat.RemoveDamageModifier("brewinghatbonus") -- remove the bons and only this bonus, no other boni. Hello, sorry for the incredibly late reply. I've added the code to the modmain, equip, and unequip as intended, but when i unequip the hat, I crash and this is what I get. On the bright side, the damage multiplier works. here is the .lua so far brewinghat.lua thanks for helping though Heads up, I also added a different perk to the same hat before I noticed this, where hunger decays slower. Link to comment Share on other sites More sharing options...
Serpens Posted November 28, 2017 Share Posted November 28, 2017 (edited) please also upload your modmain. Only explanation is that there is something wrong. Also in the code I posted could be a bug, but at the moment I see no bug in it. Edited November 28, 2017 by Serpens Link to comment Share on other sites More sharing options...
Danielance Posted November 29, 2017 Author Share Posted November 29, 2017 modmain.lua Link to comment Share on other sites More sharing options...
Serpens Posted December 10, 2017 Share Posted December 10, 2017 ok, in modmain is no error, but I now see it: owner.components.combat.RemoveDamageModifier("brewinghatbonus") You need a ":" before the "Remove.." so it is: owner.components.combat:RemoveDamageModifier("brewinghatbonus") In addition to that, better change local function GetDamageModifier(self) local mod = 1 for k,v in pairs(self.attack_damage_modifiers) do mod = mod + v end return mod end to: local function GetDamageModifier(self) local mod = 1 for k,v in pairs(self.attack_damage_modifiers) do mod = mod * v end return mod end because then it is really a "multiplier". Link to comment Share on other sites More sharing options...
Danielance Posted December 19, 2017 Author Share Posted December 19, 2017 It worked! thanks for all your help. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now