Game Development Community

Using different Models with AIGuard

by Tim Lang · in Technical Issues · 08/21/2007 (11:41 pm) · 1 replies

So I made a modification to AIGuard that will allow you to add the name of a model as a dynamic field in the AIGuardMarker and use a different model with the same AI...

Here's how it works:

First, replace this code:

function AIGuard::spawn(%name, %obj)
{
  
   // Create the demo player object
  /dataBlock = GuardPlayer;

with this:
function AIGuard::spawn(%name, %obj)
{
    echo(%obj.Character);
    %myChar = %obj.Character;
    
       switch$ (%myChar)
   {
      case "Kork":
         // Let the player fly around
         %datablock = GuardPlayer;
         
      case "Skeleton":
         %datablock = SkeletonGuardPlayer;
         
      default :
         echo("error in switching obj char");
         %datablock = GuardPlayer;

   }
   // Create the demo player object
   %player = new AIGuard() {
  // dataBlock = GuardPlayer;
  datablock = %datablock;

Step 2:
modify the cases to be the names of the characters you want to use. Add cases as necessary

Step 3:

Copy aiPlayer.cs from data/server/scripts and rename it something you'll remember for every new character you want to include

Step 4:
Rename the GuardPlayer datablock in all your new aiPlayer.cs scripts and add them after the %datablock in the cases.

Step 5: (forgot this one too!) Change the shapeFile in your new aiPlayer.cs script to point to the model you want to use

Step 6:
add an exec (./"mynewplayer.cs"); to your server/scripts/game.cs file. (I put mine after exec(".aiPlayer"))

Step 7:
Place your AIGuardMarkers as normal.

Step 8:
Add a new field in your AIGuardMarkers called "Character" and put the case name of the character you want to use in there (without quotes)

Step 9:
Save, and reload the level

Step 10:
Sit back, and drink a beer!

#1
12/30/2007 (7:15 pm)
I've been trying to find out how to use different models for the AI, and it looks like a found the answer :-). Thanks for posting it.