Game Development Community

How to tell who is a player and who is an AI

by Andy Hawkins · in Torque Game Engine · 09/13/2006 (8:19 am) · 1 replies

I've had to write a new bit of code for handling death when using K.Finney's swarm code. Seems when I attack the AI they don't die - they take damage, they just don't play the Armor::onDisable() function in player.cs

So what I did was write it into my collision detection function - however I've since found out, while doing a multiplayer test that the other player actual does use the Armor::onDisable() function so both mine and the player.cs function run at the same time. The result is that if the player dies they can still fire, and when they respawn the engine crashes.

Here's the code below, but I think I need to find out
a) why Mr. Finney's swarm code is not calling the Armor::onDisable() function - all AI are of Player type.
b) if I should be writing my own onDisable code for the AI
c) and if so (writing my own) how do I detect if the character is a player and so don't run my own code, let the player.cs do it's thing instead....something like if (!this.object.is.player && ((%col.getType() & $TypeMasks::PlayerObjectType) && %col.getState() !$= "Dead")) - then do it...

Here's what I have now that conflicts with Armor::onDisable() if it's a player being killed. Hope someone can help.


// Apply damage to the object all shape base objects
   if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
   {
      // damage it
      if((%col.getType() & $TypeMasks::PlayerObjectType) && %col.getState() !$= "Dead")
      {
         %col.applyDamage(%this.directDamage);
         
         if (%col.getState() $= "Dead")
         {
            %col.playDeathCry();
            %col.playDeathAnimation();
            %col.setDamageFlash(0.75);

            // Release the main weapon trigger
            %col.setImageTrigger(0,false);

            // Schedule corpse removal.  Just keeping the place clean.
            %col.schedule($CorpseTimeoutValue - 1000, "startFade", 1000, 0, true);
            %col.schedule($CorpseTimeoutValue, "delete");
         }
      }
      else
      {
         %col.damage(%obj,%pos,%this.directDamage,"Fireball Damage");
      }
      
   }

#1
09/13/2006 (8:49 am)
You can tell if a player object is a bot or a real player a couple ways:

1. check its classname:
if (%player.getClassName() $= "AIPlayer")
   // it's an AI player
else
   // it's a real player

2. check if it has a valid client field. this is the one i prefer.
if (isObject(%player.client))
   // it's a real player
else
   // it's an AI player