Game Development Community

Ai Player Problem

by Johnathan Moore · in Torque Game Engine · 12/18/2005 (12:31 pm) · 12 replies

Ok my head is spinning over this, I just figured out how the whole AI player system works(ish) now it has an error whenever it loads my script file and spits
Loading compiled script CrimsonReign/server/Characters/SoldierClSpwn.cs.
Loading compiled script CrimsonReign/server/soldier/soldiernpc.cs.
Validation required for shape: CrimsonReign/data/shapes/soldier/soldier.dts


This is what i've put to create the player
function Spawntestai(%name,%datablock,%role,%spawn)
{

%npc = new AIPlayer() {
    dataBlock = "soldiernpc";
    aiPlayer = true;
  };
  MissionCleanup.add(%npc);
  AIGroup.add(%npc);

%npc.setobjectposition(%spawn);
%npc.role = %role;
%npc.setShapeName(%name);
%npc.setTransform(%spawn);
%npc.onspawn();


// Begin looping function
  loop(%me);
}

and the soldier npc
datablock PlayerData(Soldiernpc : Soldierbase)
{
// shapeFile = "~/data/shapes/soldier/soldier.dts";
//className = "NPC";
clocktime = 20;
aiPlayer = true;
maxLOSdist = 200;
cmdCategory = "";
aiAvoidThis = false;
};


any help would be great, thks

#1
12/18/2005 (12:35 pm)
Ooopps silly little mistake
loop(%me); is loop(%npc);

doesnt change anything tho
#2
12/18/2005 (12:47 pm)
What soldier model are you using, did you make it yourself?
#3
12/18/2005 (12:49 pm)
The soldier model from the soldier content pack,there is nothing wrong with the model as it loads up when it does not execute that file
#4
12/18/2005 (1:03 pm)
Thats what I thought some of the models from content packs and such say that. I don't think that qualifies as a fatal error though I've had it say that and it didn't do anything. Maybe pop in the torque orc and see if it says the same thing, I'm pretty sure this is your model not the code.
#5
12/18/2005 (1:11 pm)
No that hasnt got much to do with it,when i said a fatal error i meant the game crashs thats just where the console ends and it appear somewhere else now, it trips up when it executes the dso
//-------------------------- 12/18/2005 -- 20:56:16 -----
Processor Init:
   Intel Pentium 4, ~2.87 Ghz
     (timed at roughly 2.86 Ghz)
   FPU detected
   MMX detected
   SSE detected
 
Math Init:
   Installing Standard C extensions
   Installing Assembly extensions
   Installing FPU extensions
   Installing MMX extensions
   Installing SSE extensions
 
Input Init:
   keyboard0 input device created.
   mouse0 input device created.
   DirectInput enabled.

Initializing chunk mappings...
   o 'TEXT' maps to TextChunk
   o 'SCHK' maps to UnknownChunk
   o 'SCHK' maps to SimChunk
--------- Loading MODS ---------
Compiling CrimsonReign/main.cs...
Loading compiled script CrimsonReign/main.cs.
Compiling common/main.cs...
Loading compiled script common/main.cs.
Missing file: common/defaults.cs!
Compiling CrimsonReign/client/defaults.cs...
Loading compiled script CrimsonReign/client/defaults.cs.
Compiling CrimsonReign/server/defaults.cs...
Loading compiled script CrimsonReign/server/defaults.cs.
Compiling CrimsonReign/client/profile/profile.cs...
Loading compiled script CrimsonReign/client/profile/profile.cs.
Compiling CrimsonReign/client/profile/John/options.cs...
Loading compiled script CrimsonReign/client/profile/John/options.cs.
Compiling creator/main.cs...
Loading compiled script creator/main.cs.
Loading compiled script common/main.cs.
Missing file: common/defaults.cs!

--------- Parsing Arguments ---------

--------- Initializing MOD: Common ---------
Compiling common/client/canvas.cs...
Loading compiled script common/client/canvas.cs.
Compiling common/client/audio.cs...
Loading compiled script common/client/audio.cs.

-----------------------------
blaa blaa blaa :p
-----------------------------

--------- Initializing: Torque Creator ---------
Compiling creator/editor/editor.cs...
Loading compiled script creator/editor/editor.cs.
Compiling creator/editor/particleEditor.cs...
Loading compiled script creator/editor/particleEditor.cs.
Compiling creator/scripts/scriptDoc.cs...
Loading compiled script creator/scripts/scriptDoc.cs.
Compiling creator/ui/creatorProfiles.cs...
Loading compiled script creator/ui/creatorProfiles.cs.
Compiling creator/ui/InspectDlg.gui...
Loading compiled script creator/ui/InspectDlg.gui.
Compiling creator/ui/GuiEditorGui.gui...
Loading compiled script creator/ui/GuiEditorGui.gui.
Engine initialized...
Cancel cg logo
cancelScreen: Unknown command.
Exporting server prefs...
Compiling CrimsonReign/server/audioProfiles.cs...
Loading compiled script CrimsonReign/server/audioProfiles.cs.
Compiling CrimsonReign/server/camera.cs...
Loading compiled script CrimsonReign/server/camera.cs.
Compiling CrimsonReign/server/editor.cs...
Loading compiled script CrimsonReign/server/editor.cs.
Compiling CrimsonReign/server/soldier/player.cs...
Loading compiled script CrimsonReign/server/soldier/player.cs.
Compiling CrimsonReign/data/shapes/soldier/soldier.cs...
Loading compiled script CrimsonReign/data/shapes/soldier/soldier.cs.
Validation required for shape: CrimsonReign/data/shapes/soldier/soldier.dts
Compiling CrimsonReign/server/soldier/SoldierCharacters.cs...
Loading compiled script CrimsonReign/server/soldier/SoldierCharacters.cs.
Validation required for shape: CrimsonReign/data/shapes/soldier/soldier.dts
Validation required for shape: CrimsonReign/data/shapes/soldier/soldier.dts
Validation required for shape: CrimsonReign/data/shapes/soldier/soldier.dts
Validation required for shape: CrimsonReign/data/shapes/soldier/soldier.dts
Compiling CrimsonReign/data/shapes/weapons/load.cs...
Loading compiled script CrimsonReign/data/shapes/weapons/load.cs.
Compiling CrimsonReign/data/shapes/weapons/m16/m16.cs...
Loading compiled script CrimsonReign/data/shapes/weapons/m16/m16.cs.
Object 'M16ExplosionBubbleEmitter' is not a member of the 'ParticleEmitterData' data block class
Object 'M16ExplosionBubbleEmitter' is not a member of the 'ParticleEmitterData' data block class
Object 'M16AmmoBubbleEmitter' is not a member of the 'ParticleEmitterData' data block class
Error: shape CrimsonReign/data/shapes/weapons/m16/ammo.dts-collision detail 0 (Collision-3) bounds box invalid!
Object 'WeaponSwitchSound' is not a member of the 'AudioProfile' data block class
Compiling CrimsonReign/data/shapes/weapons/rifleammo.cs...
Loading compiled script CrimsonReign/data/shapes/weapons/rifleammo.cs.
Error: shape CrimsonReign/data/shapes/weapons/ammo.dts-collision detail 0 (Collision-3) bounds box invalid!
Compiling CrimsonReign/data/shapes/weapons/tommygun/tommygun.cs...
Loading compiled script CrimsonReign/data/shapes/weapons/tommygun/tommygun.cs.
ParticleEmitterData(TommyGunSmokeEmitter) unable to find particle datablock: TommyGunsmoke
ParticleEmitterData(TommyGunSmokeEmitter) unable to find any particle datablocks
CrimsonReign/data/shapes/weapons/tommygun/tommygun.cs (0): Register object failed for object TommyGunSmokeEmitter of class ParticleEmitterData.
Missing file: CrimsonReign/data/shapes/weapons/tommygun/crossbow.cs!
Compiling CrimsonReign/server/centerprint.cs...
Loading compiled script CrimsonReign/server/centerprint.cs.
Compiling CrimsonReign/server/item.cs...
Loading compiled script CrimsonReign/server/item.cs.
Compiling CrimsonReign/server/itemdata/health.cs...
Loading compiled script CrimsonReign/server/itemdata/health.cs.
Compiling CrimsonReign/server/weapon.cs...
Loading compiled script CrimsonReign/server/weapon.cs.
Compiling CrimsonReign/server/triggers.cs...
Loading compiled script CrimsonReign/server/triggers.cs.
Compiling CrimsonReign/server/inventory.cs...
Loading compiled script CrimsonReign/server/inventory.cs.
Compiling CrimsonReign/server/soldier/soldier_accessories.cs...
Loading compiled script CrimsonReign/server/soldier/soldier_accessories.cs.
Compiling CrimsonReign/server/radiusdamage.cs...
Loading compiled script CrimsonReign/server/radiusdamage.cs.
Compiling CrimsonReign/server/Characters/SoldierClSpwn.cs...
Loading compiled script CrimsonReign/server/Characters/SoldierClSpwn.cs.
Compiling CrimsonReign/server/soldier/soldiernpc.cs...
Loading compiled script CrimsonReign/server/soldier/soldiernpc.cs.
#6
12/18/2005 (1:16 pm)
//-----------------------------------------------------------------------------
// Torque Game Engine 
// Copyright (C) Crypton Games 2005
//-----------------------------------------------------------------------------

// ***********************************************************************
// Error: cannot change namespace parent linkage for Soldiernpc from NPC to PlayerData.
// ***********************************************************************
// ???????????


function AIManager::think(%npc)
{
   // We could hook into the player's onDestroyed state instead of
   // having to "think", but thinking allows us to consider other
   // things...
  // if (!isObject(%npc.player))
  //    %npc.player = %npc.spawn();
  // %npc.loop(%npc);
}


datablock PlayerData(Soldiernpc : Soldierbase)
{
// shapeFile = "~/data/shapes/soldier/soldier.dts";
//className = "NPC";
clocktime = 20;
aiPlayer = true;
maxLOSdist = 200;
cmdCategory = "";
aiAvoidThis = false;
};


function Soldiernpc::afterSpawn(%npc)
{

}

// -----------------------------
// Methods ---------------------
// -----------------------------


function Soldiernpc::loop(%npc)
{
switch$(%npc.role)
{
case "Turret":
%threat = CheckForThreat(%this);
  if (!%threat == 0)
  {
  if ( 1 == CheckThreatSize(%this,%threat))
  {
   // Blast it to pieces
   %npc.openfire(%this,%threat);
  }

  }


}
// Schedules next loop depending on clocktime
%npc.loopvar=schedule(%npc.clocktime,"loop(%npc)");

}



function Soldiernpc::godumb(%npc)
{
// Cancels the loop so npc no longer thinks
cancel(%npc.loopvar);

}



// Spawntestai("AiNPC","soldiernpc","Turret","0 20 0")
function Spawntestai(%name,%datablock,%role,%spawn)
{

%npc = new AIPlayer() {
    dataBlock = "soldiernpc";
    aiPlayer = true;
  };
  MissionCleanup.add(%npc);
  AIGroup.add(%npc);

%npc.setobjectposition(%spawn);
%npc.role = %role;
%npc.setShapeName(%name);
%npc.setTransform(%spawn);
//%npc.onspawn();


// Begin looping function
  loop(%npc);
}

function Soldiernpc::fireashot(%this,%obj)
{
%obj.setImageTrigger(0,true);
}




function Soldiernpc::CheckForThreat(%this)
{
// Added check the distance
%enemy = getClosestEnemyinLOS(%this);
if (%this.maxLOSdist > VectorDist(%this.getPosition(), %enemy.getPosition()))
  {
  %enemy = getClosestEnemyinLOS(%this);
    if (%enemy == 0)
    {
    return %enemy;
    }
  return 0;
  }
return 0;
}

function Soldiernpc::CheckThreatSize(%this,%threat)
{

// Do this Algothorum later :)
// Just Engage
return 1;
}

function Soldiernpc::onTargetEnterLOS(%this,%obj)
{
   // If an aim target object is set, this method is invoked when
   // that object becomes visible.
      DebugPrint( "%this:"@%this@"~Soldiernpc::onTargetEnterLOS LOS TARGET ! (from:"@%obj@")", "onTargetEnterLOS");
   if(!isObject(%obj))
      return;
   %obj.attentionLevel = %this.attention;
   %this.schedule($MIN_ITCHY_FINGER+getRandom($MAX_ITCHY_FINGER), "pauseFire", %obj);
   %this.schedule($MIN_SCAN_GAP+getRandom($MAX_SCAN_GAP/%this.alertness), "doScan", %obj);
   %obj.setImageTrigger(0,true);
}

function Soldiernpc::onTargetExitLOS(%this,%obj)
{
   // If an aim target object is set, this method is invoked when
   // the object is no longer visible.
   DebugPrint( "%this:"@%this@"~Soldiernpc::onTargetExitLOS Fuhgetaboutit (from:"@%obj@")", onTargetExitLOS);
   if(!isObject(%obj))
      return;
   %obj.setImageTrigger(0,false);
   %obj.clearAim();
      DebugPrint( "> %obj.clearAim (from:"@%obj@")", "onTargetExitLOS");
   %obj.currentTarget = 0;  // forget this target
   %this.schedule($MIN_SCAN_GAP, "doScan", %obj);
}

function Soldiernpc::openfire(%this,%threat)
{
   // Work out aim difference
   %playPos = %this.getposition();
   %targetPos = %threat.getposition();
   %f = VectorDist(%playPos, %targetPos);
   %dif =(%f * %this.aim)/3;
   
   // not finished ****************************************************
   %this.aimat(%targetPos);
   
   schedule(%this.aimdelay,"%this.firecycle(%this)");
}

function Soldiernpc::firecycle(%this)
{
%obj.setImageTrigger(0,true);
%obj.setImageTrigger(0,false);
%obj.setImageTrigger(0,true);
%obj.setImageTrigger(0,false);
%obj.setImageTrigger(0,true);
%obj.setImageTrigger(0,false);
         
}
function Soldiernpc::pauseFire(%this,%obj)
{
      DebugPrint("%this:"@%this@"~Soldiernpc::ceaseFire (from:"@%obj@")", pauseFire);
   if(!isObject(%obj))
      return;
   %obj.setImageTrigger(0,false);
   %this.schedule($MIN_TRIGGER_HOLD+getRandom($MAX_TRIGGER_HOLD), "ceaseFire", %obj);
}

function Soldiernpc::ceaseFire(%this,%obj)
{
      DebugPrint( "%this:"@%this@"~Soldiernpc::ceaseFire (from:"@%obj@")", ceaseFire);
   if(!isObject(%obj))
      return;
   %obj.setImageTrigger(0,false);
   %obj.clearAim();
   %obj.currentTarget = 0; // forget this target
}



// My masterpiece :p
// There maybe a bit of confusion over who exactly is an enemy by the npc as no1 knows the teams relationship

function AIPlayer::getClosestEnemy(%this)
{
   DebugPrint( "%this:"@%this@"~AIPlayer::getClosestEnemy", getClosestEnemy);

   %index = -1;
   %botPos = %this.getPosition();
   %clcount = ClientGroup.getCount();
   %npcount = nameToID("Aiplayers").getCount();
   %count=%clcount+%aicount;
   %npgroup=nameToID("Aiplayers");
   %curenlist=0;


// Add to the enemy list the clients on a different team
   for(%i=0; %i < %clcount; %i++)
   {

// if there is an error return -1
   %client = ClientGroup.getObject(%i);
   if (%client.player $= "" || %client.player == 0 )
   return -1;

        if (!%client.player.team == 0)
        {
             if(!%this.team == %client.player.team)
             {
            
             %Enemylist[%curenlist]= %client.player;
             %curenlist++;
             }
        }
   }

// Add to the enemy list the NPC's on a different team
   for(%i=0; %i < %npcount; %i++)
   {
   // if there is an error return -1
   %client = ClientGroup.getObject(%i);
   if (%client.player $= "" || %client.player == 0 )
   return -1;

   %obj = %npgroup.getObject(%i);

        if (!%obj.team == 0)
        {
             if(!%this.team == %obj.team)
             {
            
             %Enemylist[%curenlist]= %obj;
             %curenlist++;
             }
        }
    }

echo("NPC "@%this@" sees "@%curenlist@" enemys after looking in front");

   for(%i = 0; %i < %curenlist; %i++)
   {
      if (%Enemylist[%i] $= "" || %Enemylist[%i] == 0 )
         echo ("NPC "@%this@"'s enemy list is courrupt");
      %playPos = %Enemylist[%i].getPosition();

      %tempDist = VectorDist(%playPos, %botPos);
      if(%i == 0) 
      {
         %distance = %tempDist;
         %index = %i;
      }
      else 
      {
         if(%distance > %tempDist) 
         {
            %distance = %tempDist;
            %index = %i;
         }
      }
   }
   return %index;
}
#7
12/18/2005 (1:16 pm)
// Another of my masterpiece :p
// There maybe a bit of confusion over who exactly is an enemy by the npc as no1 knows the teams relationship

function AIPlayer::getClosestEnemyInLOS(%this)
{
   DebugPrint( "%this:"@%this@"~AIPlayer::getClosestEnemy", getClosestEnemy);

   %index = -1;
   %botPos = %this.getPosition();
   %clcount = ClientGroup.getCount();
   %npcount = nameToID("Aiplayers").getCount();
   %count=%clcount+%aicount;
   %npgroup=nameToID("Aiplayers");
   %curenlist=0;


// Add to the enemy list the clients on a different team
   for(%i=0; %i < %clcount; %i++)
   {

// if there is an error return -1
   %client = ClientGroup.getObject(%i);
   if (%client.player $= "" || %client.player == 0 )
   return -1;

        if (!%client.player.team == 0)
        {
             if(!%this.team == %client.player.team)
             {
                  if ( !%obj.CheckArcOfSight(%target.player) )
                  {
                  
                  %Enemylist[%curenlist]= %client.player;
                  %curenlist++;
                  
                  }
             }
        }
   }

// Add to the enemy list the NPC's on a different team
   for(%i=0; %i < %npcount; %i++)
   {
   // if there is an error return -1
   %client = ClientGroup.getObject(%i);
   if (%client.player $= "" || %client.player == 0 )
   return -1;

   %obj = %npgroup.getObject(%i);

        if (!%obj.team == 0)
        {
             if(!%this.team == %obj.team)
             {
            
             %Enemylist[%curenlist]= %obj;
             %curenlist++;
             }
        }
    }

echo("NPC "@%this@" sees "@%curenlist@" enemys after looking in front");

   for(%i = 0; %i < %curenlist; %i++)
   {
      if (%Enemylist[%i] $= "" || %Enemylist[%i] == 0 )
         echo ("NPC "@%this@"'s enemy list is courrupt");
      %playPos = %Enemylist[%i].getPosition();

      %tempDist = VectorDist(%playPos, %botPos);
      if(%i == 0) 
      {
         %distance = %tempDist;
         %index = %i;
      }
      else 
      {
         if(%distance > %tempDist) 
         {
            %distance = %tempDist;
            %index = %i;
         }
      }
   }
   return %index;
}


// -----------------------------
// Characters ------------------
// -----------------------------
datablock PlayerData(Terroristnpc)
{
className = "Soldiernpc";
   maxForwardSpeed = 10;
   maxBackwardSpeed = 8;
   maxSideSpeed = 10;
   aim = 6;
   aimDelay = 20;

};

// Brittish
datablock PlayerData(Brittishnpc : Soldiernpc)
{
   className = "Soldiernpc";
   maxForwardSpeed = 10;
   maxBackwardSpeed = 8;
   maxSideSpeed = 40;
   aimDelay = 100;
   aim = 2;
};

datablock PlayerData(SASnpc : Soldiernpc)
{
   className = "Soldiernpc";
   maxForwardSpeed = 10;
   maxBackwardSpeed = 8;
   maxSideSpeed = 10;
   aimDelay = 10;
   aim = 1.2;
};
// Classic commando double tap
function SASnpc::firecycle(%this)
{
%obj.setImageTrigger(0,true);
%obj.setImageTrigger(0,false);
%obj.setImageTrigger(0,true);
%obj.setImageTrigger(0,false);
}

// American
datablock PlayerData(Americannpc : Soldiernpc)
{
   className = "Soldiernpc";
   maxForwardSpeed = 10;
   maxBackwardSpeed = 8;
   maxSideSpeed = 10;
   aimDelay = 30;
   aim = 2.5;
};

function SASnpc::firecycle(%this)
{
%obj.setImageTrigger(0,true);
%obj.setImageTrigger(0,false);
%obj.setImageTrigger(0,true);
%obj.setImageTrigger(0,false);
%obj.setImageTrigger(0,true);
%obj.setImageTrigger(0,false);
}
#8
12/20/2005 (7:10 am)
Any Help? the application just closes and on older versions comes up with the error report
#9
12/30/2005 (1:15 pm)
Its strange the TSE Demo build compiles & executes it fine but doesnt work on anything else
Ive tried it on the following builds:

Advanced 3D GP 's build
TGE 1.4 original
TGE 1.3 original
TGE 1.3 modified
RTS_Debug original
Synapselighting pack demo
TSE demo - It Works!!!

Is there some reason why it should,
Help plz - thks
#10
12/31/2005 (6:50 pm)
When you run in a debugger, what is the callstack?
#11
01/02/2006 (6:22 am)
Ahh, I have just discovered it said this when running in debug mode on tourquedev
Warning: (c:\dev\rts_svn\trunk\engine\gui\guitypes.cc @ 293) GuiControlProfile: requested gui profile (GuiContentProfile) does not exist.
ill see if it says the same for 1.4, even though im getting TSE soon :)

actually thats probably because it was the RTS engine
#12
01/10/2006 (7:31 am)
Ok it seems like ive had quite a few problems, Ive realised wats wrong with that source file it was the datablocks at the bottom. But i now have the shader engine and it has that same error I posted above a missing gui profile and usually breaks when it executes and gui file, any ideas why?

btw it does this whatever profile i set it as i changed it to guidefaultprofile and it still breaks