How do YOU spawn NPC's?
by Infinitum3D · in Torque Game Engine · 03/11/2009 (3:04 pm) · 6 replies
I can spawn NPC's but I have no idea what I'm doing, and I'm sure there's a better way.
I have the RPGDialog resource working, and I use it to spawn NPC's. I have a file, SpawnNPCs.cs, and I hard code the coordinates of each and every NPC. Then I exec this file in game.cs and TGE loads all my NPC's when the game loads.
Is this efficient? Acceptible? Completely wrong?
What's a better way? How do the pro's do it?
Discuss, please :)
Thanks!
Tony
I have the RPGDialog resource working, and I use it to spawn NPC's. I have a file, SpawnNPCs.cs, and I hard code the coordinates of each and every NPC. Then I exec this file in game.cs and TGE loads all my NPC's when the game loads.
Is this efficient? Acceptible? Completely wrong?
What's a better way? How do the pro's do it?
Discuss, please :)
Thanks!
Tony
#2
So i think your solution is completely correct.
03/14/2009 (1:59 am)
A spawnsphere is nothing more than a placeholder. This is a visual representation where the player will be when a mission starts respectively where the player's respawn point is. So i think your solution is completely correct.
#3
This is a basic layout of what happens in my spawn function. In my code it is much more complex
03/14/2009 (5:58 am)
spawnai(team,marker index in a simgroup,type);This is a basic layout of what happens in my spawn function. In my code it is much more complex
function spawnai(%team, %markerindex, %type)
{
%AI = new AIPlayer() {
datablock = %type;
position = Path1.getObject(%markerindex).getPosition();
team = %team;
};
%AI.think(); // Begins the thinking loop
}
#4
@Bryce,
Thanks! So you place markers (using the world editor) and then the ai is spawned at a 'random' marker based on type? Do I understand that correctly?
I like that idea. Its easy to go into a mission and lay down a couple dozen markers, and move them around in the editor. A lot easier than finding dozens of specific coordinates.
Anyone have other ideas, suggestions or comments?
Thanks again!
Tony
03/14/2009 (9:18 am)
Thanks Thomas! I appreciate your help.@Bryce,
Thanks! So you place markers (using the world editor) and then the ai is spawned at a 'random' marker based on type? Do I understand that correctly?
I like that idea. Its easy to go into a mission and lay down a couple dozen markers, and move them around in the editor. A lot easier than finding dozens of specific coordinates.
Anyone have other ideas, suggestions or comments?
Thanks again!
Tony
#5
Using a marker system has allowed me to add more advanced functionality to AI Players more easily. With a spawn marker, you can manage respawning (certain number of spawns, how many NPCs to drop per respawn to create waves of enemies), have a moveDestination that tells the NPC where to go at spawn, etc. I strongly advise using a spawn marker system.
04/01/2009 (5:22 am)
Yes, I create a path called Path1, and each marker within that group is a spawn point. So, I can call spawnAI(1,2,1);. This will spawn an AI Player on team 1, at the position of the second marker belonging to Path1, and with type 1 (don't worry about this, it's specific to my spawn function).Using a marker system has allowed me to add more advanced functionality to AI Players more easily. With a spawn marker, you can manage respawning (certain number of spawns, how many NPCs to drop per respawn to create waves of enemies), have a moveDestination that tells the NPC where to go at spawn, etc. I strongly advise using a spawn marker system.
#6
Oh, and Infinitum, in another (RPG) project I'm doing it exactly as you are, using the spawn function from RPGDialog =)
04/10/2009 (6:45 am)
bryce, you just gave me an idea that might get me bots spawning on different teams at beginning of each "round"...Oh, and Infinitum, in another (RPG) project I'm doing it exactly as you are, using the spawn function from RPGDialog =)
Torque Owner Infinitum3D
in spawnNPC.cs my spawn script is this
//--Spawn an orc--//
SpawnNPCorc("anNPCorc","200 -744 108 0 0 1 180");
This spawns an orc with
name=anNPCorc
at location X=200 Y=-744 Z=108
with a rotation of 180 degrees around the Z-axis.
Since I have the RPGDialog resource working, I can add dialog script, photo, and start question as follows,
SpawnNPCorc("anNPCorc", merchant1, "orc1", 1, "200 -744 108 0 0 1 180");
Now we spawn an orc with
name=anNPCorc
dialog script=merchant1.dlq
photo=orc1.png
start question=question#1 of dialog script merchant1.dlq
location=200 -744 108
rotation=0 0 1 180
All this works, but is there a more efficient way? Is this how everyone does it, or should I be using spawnSpheres? or are spawnSpheres only for players?
Any hints, tips, ideas, or suggestions? If I'm doing it right, then please let me know. If I'm wrong, please tell me how.
Thanks!
Tony