Data Realms Fan Forums http://868000.nnhp.asia/ |
|
Parent of the bullet http://868000.nnhp.asia/viewtopic.php?f=73&t=31946 |
Page 1 of 1 |
Author: | Asklar [ Mon Oct 15, 2012 12:12 am ] |
Post subject: | Parent of the bullet |
So yeah, I've been forgetting all the lua stuff we used to use before lua on attachables. Code: function Create(self) for actor in MovableMan.Actors do if SceneMan:ShortestDistance(self.Pos,actor.Pos,true) < 100 and actor.EquippedItem.PresetName == "Tactical Grenade Launcher" then self.Parent = actor end end end function Update(self) for actor in MovableMan.Actors do if SceneMan:ShortestDistance(self.Pos,actor.Pos,true) < 100 and actor.Team ~= self.Parent.Team then self.PinStrength = 99999 self.Vel = (actor.Pos-self.Pos) self:GibThis() end end end It's just the old school way to find out who is the parent of the bullet (the script is attached to the bullet) and then ignoring the parent's team to explode against enemies. Basically some sort of proximity-detector with added directed blast. The error I'm getting is at line 11 (the first if of function Update(self)), in which it says it can't compare nil with a number, which probably means it isn't detecting any parent and hence can't compare the non-existing parent's team with the soon-to-be-killed actor's team. What the hell am I doing wrong? |
Author: | Shook [ Mon Oct 15, 2012 12:51 am ] |
Post subject: | Re: Parent of the bullet |
From what i can see, you forgot to grab the magnitude of SceneMan:ShortestDistance(), since that function returns a vector. Appending ".Magnitude" to the end of the function oughta fix at least SOME of your worries. However, what i also can tell you is that we now have a super awesome variable called self.IgnoresWhichTeam. It returns, conveniently enough, the team that the projectile doesn't collide with, which generally is the same as the guy who fired the gun. Just compare the potential target's team with that, and you should be good to go. There's not even the tiny risk of detecting an enemy actor with the same gun instead of yourself to begin with. c: |
Author: | Asklar [ Mon Oct 15, 2012 1:08 am ] |
Post subject: | Re: Parent of the bullet |
Code: function Update(self) for actor in MovableMan.Actors do if SceneMan:ShortestDistance(self.Pos,actor.Pos,true).Magnitude < 100 and actor.Team ~= self.IgnoresWhichTeam then self.PinStrength = 99999 self.Vel = (actor.Pos-self.Pos) self:GibThis() end end end Like this? Shook you are lovely, I didn't know we had that function! EDIT: Yes, that did it, Shook, I luv u c: |
Author: | Asklar [ Tue Oct 16, 2012 8:25 pm ] |
Post subject: | Re: Parent of the bullet |
Yes, Non, but at times I'm very dumb and compare vectors with integers just because. Also, I read on the wiki that if SceneMan:CastMORay() didn't collide with a MO it would return nil. Well, it returns 255. If someone can fix it I'd be glad. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |