Game Development Community

Bots killing each other because of friendly fire, help

by Jose Salinas · in Torque 3D Professional · 08/24/2011 (7:23 pm) · 6 replies

Is there a ways to set the derect damage of a weapon to only go to the player datablock and not the bot datablock when they both use the DefultPlayerData? Or is there a way to do a friendly fire check?

#1
08/25/2011 (9:48 am)
Take a look at Armor::damage(), this is where applyDamage gets called. Just add an additional condition to the if check at the beginning so that if the object's class is AIPlayer then it will return.
#2
08/25/2011 (12:15 pm)
thanks for the reply,
sorry but my coding skills arnt good, Im more of an artist. I started to read some books but havent gottent to far in them yet,I got around it by setting my bots with very high health and do very low damage then setting the player with very low health and very high damage. You can see here http://www.facebook.com/#!/video/video.php?v=10150264658746621&oid=254703791218118&comments
#3
08/30/2011 (6:28 am)
go to scripts->server->player.cs

in
function Armor::damage()
change

function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
   if (!isObject(%obj) || %obj.getState() $= "Dead")
      return;

to

function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{

  if(%obj.getDataBlock ().getClassName () == "playerData")
  {
    echo("we r in god mode,so return from damagins us.");
    return;
  }

  if (!isObject(%obj) || %obj.getState() $= "Dead")
      return;

this will give both player and aibot god mode(no one will die).so make fun.
if u want something else than post u r code that u have changed from stock template code.

Animation of that video was nice.+battle
#4
08/30/2011 (6:42 am)
That code should be:
function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
   if(%this.getClassName() $= "PlayerData")
   {
      ...
(The getDataBlock() bit is technically correct, but unnecessary.) Though you'll probably want to be doing some comparisons on both the shooter and the target. So maybe something like:
function Armor::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
   if (!isObject(%obj) || %obj.getState() $= "Dead")
      return;

   if(%obj.getClassName() $= "AIPlayer" && %sourceObject.getClassName() $= "AIPlayer")
      // Don't damage the target
      return;

   // Damage the target
#5
08/30/2011 (7:08 am)
Daniel,That was a result of quick thinking,although I was trying to figure out u r one.i am still new to t3d.thanks
jose,u r work done.no need to post whole script.
#6
08/30/2011 (8:11 am)
thanks guys, im glad you like the video muzaheed.