Farlein Posted April 5, 2019 Share Posted April 5, 2019 (edited) Greetings. I came here for ask help from more experienced mod creators. I'm trying to create characters that own weapon with spread(aoe, area of effect damage), but will not use that spread when weapon is not equipped. Tried to use function below, but it's doesn't seem to be working. How could I give spread just to weapon and not for character? local function OnEquip(inst, owner) owner.components.combat:SetAreaDamage(20, 1) Edited April 5, 2019 by Farlein Link to comment https://forums.kleientertainment.com/forums/topic/104594-weapon-spread-on-equip/ Share on other sites More sharing options...
YakumoYukari Posted April 5, 2019 Share Posted April 5, 2019 The reason you can't AOE(the meaning of your "weapon spread") attack via owner.components.combat:SetAreaDamage(20, 1) is because the player's ATTACK action does target only one they're trying to attack. While AOE attacked will only exist when the attacker's attack can have multiple targets, and the attacked has not been attacked by the direct hit(this includes case evading DH but still in AOE range). So I think the best easy way to do is to let the weapon itself cause the attacker does AOE. Here's the code. In your weapon.lua: Put this in your fn() inst.components.weapon:SetOnAttack(OnAttack) And these in anywhere where is not belong to any local functions. local AOE_RADIUS = 20 local AREA_EXCLUDE_TAGS = { "INLIMBO", "notarget", "noattack", "flight", "invisible", "playerghost", "companion", "wall" } local function IsPreemitive(ent) return (TheNet:GetPVPEnabled() and ent:HasTag("player")) or (ent.components.combat ~= nil and ent.components.combat.target ~= nil) end local function DoAOEAttack(inst, attacker, target) attacker.components.combat:DoAreaAttack(target, AOE_RADIUS, inst, IsPreemitive, nil, AREA_EXCLUDE_TAGS) end local function OnAttack(inst, attacker, target) DoAOEAttack(inst, attacker, target) end If the attacker attacks target by your weapon, OnAttack() calls and it calls DoAOEAttack(). If you need to make a condition to raise AOE, if-case it. And DoAOEAttack() cause AOE only targets enemies that is about to attack you and players when PVP is on. If you don't want this condition, modify IsPreemitive() and AREA_EXCLUDE_TAGS as you wish. And the amount of AOE damage can be edited by inst.components.combat.areahitdamagepercent = 1 in fn() of your character.lua But the damage itself will not decrease or dynamically calculated by distance. - Only the static amount of damage will be taken. If you want to implement any kind of these, you need to make your AOE functions. 1 Link to comment https://forums.kleientertainment.com/forums/topic/104594-weapon-spread-on-equip/#findComment-1175063 Share on other sites More sharing options...
KingAlpha Posted June 10, 2020 Share Posted June 10, 2020 Hi @YakumoYukari. I stumbled on this post while dealing with my creation. I'm trying to make an ultimate attack for my character. And when it hits I would like it to hit enemies around the initial target. For now this is what I have. So the way it works is I press a button, weapon will lights up, and when I press attack on the enemy this bunch of fx will happen and the attack is hit. Please do not laugh too hard at my fx spam, I like it fancy . local function hitother(inst) if inst.components.king.power == 1 and inst.components.combat.target and inst.components.combat.target:IsValid() then if inst.components.rider:IsRiding() then return end inst.components.king.power = 0 SpawnPrefab("icing_splash_fx_full").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("icing_splash_fx_med").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("icing_splash_fx_low").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("icing_splash_fx_melted").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("crabking_feeze").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("crabking_ring_fx").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("icespike_fx_1").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("icespike_fx_2").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("icespike_fx_3").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("icespike_fx_4").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("splash_snow_fx").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("spawn_fx_small_high").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) SpawnPrefab("groundpoundring_fx").Transform:SetPosition(inst.components.combat.target.Transform:GetWorldPosition()) DoAOEAttack(inst, target) inst.powerfx:Remove() inst.fxout = SpawnPrefab("deer_ice_burst") inst.fxout.entity:SetParent(inst.entity) inst.fxout.entity:AddFollower() inst.fxout.Follower:FollowSymbol(inst.GUID, "swap_body", 0, 0, 0) inst.SoundEmitter:PlaySound("dontstarve/common/fireOut") inst.components.combat.damagemultiplier = 1 if inst.components.hunger.current <= 0 then inst.components.health:DoDelta(-40) end inst.components.hunger:DoDelta(-40) inst.components.sanity:DoDelta(-20) end end This worked in game as it attack only one enemy. This code is in my character.lua because the special attack can be use on any weapon. Thank you very much Link to comment https://forums.kleientertainment.com/forums/topic/104594-weapon-spread-on-equip/#findComment-1341224 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