Basic npc/placeable spawn scripts:
Placeable:
void main()
{
CreateObject(OBJECT_TYPE_PLACEABLE, "container_templateresref", Location(Vector(0.00,0.00,0.00), 0.0));
}
Creature:
void main()
{
CreateObject(OBJECT_TYPE_CREATURE, "creature_templateresref", Location(Vector(0.00,0.00,0.00), 0.0));
}
- container_templateresref and creature_templateresref correspond to the name of the *.utc or *.utp file for your creature/placeable.
-(0.00, 0.00, 0.00), 0.00 correspond respectively to the x y z coordinates and the orientation in degrees . For Kotor I, do a whereamI cheat to get them . For Kotor II, you will need the whereami armband available here:
http://www.starwarsknights.com/tools.php)
How to add your items to an existing container that does not have a unique tag?
If there are other containers with the same tag in the game and don't want to end up adding your custom items in all the other ocntainers, you can use the GetNearestObjectToLocation function to specify a location and then target the nearest object to that location:
// 228: Get the nNth object nearest to lLocation that is of the specified type.
// - nObjectType: OBJECT_TYPE_*
// - lLocation
// - nNth
// * Return value on error: OBJECT_INVALID
object GetNearestObjectToLocation (int nObjectType, location lLocation, int nNth=1);
here is a sample script:
void main () {
//the coordinates can be obtained with the whereami armband (
http://www.starwarsknights.com/tools.php).
//Just stand the closest as you can from the container you want to use..
vector vecCont;
vecCont.x = 0.0; // x coordinate goes here
vecCont.y = 0.0; // y coordinate goes here
vecCont.z = 0.0; // z coordinate goes here
int nIdx = 1;
location locCont = Location(vecCont, 0.0);
object oContainer = GetNearestObjectToLocation(OBJECT_TYPE_PLACEABLE, locCont, nIdx);
while (GetIsObjectValid(oContainer)) {
if (GetTag(oContainer) == "my_object_tag") {
CreateItemOnObject("item_template", oContainer);
CreateItemOnObject("item_template", oContainer);
break;
}
oContainer = GetNearestObjectToLocation(OBJECT_TYPE_PLACEABLE, locCont, ++nIdx);
}
}
How to spawn a container when I enter an area:
(you can always decompile the script and add the lines to spawn a container or you can use the easy following method which gives the same results at the end)
1. extract the On_enter script for the module. Check the .are file if you are unsure. Per example, when you enter the bar in NAr Shadaa, the script would be: a_306onenter.ncs
2. rename the script you just extracted to something else: exmaple old__a_306onenter.ncs
3. Create a new script:
void main()
{
object oEntering = GetEnteringObject();
object oPC=GetFirstPC();
if (GetIsPC(oEntering))
{
//check if the object is already there to avoid multiple objects
if (!GetIsObjectValid(GetObjectByTag("o")))
{
//replace the (0.00,0.00,0.00) by the xyz coordinates where you want to spawn the container.
//for TSL, use the whereami armband
http://www.starwarsknights.com) to get the coordinates. For kotor use the whereami cheat
oContainer= CreateObject(OBJECT_TYPE_PLACEABLE, "container_templateresref", Location(Vector(0.00,0.00,0.00), 0.0));
}
// Fire the old onenter script that we renamed at step 2:
ExecuteScript("old_a_306onenter", OBJECT_SELF);
}
}
4. Save your script as a_306onenter.nss (the original name of the On enter script we extracted) and compile.
How to spawn a npc in an area:
It works exactly the same as a container:
1. extract the On_enter script for the module. Check the .are file if you are unsure. Per example, when you enter the bar in NAr Shadaa, the script would be: a_306onenter.ncs
2. rename the script you just extracted to something else: exmaple old__a_306onenter.ncs
3. Create a new script:
void main()
{
object oEntering = GetEnteringObject();
object oPC=GetFirstPC();
if (GetIsPC(oEntering))
{
//check if the object is already there to avoid multiple objects
if (!GetIsObjectValid(GetObjectByTag("o")))
{
//Note that the script uses OBJECT_TYPE_CREATURE instead of OBJECT_TYPE_PLACEABLE - that's the only difference with the container:
CreateObject(OBJECT_TYPE_CREATURE, "my_npc_templateresref", Location(Vector(43.41,-0.28,9.66), 0.0));
// this portion is optional and will only work if you spawn the npc not too far from where you enter the area - careful if there are scripted cutscenes too.
// You can also use the On perception event instead of the on enter script for this.
NoClicksFor(0.5);
//Make the NPC walk towards you:
AssignCommand((GetObjectByTag("my_npc_tag")),ActionMoveToObject(oPC));
//Make the npc initiate the converstation after approcahing you:
AssignCommand ((GetObjectByTag("my_npc_tag")), ActionDoCommand(ActionStartConversation(oPC)));
}
ExecuteScript("old_a_306onenter", OBJECT_SELF);
}
}
4. Save your script as a_306onenter.nss (the original name of the On enter script we extracted) and compile.
How to equip/unequip a npc with new stuff when entering an area:
Again, it's very similar to the above:
1. extract the On_enter script for the module. Check the .are file if you are unsure. Per example, when you enter the bar in NAr Shadaa, the script would be: a_306onenter.ncs
2. rename the script you just extracted to something else: exmaple old_a_306onenter.ncs
3. Create a new script:
void main ()
{
object oEntering = GetEnteringObject();
object oNPC = GetObjectByTag("my_npc_tag", 0); //identify the targetted npc
object oGun1 = GetItemInSlot(INVENTORY_SLOT_RIGHTWEAPON ,oNPC); // identify the weapon slot
if (GetIsPC(oEntering)){
object oNewgun = CreateItemOnObject("s_w_rptnblstr09",oNPC);//create the new object on the npc
if (GetIsObjectValid (oGun1)) //checks if the slot is empty or not
{
DestroyObject(oGun1);// if slot is not empty, then remove the previous object from inventory - this will destroy the previous object not just unequip it
}
AssignCommand (oNPC, ActionEquipItem(oNewgun, INVENTORY_SLOT_RIGHTWEAPON)); //equip the new object
ExecuteScript("old_a_306onenter", OBJECT_SELF); //run hte old OnEnter script
}
}
4. Save your script as a_306onenter.nss (the original name of the On enter script we extracted) and compile.
The other inventory slots are:
int INVENTORY_SLOT_HEAD = 0;
int INVENTORY_SLOT_BODY = 1;
int INVENTORY_SLOT_HANDS = 3;
int INVENTORY_SLOT_RIGHTWEAPON = 4;
int INVENTORY_SLOT_LEFTWEAPON = 5;
int INVENTORY_SLOT_LEFTARM = 7;
int INVENTORY_SLOT_RIGHTARM = 8;
int INVENTORY_SLOT_IMPLANT = 9;
int INVENTORY_SLOT_BELT = 10;
int INVENTORY_SLOT_CWEAPON_L = 14;
int INVENTORY_SLOT_CWEAPON_R = 15;
int INVENTORY_SLOT_CWEAPON_B = 16;
int INVENTORY_SLOT_CARMOUR = 17;
int INVENTORY_SLOT_RIGHTWEAPON2= 18;
int INVENTORY_SLOT_LEFTWEAPON2 = 19;