Jump to content

Recommended Posts

Hello, I need help :)!

This's the code I need help with

Spoiler

local function BatVeilAttack(inst)
local x, y, z = inst.Transform:GetWorldPosition()
local adam = TheSim:FindEntities(x, y, z, 1, nil, NON_ATTACK_TAGS, ATTACK_TAGS)
local ents = TheSim:FindEntities(x, y, z, 1.75, nil, NON_ATTACK_TAGS, ATTACK_TAGS)

   for i, v in ipairs(ents) do
      if v:IsValid() and not v:IsInLimbo() then
         if v.components.combat ~= nil and not v.lord_mode == true and v.components.health and not v.components.health:IsDead() then
            v.components.combat:GetAttacked(inst, 1, nil)
			
            for i, v in ipairs(adam) do
               if v:IsValid() and not v:IsInLimbo() then
                  if v.lord_mode == true and v.components.health and not v.components.health:IsDead() then
                  v.components.health:DoDelta(1)
                  end
               end
            end
			
         end
      end
   end
   
end

So, what I want to do is make a leeching attack for my character, where when an entity in range gets hit the health goes to my character!

The problem right now's since I don't know a code to check how many entities are in 1.75 range then my character just heals 1 point of health even if their are 5 entities in range getting hit by the leeching attack..

Also, thanks very much for reading my problem & have like a wonderful day or night, peace :D!!!

 

EDIT: So, I didn't figure out how to check how many entities are within range, but I learned that Ipairs already does the code for every single entity in range so my health draining thing was always working fine it's just I wasn't close enough when testing it, lol fail!! Anyways thanks for reading :D!

 

 

Edited by SuperDavid

I think you need to put the code for the second part inside the first part so it happens when there are entities in ents. Or save the number of entities in ents and use that in the second part.

Edited by HabdomeRaider
4 hours ago, HabdomeRaider said:

I think you need to put the code for the second part inside the first part so it happens when there are entities in ents. Or save the number of entities in ents and use that in the second part.

Thanks, I didn't think of that at all! It totally worked, now it only heals when their are entities in range :D!!

Edited by SuperDavid

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...