Zardexrlz Posted December 10, 2016 Share Posted December 10, 2016 (edited) So i'm making a weapon that does more damage against dragon-type mobs (for now i'm including just dragonfly). The problem is that i dont know how to access the "target" to check if it has the tag i'm looking for. This part of the code is in the prefab file. I tried to use data.target and just target, as I saw on similar problems but still no luck. It doesn't crash, but my guess is that data is always nil. local damage = 2000 -- absurd damage is just to test it, after i get it working i will fine-tune it if data ~= nil then if data.target ~= nil and data.target.combat ~= nil then if data.target:HasTag("dragonfly") then -- absurd damage is just to test it, after i get it working i will fine-tune it damage = 27500 end end end inst:AddComponent("weapon") inst.components.weapon:SetDamage(damage) Any ideas? Thanks for the help in advance Edited December 10, 2016 by Zardexrlz Link to comment https://forums.kleientertainment.com/forums/topic/72382-modifying-damage-against-a-specific-mob-mob-type-with-a-specific-weapon/ Share on other sites More sharing options...
Rosten Posted December 10, 2016 Share Posted December 10, 2016 (edited) Try adding your function to the weapon's onattack with weapon:SetOnAttack like local function fireflykiller(target) local damage = 10 -- Default damage if target:HasTag("dragonfly") then damage = 30000 end inst.components.weapon:SetDamage(damage) end inst.components.weapon:SetOnAttack(fireflykiller) (Disclaimer: I'm kind of a terrible coder, this code probably wouldn't work, or at least, would impact performance a bit since it runs the function everytime it attacks anything) Edited December 10, 2016 by Rosten Added example code, fixed a bug which allowed Reaper to reach unintended locations with Shadow Step Link to comment https://forums.kleientertainment.com/forums/topic/72382-modifying-damage-against-a-specific-mob-mob-type-with-a-specific-weapon/#findComment-846879 Share on other sites More sharing options...
Aquaterion Posted December 10, 2016 Share Posted December 10, 2016 local function OnAttack(inst, attacker, target) if target:HasTag("dragonfly") then target.components.combat:GetAttacked(attacker, 200, inst)--200 is the bonus damage + the normal weapon damage end end inst.components.weapon:SetOnAttack(OnAttack) Link to comment https://forums.kleientertainment.com/forums/topic/72382-modifying-damage-against-a-specific-mob-mob-type-with-a-specific-weapon/#findComment-846896 Share on other sites More sharing options...
Zardexrlz Posted December 10, 2016 Author Share Posted December 10, 2016 7 hours ago, Rosten said: Try adding your function to the weapon's onattack with weapon:SetOnAttack like local function fireflykiller(target) local damage = 10 -- Default damage if target:HasTag("dragonfly") then damage = 30000 end inst.components.weapon:SetDamage(damage) end inst.components.weapon:SetOnAttack(fireflykiller) (Disclaimer: I'm kind of a terrible coder, this code probably wouldn't work, or at least, would impact performance a bit since it runs the function everytime it attacks anything) 6 hours ago, Aquaterion said: local function OnAttack(inst, attacker, target) if target:HasTag("dragonfly") then target.components.combat:GetAttacked(attacker, 200, inst)--200 is the bonus damage + the normal weapon damage end end inst.components.weapon:SetOnAttack(OnAttack) Thanks you both, it worked :D. Didn't see any performance issues @Rosten. Do you or @Aquaterion knows why exactly my code wouldn't work? I'm learning lua now so I want to understand all that I can. Thanks Link to comment https://forums.kleientertainment.com/forums/topic/72382-modifying-damage-against-a-specific-mob-mob-type-with-a-specific-weapon/#findComment-846972 Share on other sites More sharing options...
Rosten Posted December 10, 2016 Share Posted December 10, 2016 2 hours ago, Zardexrlz said: Thanks you both, it worked :D. Didn't see any performance issues @Rosten. Do you or @Aquaterion knows why exactly my code wouldn't work? I'm learning lua now so I want to understand all that I can. Thanks Reason being that your function is never called. It's just kind of there in the code. Adding it to OnAttack just makes it so that it runs whenever you hit something with your weapon. Link to comment https://forums.kleientertainment.com/forums/topic/72382-modifying-damage-against-a-specific-mob-mob-type-with-a-specific-weapon/#findComment-847006 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