| Author | Message | 
        
			| blargiefarg 
					Joined: Mon Apr 05, 2010 8:04 am
 Posts: 149
 Location: Under your bed
   |   detect damage on a targetSo what I'm trying to do is make a script that stores the amount of damage that it does to an actor in a variable to be accessed on the Destroy() function. Any ideas on how I might achieve this? I took a look at the CollectDamage function, but I'm not 100% sure if its what I need. EDIT: I gave it a shot anyway. here's what I've got, I haven't tested it yet, but its something Code: function Create(self)local curdist = 50;
 for actor in MovableMan.Actors do
 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 < curdist then
 curdist = dist;
 self.parent = actor;
 end
 end
 self.target = nil;
 leechpx = CreateMOPixel("healpx")
 leechpx.vectorthing = nil;
 leechpx.anglething = nil;
 self.target.damage = nil;
 
 function Update(self)
 local curdist = 50;
 for particle in MovableMan.Particles do
 if particle.IsOfActor == 1
 if particle.Team ~= self.Team then
 local avgx = particle.Pos.X - self.Pos.X;
 local avgy = particle.Pos.Y - self.Pos.Y;
 local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
 if dist < curdist then
 curdist = dist;
 self.target = particle;
 end
 end
 end
 end
 
 function Destroy(self)
 if self.target ~= nil then
 self.target.damage = self.target:CollectDamage();
 if self.target.damage > 0 then
 self.parent = AddHealth(self.target.damage)
 MovableMan:AddMOPixel(leechpx);
 MovableMan:AddMOPixel(leechpx);
 MovableMan:AddMOPixel(leechpx);
 leechpx.pos = self.pos;
 if MovableMan:IsActor(self.target) and MovableMan:IsActor(self.parent) then
 leechpx.vectorthing = SceneMan:ShortestDistance(leechpx.Pos,self.parent.Pos,self.mapwrapx):SetMagnitude(leechpx.Vel.Magnitude);
 leechpx.anglething = (leechpx.Vel + (leechpx.vectorthing):SetMagnitude(leechpx.Vel.Magnitude)).AbsRadAngle;
 --self.Vel = Vector(self.Vel.X,self.Vel.Y):RadRotate(self.anglething);
 leechpx.Vel = (leechpx.Vel + leechpx.vectorthing):SetMagnitude(leechpx.Vel.Magnitude);
 end
 end
 end
EDIT2: Tested it, and there's no luck. I'm going to double check, but if anyone spots something first, do tell!
 
 
    							Last edited by blargiefarg on Tue May 17, 2011 7:20 am, edited 1 time in total. 
 
 | 
		
			| Sun May 15, 2011 4:33 pm | 
					
					     | 
	
	
		|  | 
	
			| CaveCricket48 
					Joined: Tue Jun 12, 2007 11:52 pm
 Posts: 13144
 Location: Here
   |   Re: detect damage on a targetFirst, use the [code] tags. Makes it easier to read.
 Second, CollectDamage() may or may not actually work.
 
 
 | 
		
			| Mon May 16, 2011 11:39 pm | 
					
					   | 
	
	
		|  | 
	
			| blargiefarg 
					Joined: Mon Apr 05, 2010 8:04 am
 Posts: 149
 Location: Under your bed
   |   Re: detect damage on a targetReally? is it simply kinda hard to predict, or is it a not quite finished feature? 
 
 | 
		
			| Tue May 17, 2011 7:22 am | 
					
					     | 
	
	
		|  | 
	
			| Xery 
					Joined: Sat Feb 26, 2011 10:29 am
 Posts: 163
   |   Re: detect damage on a target
 
 | 
		
			| Tue May 17, 2011 9:35 am | 
					
					   | 
	
	
		|  | 
	
			| blargiefarg 
					Joined: Mon Apr 05, 2010 8:04 am
 Posts: 149
 Location: Under your bed
   |   Re: detect damage on a targetYeah, kinda, but the problem with that method is that will give me the amount of damage that the actor has received throughout its entire lifespan, not the damage that it received from a single bullet. I could be messy, and set the leech at a flat value for every hit, but if possible, I'd like it to be variable depending on how much damage the bullet does. 
 
 | 
		
			| Tue May 17, 2011 11:09 am | 
					
					     | 
	
	
		|  | 
	
			| Grif REAL AMERICAN HERO 
					Joined: Sat Jan 27, 2007 10:25 pm
 Posts: 5655
   |   Re: detect damage on a targetwhat might work, depending on how your bullet itself flies:
 cast an MORay as soon as the bullet is fired, which locks in the "target", and stores the health
 
 then inside your other particle's code, check the difference between the two health values
 
 
 | 
		
			| Tue May 17, 2011 6:29 pm | 
					
					   | 
	
	
		|  | 
	
			| Xery 
					Joined: Sat Feb 26, 2011 10:29 am
 Posts: 163
   |   Re: detect damage on a targetGrif wrote: what might work, depending on how your bullet itself flies:
 cast an MORay as soon as the bullet is fired, which locks in the "target", and stores the health
 
 then inside your other particle's code, check the difference between the two health values
If bullets from other guns damage the target between the two checking...
 
 | 
		
			| Tue May 17, 2011 6:53 pm | 
					
					   | 
	
	
		|  | 
	
			| blargiefarg 
					Joined: Mon Apr 05, 2010 8:04 am
 Posts: 149
 Location: Under your bed
   |   Re: detect damage on a targetI'd be willing to do that, but I guess its time to do some research on MORays, for I have NO experience with them. 
 
 | 
		
			| Wed May 18, 2011 12:08 am | 
					
					     | 
	
	
		|  | 
	
			| Xery 
					Joined: Sat Feb 26, 2011 10:29 am
 Posts: 163
   |   Re: detect damage on a targetblargiefarg wrote: I'd be willing to do that, but I guess its time to do some research on MORays, for I have NO experience with them.What? Wait, there're many methods similar to this one, I didn't propose them because they have a short time interval between the bullet checked to be destroy or not, which may cause miscalculation when other bullets damage the target in this interval(thing about shotguns or explosives). How to solve this, to judgment more accurately?
 
 | 
		
			| Wed May 18, 2011 4:36 am | 
					
					   | 
	
	
		|  | 
	
			| blargiefarg 
					Joined: Mon Apr 05, 2010 8:04 am
 Posts: 149
 Location: Under your bed
   |   Re: detect damage on a targetI think I may have come up with a fix for that. Put the SceneMan:CastMORay in the update function of the bullet itself, that way it would update the target in case of an odd change of direction, and also, it would automatically update the health every frame in case he gets hit by someone else''s fire. 
 
 | 
		
			| Wed May 18, 2011 2:44 pm | 
					
					     | 
	
	
		|  | 
	
			| Grif REAL AMERICAN HERO 
					Joined: Sat Jan 27, 2007 10:25 pm
 Posts: 5655
   |   Re: detect damage on a targetXery: I'm aware of the problem, but I can't see any solution that's really any better. Obviously casting the ray each frame would help, but rays are fairly expensive, cycle wise. Shouldn't be a huge issue unless it's a fully automatic weapon. 
 
 | 
		
			| Wed May 18, 2011 4:46 pm | 
					
					   | 
	
	
		|  | 
	
			| blargiefarg 
					Joined: Mon Apr 05, 2010 8:04 am
 Posts: 149
 Location: Under your bed
   |   Re: detect damage on a targetI could also probably make it skip a pixel or two to optimize it further.
 EDIT: How would you get the health once the MORay hits?
 
 
 | 
		
			| Wed May 18, 2011 6:55 pm | 
					
					     | 
	
	
		|  | 
	
			| Grif REAL AMERICAN HERO 
					Joined: Sat Jan 27, 2007 10:25 pm
 Posts: 5655
   |   Re: detect damage on a targetyou get the MOID from the ray, then use GetMOFromID, then you might need a ToActor, but you should be able to read health at that point.
 There's probably also something in there with .RootID, since you might get an arm or leg, but I am honestly not sure. I hardly ever use rays.
 
 
 | 
		
			| Thu May 19, 2011 4:01 am | 
					
					   | 
	
	
		|  | 
	
			| blargiefarg 
					Joined: Mon Apr 05, 2010 8:04 am
 Posts: 149
 Location: Under your bed
   |   Re: detect damage on a targetWould you please elabourate on the .RootID? I might have an idea, but before I do anything, I'd like to know where on earth you'd include it. Code: function Create(self)local curdist = 50;
 for actor in MovableMan.Actors do
 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 < curdist then
 curdist = dist;
 self.parent = actor;
 end
 end
 print ("self.parent set");
 self.target = nil;
 leechpx = CreateMOPixel("healpx");
 print ("healpx ready");
 leechpx.vectorthing = nil;
 leechpx.anglething = nil;
 self.targetbefore.health = nil;
 self.targetafter.health = nil;
 self.targetafter.damage = nil;
 
 function Update(self)
 self.targetbefore = ToActor(MovableMan:GetMOFromID(SceneMan:CastMORay(self.Pos, (self.Vel*2), self.ID, 0, true, 1)));
 self.targetbefore.health = self.targetbefore.Health;
 
 function Destroy(self)
 local curdist = 50;
 for actor in MovableMan.Actors do
 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 < curdist then
 curdist = dist;
 self.targetafter = actor;
 self.targetafter.health = self.targetafter.Health
 end
 end
 if self.targetafter ~= nil then
 self.targetafter.damage = (self.targetbefore.health - self.targetafter.Health)
 if self.targetafter.damage > 0 then
 self.parent:AddHealth(self.target.damage);
 MovableMan:AddMOPixel(leechpx);
 MovableMan:AddMOPixel(leechpx);
 MovableMan:AddMOPixel(leechpx);
 leechpx.pos = self.pos;
 if MovableMan:IsActor(self.target) and MovableMan:IsActor(self.parent) then
 leechpx.vectorthing = SceneMan:ShortestDistance(leechpx.Pos,self.parent.Pos,self.mapwrapx):SetMagnitude(leechpx.Vel.Magnitude);
 leechpx.anglething = (leechpx.Vel + (leechpx.vectorthing):SetMagnitude(leechpx.Vel.Magnitude)).AbsRadAngle;
 --self.Vel = Vector(self.Vel.X,self.Vel.Y):RadRotate(self.anglething);
 leechpx.Vel = (leechpx.Vel + leechpx.vectorthing):SetMagnitude(leechpx.Vel.Magnitude);
 end
 end
 end
 
 | 
		
			| Thu May 19, 2011 12:00 pm | 
					
					     | 
	
	
		|  | 
	
			| Roast Veg Data Realms Elite 
					Joined: Tue May 25, 2010 8:27 pm
 Posts: 4522
 Location: Constant motion
   |   Re: detect damage on a targetCode: self.targetbefore = ToActor(MovableMan:GetMOFromID(SceneMan:CastMORay(self.Pos, (self.Vel*2), self.ID, 0, true, 1)).RootID);You might want to end those functions as well.
 
 | 
		
			| Thu May 19, 2011 4:59 pm | 
					
					   | 
	
	
		|  | 
	
	
		|  |