View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:22 pm



Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
 detect damage on a target 
Author Message
User avatar

Joined: Mon Apr 05, 2010 8:04 am
Posts: 149
Location: Under your bed
Reply with quote
Post 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!


Last edited by blargiefarg on Tue May 17, 2011 7:20 am, edited 1 time in total.



Sun May 15, 2011 4:33 pm
Profile YIM
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: detect damage on a target
First, use the [code] tags. Makes it easier to read.

Second, CollectDamage() may or may not actually work.


Mon May 16, 2011 11:39 pm
Profile
User avatar

Joined: Mon Apr 05, 2010 8:04 am
Posts: 149
Location: Under your bed
Reply with quote
Post Re: detect damage on a target
Really? is it simply kinda hard to predict, or is it a not quite finished feature?


Tue May 17, 2011 7:22 am
Profile YIM
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post Re: detect damage on a target
viewtopic.php?f=75&t=22486&start=15
Can this help you?


Tue May 17, 2011 9:35 am
Profile
User avatar

Joined: Mon Apr 05, 2010 8:04 am
Posts: 149
Location: Under your bed
Reply with quote
Post 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.


Tue May 17, 2011 11:09 am
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Tue May 17, 2011 6:29 pm
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post 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...


Tue May 17, 2011 6:53 pm
Profile
User avatar

Joined: Mon Apr 05, 2010 8:04 am
Posts: 149
Location: Under your bed
Reply with quote
Post 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.


Wed May 18, 2011 12:08 am
Profile YIM
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post 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?


Wed May 18, 2011 4:36 am
Profile
User avatar

Joined: Mon Apr 05, 2010 8:04 am
Posts: 149
Location: Under your bed
Reply with quote
Post 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.


Wed May 18, 2011 2:44 pm
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Wed May 18, 2011 4:46 pm
Profile
User avatar

Joined: Mon Apr 05, 2010 8:04 am
Posts: 149
Location: Under your bed
Reply with quote
Post 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?


Wed May 18, 2011 6:55 pm
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Thu May 19, 2011 4:01 am
Profile
User avatar

Joined: Mon Apr 05, 2010 8:04 am
Posts: 149
Location: Under your bed
Reply with quote
Post 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


Thu May 19, 2011 12:00 pm
Profile YIM
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post 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.


Thu May 19, 2011 4:59 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 16 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.071s | 13 Queries | GZIP : Off ]