PDA

View Full Version : Help with script spawning NPCs (was: will this....)


Master Orran
10-25-2006, 05:55 PM
if i use this script will this spawn atton, kreia and t3m4 in the same location in one script?

// Generated by jmac7142's KotOR Script Generator
// Spawn Creature / Open Merchant

#include "k_inc_debug"
#include "k_inc_utility"

void main()
{
float x = 0;
float y = 0;
float z = 0;
float r = Orientation;

vector vCre = Vector(x, y, z);
location lCre = Location(r, vCre);

if (GetIsPC(GetEnteringObject()))
{
object oCre = CreateObject(OBJECT_TYPE_CREATURE, "p_Atton, p_Kreia, p_T3M4", lCre);
}
else
{
return;
}

}

or

// Generated by jmac7142's KotOR Script Generator
// Spawn Creature / Open Merchant

#include "k_inc_debug"
#include "k_inc_utility"

void main()
{
float x = 0;
float y = 0;
float z = 0;
float r = Orientation;

vector vCre = Vector(x, y, z);
location lCre = Location(r, vCre);

if (GetIsPC(GetEnteringObject()))
{
object oCre = CreateObject(OBJECT_TYPE_CREATURE, "p_Atton", lCre);
object oCre = CreateObject(OBJECT_TYPE_CREATURE, "p_Kreia", lCre);
object oCre = CreateObject(OBJECT_TYPE_CREATURE, "p_T3M4", lCre);
}
else
{
return;
}

}

Moderator note: Changed thread title. Using more descriptive thread titles will increase the chance that someone who can answer your questions will read the thread. Please do so. :) ~M

goldberry
10-25-2006, 06:16 PM
Please use [/CODE] and [CODE] to type scripts. I reversed the order, because it was showing as though i was writing code :P

That might work, but I'm no scripting guru, so I can't be certain. Your best bet is to kick it into the game and try it out.

stoffe
10-25-2006, 06:18 PM
if i use this script will this spawn atton, kreia and t3m4 in the same location in one script?


No, since neither of them will compile. You assign Orientation to the variable r but it has never been declared, and you try to assign the integer value 0 to the three float variables x, y and z. You'll either have to explicitly say it's a float, or add a decimal separator (0f or 0.0).

Further you have the parameters to the Location() function call in the wrong order, you should specify a coordinate vector as the first parameter and a facing angle as the second.

Also the first script wouldn't spawn anything since there is no creature template with the ResRef p_Atton, p_Kreia, p_T3M4 since it is an invalid ResRef (it's too long and contains non-alphanumerical characters).

Unless you intend to spawn the characters at coordinates 0, 0, 0 you'll need to set where in the area they should spawn as well.

The script also contains a bunch of unnecessary code, which while it's not an error its... unnecessary. :)
You don't need either of the two include files you include since you don't use any functions or globals defined within them.
You declare lots of variables (x, y, z, r, vCre) that you only use once and might just as well put the constant values as function parameters directly.
You assign the created NPCs to the oCre variable but you never use it for anything. And you declare the variable three times in the same scope in the second script.
You don't check if the creature triggering the script should run it until you've already declared a bunch of variables and assigned values to them. And you don't need the else statement of the PC check, since the script would just end there anyway.


Finally, the script as it is laid out would only work as an OnEnter script, since the GetEnteringObject() doesn't work in other types of scripts. If that's what you need it for then that's OK though. :)

You could do the same like:
void main() {
// ST: These two lines are only needed for OnEnter event scripts.
if (GetEnteringObject() != GetFirstPC())
return;

// ST: Destination coordinates (x,y,z) within the area need to be set here.
location lCre = Location(Vector(0.0, 0.0, 0.0), 0.0);
CreateObject(OBJECT_TYPE_CREATURE, "p_atton", lCre);
CreateObject(OBJECT_TYPE_CREATURE, "p_kreia", lCre);
CreateObject(OBJECT_TYPE_CREATURE, "p_t3m4", lCre);
}

goldberry
10-25-2006, 06:20 PM
Okay, I'll change my answer :P no it will not work :D

EDIT: Stoffe's version's a little more compact :P My programming teach said it's always best to write as little as possible when coding; as stoffe just proved :D

Master Orran
10-25-2006, 06:22 PM
i used the script generator for it.

goldberry
10-25-2006, 06:24 PM
? A script generator ?
Was it custom for kotor? i think if that's what it churned out then you should stay away from it :P

Master Orran
10-25-2006, 06:25 PM
for kotor 2