Data Realms Fan Forums http://45.55.195.193/ |
|
detect damage on a target http://45.55.195.193/viewtopic.php?f=73&t=23746 |
Page 1 of 2 |
Author: | blargiefarg [ Sun May 15, 2011 4:33 pm ] |
Post subject: | detect damage on a target |
So 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! |
Author: | CaveCricket48 [ Mon May 16, 2011 11:39 pm ] |
Post subject: | Re: detect damage on a target |
First, use the [code] tags. Makes it easier to read. Second, CollectDamage() may or may not actually work. |
Author: | blargiefarg [ Tue May 17, 2011 7:22 am ] |
Post subject: | Re: detect damage on a target |
Really? is it simply kinda hard to predict, or is it a not quite finished feature? |
Author: | Xery [ Tue May 17, 2011 9:35 am ] |
Post subject: | Re: detect damage on a target |
viewtopic.php?f=75&t=22486&start=15 Can this help you? |
Author: | blargiefarg [ Tue May 17, 2011 11:09 am ] |
Post subject: | Re: detect damage on a target |
Yeah, 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. |
Author: | Grif [ Tue May 17, 2011 6:29 pm ] |
Post subject: | Re: detect damage on a target |
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 |
Author: | Xery [ Tue May 17, 2011 6:53 pm ] |
Post subject: | Re: detect damage on a target |
Grif 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... |
Author: | blargiefarg [ Wed May 18, 2011 12:08 am ] |
Post subject: | Re: detect damage on a target |
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. |
Author: | Xery [ Wed May 18, 2011 4:36 am ] |
Post subject: | Re: detect damage on a target |
blargiefarg 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? |
Author: | blargiefarg [ Wed May 18, 2011 2:44 pm ] |
Post subject: | Re: detect damage on a target |
I 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. |
Author: | Grif [ Wed May 18, 2011 4:46 pm ] |
Post subject: | Re: detect damage on a target |
Xery: 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. |
Author: | blargiefarg [ Wed May 18, 2011 6:55 pm ] |
Post subject: | Re: detect damage on a target |
I 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? |
Author: | Grif [ Thu May 19, 2011 4:01 am ] |
Post subject: | Re: detect damage on a target |
you 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. |
Author: | blargiefarg [ Thu May 19, 2011 12:00 pm ] |
Post subject: | Re: detect damage on a target |
Would 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 |
Author: | Roast Veg [ Thu May 19, 2011 4:59 pm ] |
Post subject: | Re: detect damage on a target |
Code: 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. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |