View Full Version : NPC Typing Script

05-26-2007, 01:25 AM
I'm working on a large mod called Nimosa: dangen77's KOTOR Mods (http://giicgo.tzo.com/kotor) . Anyways, I suck at scripting and am pretty good at most other areas of modding. I need a simple script, but don't know how to write it. I'm sure I could learn the syntax, and eventually I will, but I haven't done any programming in 5 or 6 years and I just don't have time to learn it right now.

Anyways, I need an OnSpawn script that will make an NPC work with their hands, like on a computer or on a workbench, etc... I'm sure this is very simple, but I don't know how to do it. I've tried reusing the "Kiph" script from Onderon Royal Palace, but this script also makes the NPC change direction. I need one that will do the same thing, without the direction change, I want to use this script for several NPC's who aren't all facing the same direction.

If someone could please write this script and post it here, I would really appreciate it. Foot notes of how it works would be even better, for the whole community, but I'd be as happy with just the script Eventually, I'll set up a team for this mod (once I've finished the basics like NPCs, placeables, area retexturing, etc...) and I'll really need scripters. Whoever does this, will definately be on my list!

Thanks in advance!!!

05-26-2007, 07:01 AM
Anyways, I need an OnSpawn script that will make an NPC work with their hands, like on a computer or on a workbench, etc...

It's pretty risky to use an OnSpawn script for something like that. If something interrupts them they would just stand around after that. I'd use a heartbeat script for it instead which re-issues the work-action continually. Something like this might work:

// Support function, move close to an object, face it and play an animation for one round.
void ST_WorkOnObject(object oComputer, int iAnimation, float fMaxDistance=1.5) {
// Don't do any of this if we're in combat, in conversation or if killed.
if (GetIsObjectValid(oComputer)
&& !GetIsInCombat(OBJECT_SELF)
&& !GetIsInConversation(OBJECT_SELF)
&& !GetIsDead(OBJECT_SELF))
// If we're not moving around, work on our object.
if (GetCurrentAction() != ACTION_MOVETOPOINT) {
// If not close enough (1.5 meters) to the work object, move to it first.
if (GetDistanceToObject(oComputer) > fMaxDistance) {
ActionForceMoveToObject(oComputer, TRUE);
// We're close enough, so face the object to work on and play an animation for 1 round.
else {
PlayAnimation(iAnimation, 1.0, RoundsToSeconds(1));

void main() {
// Set this to the Tag of the object they will work on.
object oComputer = GetObjectByTag("ObjectToWorkOn");

// Do the work. Second param is the animation to play to simulate working on the object.

// Trigger user-defined heartbeat event, if enabled.
if (GetLocalBoolean(OBJECT_SELF, 28)) {
SignalEvent(OBJECT_SELF, EventUserDefined(1001));

This is meant to be used as an OnHeartbeat event script set on a creature/NPC. Replace the part in yellow with the Tag of the object the NPC should work on (usually a computer terminal or workbench placeable or something like that).

05-26-2007, 04:49 PM
Thanks Stoffe!!! One more question. The NPCs that will be using this script are set to uninterruptable in their .utc file. Do you still think it's better to use the On Heartbeat? If so, why? I don't know anything about the OnHeartbeat script, have never used it, and would like to learn more about it.

Thanks again!

05-27-2007, 04:43 PM
This script works great, but I still have a problem. Can this be done without the need for a specific placeable? I have some NPC's who are working on tables that are part of the Area Model. Here's a photo to better explain.


Also, because this script refers to a specific placeable, I would have to create unique placeables and NPCs, but I was planning on using one NPC and one placeable many times. If the script didn't rely on a specific placeable, it would solve both of these problems. I'm not to worried about them moving to the placeable, as they are already in front of it and they have the "Reorient on PC" set to off, so interruptions shouldn't be a problem either.

Thanks Again!!!

05-27-2007, 06:00 PM
You could try changing this line
object oComputer = GetObjectByTag("ObjectToWorkOn");
to this
object oComputer = GetNearestObject(OBJECT_TYPE_PLACEABLE);
or this
object oComputer =GetNearestObjectToLocation(OBJECT_TYPE_PLACEABLE, locSomeVicinity); (in the latter you'd have to declare locSomeVicinity as a location and assign coordinates)