Kyrogeniz Posted February 17, 2018 Share Posted February 17, 2018 (edited) Hey guys! So, I'm trying to enable my weapon the ability to set enemies on fire when hit. I thought I had an idea to go about it, but it doesn't seem to work in-game. Here's my code, including the other function I think may be conflicting with it: local function onattack_defiance(inst, attacker, victim) if victim ~= nil then local onepercent = inst.components.finiteuses.total / 100 if (inst.components.finiteuses.current) <= inst.components.finiteuses.total then inst.components.finiteuses:Use(2) elseif (inst.components.finiteuses.current) == inst.components.finiteuses.total then inst.components.finiteuses:Use(-onepercent) end end local function onattack(weapon, attacker, victim) if victim ~= nil and victim.components.burnable ~= nil and math.random() < TUNING.TORCH_ATTACK_IGNITE_PERCENT * victim.components.burnable.flammability then victim.components.burnable:Ignite(nil, attacker) end end Any idea what's going wrong? Edited February 17, 2018 by Kyrogeniz Link to comment https://forums.kleientertainment.com/forums/topic/87744-coding-help-weapon-to-ignite-enemies/ Share on other sites More sharing options...
Aquaterion Posted February 17, 2018 Share Posted February 17, 2018 when are you calling these functions? Link to comment https://forums.kleientertainment.com/forums/topic/87744-coding-help-weapon-to-ignite-enemies/#findComment-1005609 Share on other sites More sharing options...
Kyrogeniz Posted February 17, 2018 Author Share Posted February 17, 2018 So they're being called inside of the weapon's .lua within the local function MakeSword, like this (full code): Quote local function MakeSword(defiance, damage) local assets = { Asset("ANIM", "anim/defiance.zip"), Asset("ANIM", "anim/swap_defiance.zip"), Asset("IMAGE", "images/inventoryimages/defiance.tex"), Asset("ATLAS", "images/inventoryimages/defiance.xml"), } local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_defiance", "swap_defiance") 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 onattack_defiance(inst, attacker, victim) if victim ~= nil then local onepercent = inst.components.finiteuses.total / 100 if (inst.components.finiteuses.current) <= inst.components.finiteuses.total then inst.components.finiteuses:Use(2) elseif (inst.components.finiteuses.current) == inst.components.finiteuses.total then inst.components.finiteuses:Use(-onepercent) end end local function onattack(weapon, attacker, target) if target ~= nil and target.components.burnable ~= nil and math.random() < TUNING.TORCH_ATTACK_IGNITE_PERCENT * target.components.burnable.flammability then target.components.burnable:Ignite(nil, attacker) end end if attacker and attacker.components.hunger then attacker.components.hunger:DoDelta(2) end end local function DoNothingNow(inst) end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("defiance") inst.AnimState:SetBuild("defiance") inst.AnimState:PlayAnimation("idle") inst.entity:SetPristine() inst:AddTag("sharp") if not TheWorld.ismastersim then return inst end inst:AddComponent("finiteuses") inst.components.finiteuses:SetOnFinished(inst.Remove) inst:AddComponent("weapon") inst.components.weapon:SetDamage(62) --the code is used to set damage inst.components.weapon:SetAttackCallback(onattack_defiance) inst:AddComponent("tool") inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/defiance.xml" inst.components.inventoryitem.imagename = "defiance" inst:AddComponent("equippable") inst.components.equippable:SetOnEquip(onequip) inst.components.equippable:SetOnUnequip(onunequip) inst.invdropquote = "Putting it back down!" MakeHauntableLaunch(inst) return inst end return Prefab( "common/inventory/defiance", fn, assets) end return MakeSword("defiance",20) Link to comment https://forums.kleientertainment.com/forums/topic/87744-coding-help-weapon-to-ignite-enemies/#findComment-1005620 Share on other sites More sharing options...
Kyrogeniz Posted February 18, 2018 Author Share Posted February 18, 2018 (edited) I've figured it out; I didn't properly declare it on-attack and adjusted the method I went about it. For those curious: Quote local function onattack_fire(inst, attacker, target, skipsanity) if target.components.burnable and not target.components.burnable:IsBurning() then if target.components.freezable and target.components.freezable:IsFrozen() then target.components.freezable:Unfreeze() else target.components.burnable:Ignite(true) end end if target.components.freezable then target.components.freezable:AddColdness(-1) if target.components.freezable:IsFrozen() then target.components.freezable:Unfreeze() end end if target.components.sleeper and target.components.sleeper:IsAsleep() then target.components.sleeper:WakeUp() end if target.components.combat then target.components.combat:SuggestTarget(attacker) end attacker.SoundEmitter:PlaySound("dontstarve/wilson/fireball_explo") target:PushEvent("attacked", {attacker = attacker, damage = 0}) end Edited February 18, 2018 by Kyrogeniz Link to comment https://forums.kleientertainment.com/forums/topic/87744-coding-help-weapon-to-ignite-enemies/#findComment-1005753 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