Game Development Community

aiSpawnAIPlayer

by J. Donavan Stanley · 06/30/2003 (8:36 am) · 9 comments

Download Code File

After apply this patch you will find a static member function of AIPlayer ("spawnAIPlayer") as well as script function ("aiSpawnAIPlayer") that vastly simplifies getting AIPlayer derrived objects into your game. The players will be added to a group called "aiGroup" if it exists or the MissionGroup if not.

The syntax for the two functions are the same. Only the first two parameters are required, the rest have defaults, or can be left empty safely. They are in order:

dataBlock - The datablock to use (i.e. LightMaleHumanArmor ).
transform - The initial location of the AIPlayer (passed to setTransform).
objectName - The name of the object ( i.e. "Bot001" );
shapeName - The name of the shape (i.e. "Bob") this will show up of the AIPlayers head if you use a GuiShapeNameHud.
className - The name of the C++ class to create. This defaults to "AIPlayer". If you have your own custom AIPlayer derrived class you'd like created instead simply pass in the name of the C++ class to create.


Installation:
1) Apply this patch from the engine directory.
2) Recompile.

As Melv would say "Easy squeezy lemon peezy". (For some reason that phrase has been suck in my head all day long Melv!)

#1
06/30/2003 (10:54 am)
Patch file not available?
#2
06/30/2003 (12:39 pm)
Bad Link Again??

The page you requested was not found.
We're sorry. The Web address you entered is not a functioning page on our site. Please check the URL for proper spelling and capitalization.

Click here to visit the GarageGames home page
#3
06/30/2003 (2:39 pm)
Here's a non-GG link to download the patch.
#4
07/04/2003 (10:27 pm)
Great stuff! Thanks!
#5
08/29/2003 (11:11 am)
The GG link has been fixed...
#6
09/11/2003 (12:44 pm)
Hi Donavan,

I don't know if this bug was of my own doing, but I noticed a weird bug when I used this code (I have any almost fresh copy of HEAD).

If the OnAdd script that gets called by player->registerObject (in spawnAIPlayer) has a call to echo in it, then the
StringTableEntry transf argument from the other spawnAIPlayer gets overwritten with new data. Thus the location the player is added to is messed up.

After tracing the actual overwrite to line 981 of console/compiledEval.cc:
STR.setStringValue(curStringTable + code[ip++]);

It looks like there is a problem when using a string passed as an argument from a script, after another script function using strings is called from the C++ code(Does that make any sense?).

I know it's not a bug in your code (it seems to have something to do with the evaluation argument stack), but I thought I'd mention it because it caused me a fair amount of frustration.

-Pascal
#7
09/25/2003 (2:15 am)
Hmmm I'll put this on my list of things to look at.
#8
02/26/2005 (7:21 pm)
Okay maybe I'm an idiot but I've saved the file in my engine directory, then issued patch -p0 aispawnplayer.patch (which is what I renamed it to) on the command line from a terminal opened in the engine directory.

And I get nothing...
Little help here please?
#9
03/01/2005 (6:26 pm)
Disregard, I am being an idiot, the patch is too old to work :(