PDA

View Full Version : Spawning an NPC


Penguin Unit
06-17-2007, 08:03 PM
Hello,

The warp and cheat band has a function that causes an NPC to spawn when you use it. However, I browsed the script and found nothing indicating an NPC file for spawning. What I wanted to know is what lines I need to put into a script to make it spawn something, and then attach it to an armband item.

Thanks if any of you can help.

stoffe
06-18-2007, 07:18 AM
The warp and cheat band has a function that causes an NPC to spawn when you use it. However, I browsed the script and found nothing indicating an NPC file for spawning. What I wanted to know is what lines I need to put into a script to make it spawn something, and then attach it to an armband item.


You usually use the CreateObject() script function for this. It can be used to create other types of objects (items, placeables etc) than creatures/NPCs as well. You use it like:


void main() {
location lDestination = Location(Vector(0.0, 0.0, 0.0), 0.0);
object oNew = CreateObject(OBJECT_TYPE_CREATURE, "template", lDestination);
}


0.0 is the X coordinate in the world to spawn the creature at, 0.0 is the Y coordinate, 0.0 is the direction the creature should face when spaned (0-359 degree angle), the OBJECT_TYPE_CREATURE constant is used to spawn creatures and NPCs (there are other OBJECT_TYPE_ constants to spawn other object types) and "template" is the name of the .UTC file, without the file extension, of the template to spawn the creature from.

(You can't affect the Z-coordinate, or elevation, of creatures and NPCs in the game world, so I left that out above. The third number in the vector sets that otherwise, if you spawn placeables and the like.)

If you don't know the exact coordinates where the creature should be spawned and just want to spawn it right next to the player you can use GetLocation() instead to get the coordinates of an existing object in the game world, like:


void main() {
location lDestination = GetLocation(GetFirstPC());
object oNew = CreateObject(OBJECT_TYPE_CREATURE, "template", lDestination);
}

Penguin Unit
06-18-2007, 10:50 AM
Great, thanks. Can any of you now tell me how I would attach it to an armband or some other item that spawns the NPC I want when used? Man, I wish I was better at this, so I wouldn't have to bug you guys.

stoffe
06-18-2007, 11:09 AM
Great, thanks. Can any of you now tell me how I would attach it to an armband or some other item that spawns the NPC I want when used? Man, I wish I was better at this, so I wouldn't have to bug you guys.

Scripts fired from armbands are technically "spells" (along with force powers, grenades, rockets, medkits, stims etc), so you'll have to add a new line to the spells.2da file for your armband. On this line you set the name of your script in the impactscript column.

Then, in the UTI template of your armband you add an Activate Item property and set the Subtype field to the line number of the row you just added to spells.2da, and the Value field to Unlimited uses. This will make the armband trigger the spell when you activate it, which fired the impact script.

tk102
06-18-2007, 11:13 AM
General tip: Have a look at what others have done with armband mods while looking through this spells.2da tutorial (http://www.lucasforums.com/showthread.php?t=130898).

Penguin Unit
06-18-2007, 12:10 PM
With the script, I keep getting this thing about a syntax error and if I play around with it I get this thing below:

"To many arguments specified in call to GetFirstPC"

"Required argument missing in GetLocation"

I have the script just as you have it, with the NPC's file name (without extension) in place. What am I doing wrong?

tk102
06-18-2007, 09:54 PM
Try copy/pasting stoffe's script while only editing what's in between quotation marks.

Penguin Unit
06-18-2007, 11:02 PM
Yeah, that worked. Thanks.