Data Realms Fan Forums http://45.55.195.193/ |
|
Need help with damage script http://45.55.195.193/viewtopic.php?f=73&t=15022 |
Page 1 of 1 |
Author: | Shook [ Thu May 28, 2009 1:25 pm ] | ||
Post subject: | Need help with damage script | ||
So, the problem is that the attached script (shamelessy modified Medic Drone script) doesn't seem to work with AEmitters, and i don't know why. It's supposed to subtract health from any actor nearby at the shown rate (0.05 health every 100 milliseconds), and it works when it's put on an actor, but nothing happens when it's on an AEmitter. It'd be greatly appreciated if someone could fix it for me. (Note: I'm totally clueless regarding Lua, so please, bear with me)
|
Author: | Duh102 [ Thu May 28, 2009 2:19 pm ] |
Post subject: | 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. |
Author: | Shook [ Thu May 28, 2009 2:59 pm ] |
Post subject: | Re: Need help with damage script |
Ahh, thanks, it works like a charm now. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |