Data Realms Fan Forums http://45.55.195.193/ |
|
Problem with Proximity mine http://45.55.195.193/viewtopic.php?f=73&t=19829 |
Page 1 of 1 |
Author: | MDKill [ Wed Sep 29, 2010 1:27 am ] |
Post subject: | Problem with Proximity mine |
Hi guys. Im trying to create a script to make a proximity bomb, able to explode when an enemy aproaches. The script seems to load fine, but it doesn´t work like i want, because the mine explodes right after i throw it away. Here is the script. Code: function Update(self) for actor in MovableMan.Actors do if actor.Team ~= self.Team then 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 < 100 then self:GibThis(); end end end end |
Author: | CaveCricket48 [ Wed Sep 29, 2010 1:44 am ] |
Post subject: | Re: Problem with Proximity mine |
That's because it's detecting the thrower. It's working perfectly. You should create a timer in the Create() function, and check if it's after a certain time before doing your proximity check. |
Author: | MDKill [ Wed Sep 29, 2010 3:05 am ] |
Post subject: | Re: Problem with Proximity mine |
Ok i made a timer but im getting an error in the console: http://img529.imageshack.us/img529/7055/screendump000.jpg Here is the new script: Code: function Create(self) self.LTimer = Timer(); end function Update(self) if Timer:IsPastSimMS(3000) == true then for actor in MovableMan.Actors do if actor.Team ~= self.Team then 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 < 100 then self:GibThis(); end end end end Thanks for your help. |
Author: | Mad Alex [ Wed Sep 29, 2010 1:50 pm ] |
Post subject: | Re: Problem with Proximity mine |
Add one more "end". And it must be Code: if self.LTimer:IsPastSimMS(3000) == true then instead of Code: if Timer:IsPastSimMS(3000) == true then |
Author: | MDKill [ Wed Sep 29, 2010 6:33 pm ] |
Post subject: | Re: Problem with Proximity mine |
It works! Thanks Alex! Here is the code with somebody wants it: Code: function Create(self) self.LTimer = Timer(); end function Update(self) if self.LTimer:IsPastSimMS(3000) == true then for actor in MovableMan.Actors do if actor.Team ~= self.Team then 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 < 50 then self:GibThis(); end end end end end |
Author: | Kyred [ Fri Oct 01, 2010 12:02 am ] |
Post subject: | Re: Problem with Proximity mine |
Code: if actor.Team ~= self.Team then You can take this if statement out. If I remember correctly from the old IRC MOTD, thrown items such as grenades and stuff don't have a defined team. If you want to use this line of code, you'll have to define the team yourself by adding some code to the Create function that searches for the nearest actor, since the nearest one is most likely the one who initially threw the bomb. Define that actor as the owner, and then use his team number for comparison instead of the bomb's. Hope this helps your optimize the code a little. |
Author: | MDKill [ Fri Oct 01, 2010 1:12 am ] |
Post subject: | Re: Problem with Proximity mine |
Thanks for the idea. I just started with lua, it seems a little complicated, but i will try. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |