Re: Need help with damage script
I believe you have two problems.
1. Your timer isn't internal to the object. I helped Gotcha! with his killzone, and before I made the timer internal (put self. in front of all instances of the timer name) only the first killzone would work.
2. The code checks to see if the actor being looked at is on the same team as the object with the script attached. AEmitters don't have teams, so I don't know what it would do when it tried that comparison.
Try using this script instead.
Code:
function Create(self)
--Keep track of how long it should be before healing people.
self.healTimer = Timer();
--Interval between healings, in milliseconds.
self.healInterval = 100;
end
function Update(self)
--Heal every interval.
if self.healTimer:IsPastSimMS(self.healInterval) then
--Cycle through all actors.
for actor in MovableMan.Actors do
--If the actor is on the right team, has less than 100 health and is not the healer, continue with code.
if actor.ID ~= self.ID then
--Trigonometry to find how far the actor is.
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < 40 then
--If the actor is fairly close, heal them!
actor.Health = actor.Health - 0.05;
end
end
end
--Reset the healing timer.
self.healTimer:Reset();
end
end
I just put in the above things into your script.