View Full Version : Scripting question: Simple Spawn Script

Nick Vader
07-05-2010, 07:14 AM
Anyone care to give me some advice on spawning via script ? Thnx.

07-05-2010, 11:35 AM
There is a tutorial in the scripting section but i'll do one here.

First off you'll need to extract the on_enter script for the module you want to spawn an npc in. So, go to RIM's >>> Modules >>> and choose the module you're working in. Then go to Scripts, Compiled and find the on enter script. For example k_ptat17af_enter.ncs.

Then extract it to a location of your choice. Find where you extracted it to and add "_old" onto the filename (minus the quotes) before the .ncs . Then create a new script using the Kotor Tool Text Editor. Type this:

void main()
// Check if it's the player entering the trigger, and that it hasn't already fired
if (!GetLocalBoolean(OBJECT_SELF, 40) && (GetEnteringObject() == GetFirstPC())) {

// Make sure the trigger only fires once.
SetLocalBoolean(OBJECT_SELF, 40, TRUE);

object oNPC1 = CreateObject(OBJECT_TYPE_CREATURE, "your_npc_tag",
Location(Vector(loc1,loc2,loc3), orientation));


ExecuteScript("on_enter_old", OBJECT_SELF);


Replace "your_npc_tag" with the tag of your npc .utc file. The tag should be the same as the filename. Then replace loc1, loc2 and loc3 with the numbers you get with the 'whereami' cheat in K1 or the whereami armband in K2. The orientation is which way the character is facing. This is not shown anywhere so just play around. Think of it as a circle so for example no bigger than 360.0. Then replace "on_enter_old" with the script that you renamed earlier. The part at the top just makes sure that only one is created. Otherwise you could end up with a whole module full of one npc. o_O.

Then go up to the script menu and click script is for whatever version you are using and then click Script Compile. It may ask you to save your script first in which case save it with the same name as the old on_enter script just with the _old. It will then flash up saying completed or errors. If you have any errors post your script and errors here and I'll do what I can to help. It creates a .ncs file that can be read by KOTOR.

Then put all the files in the Override:

npc file (.utc)
new on enter script (.ncs obtained after compiling)
old on enter script (.ncs the one you extracted and renamed)

Now when you enter the module your npc should appear. Like I said you may have to play around with the orientation to get it facing the right way. If you have any scripting errors just post em and I'll see what I can do.

You don't have to have use an on_enter script. You could create a script that runs when you kill a different npc or talk to someone but there is more on that in the scripting section.

Check this out as well:


Hope I helped.


Nick Vader
07-05-2010, 12:10 PM
Hell, don't start confusing me with things I don't need to know about. You see dude, I want the placeable to spawn after a dialog entry... Not by entering the module. A little mixup here I think. But, anyway, thnx for the script. And I forgot to say it was a placeable...

EDIT: I found this (http://www.lucasforums.com/showthread.php?s=&threadid=143536). Thnx for the linkie.

All I wanted was this: void main()
CreateObject(OBJECT_TYPE_PLACEABLE, "container_templateresref", Location(Vector(0.00,0.00,0.00), 0.0));

07-05-2010, 12:25 PM
Ohhhhhhhhh, sorry. Happy to help anyway.

Qui-Gon Glenn
07-08-2010, 01:10 PM
^^^ Never apologize for offering help!

Nick's tone was a little impetuous... look dude, when people are trying to help you, at least consider being polite.

As for what was originally asked for, TimBob, you did a nice job explaining the workings of the on_enter script and how to add your own on-enter conditions. I thank you, it refreshes my memory and that is always good!