Game Development Community

How to track which agent is doing damage on who

by Imm Dtu · in Torque Game Engine · 04/30/2007 (7:58 am) · 1 replies

Hi.

I am doing some AI on a project and need to be able to track which of my bots are doing damage on other bots or human players. I need this to measure their performance at the end of the game and to find out who is shooting at who in realtime so the bots can react on who is shooting. Unfortunately I do not have a clue where to start - I have tried to search the forum and the resources but have been unsuccessful in finding similar questions. Any help on how to do this is much appreciated.

/Imm

#1
05/01/2007 (10:14 am)
If your using projectiles, its easy to keep track of who's hitting who. Using the crossbow as an example, you would have a function like this
CrossbowImage::onFire(%this, %obj, %slot)
With most functions, "%this" is the dataBlock, and "%obj" is the object. But in here, %obj is the player who fired the weapon.

You also have a function
CrossbowProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
In here, "%obj" is the projectile, and "%col" is the object the projectile hit. So lets use this to find who hit who.

You can store who fired each projectile by putting this before the "return %p;" in the "onFire" function:
%p.player = %obj;

Then in your "onCollision" function, you can echo who hit who with:
if (%col.getType() & $TypeMasks::PlayerObjectType)
      echo(%obj.player.getName() @ " Shot " @ %col.getName());

I am currently unable to test this, but I believe it should work.
Hope it helps.