RexySeven Posted May 23, 2023 Share Posted May 23, 2023 Hello again! I need help fixing the problem with weapon not depleting it's damage after 5 seconds if not attacking anything It should revert back to it's original 35 damage with maximum of 120 Although part with it gaining 5 damage each hit is working fine but the one with depletion is not local assets = { Asset("ANIM", "anim/vegie_sword.zip"), Asset("ANIM", "anim/swap_vegie_sword.zip"), Asset("ATLAS", "images/inventoryimages/vegie_sword.xml"), Asset("IMAGE", "images/inventoryimages/vegie_sword.tex"), } local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_vegiepick", "swap_vegiepick") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") end local function onunequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") end local function onhit(inst, attacker, target) if attacker and attacker.components.combat and target then inst.components.weapon.damage = inst.components.weapon.damage + 5 if inst.components.weapon.damage > 120 then inst.components.weapon.damage = 120 end end end local function ondeplete(inst) inst.components.timer:StartTimer("deplete_timer", 5) inst:ListenForEvent("timerdone", function(inst, data) if data.name == "deplete_timer" then if not inst.components.weapon:IsBusy() then inst.components.weapon.damage = inst.components.weapon.damage - 5 if inst.components.weapon.damage < 35 then inst.components.weapon.damage = 35 end inst.components.timer:StartTimer("deplete_timer", 5) end end end) end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("vegie_sword") inst.AnimState:SetBuild("vegie_sword") inst.AnimState:PlayAnimation("idle") inst:AddTag("weapon") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("weapon") inst.components.weapon:SetDamage(35) inst.components.weapon:SetOnAttack(onhit) inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "vegie_sword" inst.components.inventoryitem.atlasname = "images/inventoryimages/vegie_sword.xml" inst:AddComponent("equippable") inst.components.equippable:SetOnEquip(function(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_vegie_sword", "swap_vegie_sword") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") end) inst.components.equippable:SetOnUnequip(function(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") end) inst:AddComponent("timer") inst:ListenForEvent("ondeplete", ondeplete) inst:AddComponent("equippable") inst.components.equippable:SetOnEquip(onequip) inst.components.equippable:SetOnUnequip(onunequip) return inst end return Prefab("vegie_sword", fn, assets) I be glad if someone could help! Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/ Share on other sites More sharing options...
Rickzzs Posted May 23, 2023 Share Posted May 23, 2023 I think there is not an event called "ondeplete", you can just start the timer on attack. Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1636379 Share on other sites More sharing options...
RexySeven Posted May 23, 2023 Author Share Posted May 23, 2023 1 hour ago, Rickzzs said: I think there is not an event called "ondeplete", you can just start the timer on attack. How do I do that? :0 Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1636403 Share on other sites More sharing options...
Rickzzs Posted May 24, 2023 Share Posted May 24, 2023 You can always listen for a timer and reset its time when attack. local function fn() ... inst:ListenForEvent("timerdone", function(inst, data)...end) end and local function onhit(inst, attacker, target) ... if inst.components.timer:TimerExists("ondeplete") then inst.components.timer:SetTimeLeft(5) else inst.components.timer:StartTimer("ondeplete",5) end end Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1636502 Share on other sites More sharing options...
RexySeven Posted May 26, 2023 Author Share Posted May 26, 2023 On 5/24/2023 at 8:36 AM, Rickzzs said: You can always listen for a timer and reset its time when attack. local function fn() ... inst:ListenForEvent("timerdone", function(inst, data)...end) end and local function onhit(inst, attacker, target) ... if inst.components.timer:TimerExists("ondeplete") then inst.components.timer:SetTimeLeft(5) else inst.components.timer:StartTimer("ondeplete",5) end end Like this? local function onhit(inst, attacker, target) if attacker and attacker.components.combat and target then inst.components.weapon.damage = inst.components.weapon.damage + 5 if inst.components.weapon.damage > 120 then inst.components.weapon.damage = 120 if inst.components.timer:TimerExists("ondeplete") then inst.components.timer:SetTimeLeft(5) else inst.components.timer:StartTimer("ondeplete",5) end end Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1636880 Share on other sites More sharing options...
Rickzzs Posted May 27, 2023 Share Posted May 27, 2023 vegiebat.luabased on your current release. Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1636964 Share on other sites More sharing options...
RexySeven Posted May 27, 2023 Author Share Posted May 27, 2023 (edited) 2 hours ago, Rickzzs said: vegiebat.luabased on your current release. Getting crash and ":33: attempt to index field 'component' (a nil value)" error when attacking something with this weapon using code you attached master_server_log.txt vegie_sword.lua Edited May 27, 2023 by RexySeven Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1636970 Share on other sites More sharing options...
Rickzzs Posted May 27, 2023 Share Posted May 27, 2023 6 hours ago, RexySeven said: Getting crash and ":33: attempt to index field 'component' (a nil value)" error when attacking something with this weapon using code you attached master_server_log.txt 82.28 kB · 0 downloads vegie_sword.lua 2.94 kB · 0 downloads You can just fix it yourself.. 1 Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1636990 Share on other sites More sharing options...
RexySeven Posted May 27, 2023 Author Share Posted May 27, 2023 2 hours ago, Rickzzs said: You can just fix it yourself.. I wish I could But I'll try again bit later I'm a complete newbie in this and really hard for me getting around fixing those kind of errors because I don't know what this error is referring to. I guess it needs a damage value? But there is weapon component and "set damage" in local function fn Thank you so much for providing me a sample of code thought, I really appreciate that! Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1637015 Share on other sites More sharing options...
Hornete Posted May 27, 2023 Share Posted May 27, 2023 55 minutes ago, RexySeven said: I wish I could But I'll try again bit later I'm a complete newbie in this and really hard for me getting around fixing those kind of errors because I don't know what this error is referring to. I guess it needs a damage value? But there is weapon component and "set damage" in local function fn Thank you so much for providing me a sample of code thought, I really appreciate that! You wrote 'component' when it should be 'components'. Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1637020 Share on other sites More sharing options...
RexySeven Posted May 27, 2023 Author Share Posted May 27, 2023 27 minutes ago, Hornete said: You wrote 'component' when it should be 'components'. Well........ Okay, it works now XD You now can put the "donkey" sign on me Link to comment https://forums.kleientertainment.com/forums/topic/147932-problem-making-weapon-losing-it-damage-overtime/#findComment-1637024 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