Jump to content

Home

NPC Typing Script


dangen77

Recommended Posts

I'm working on a large mod called Nimosa: dangen77's KOTOR Mods . 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!!!

Link to comment
Share on other sites

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:

 

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

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

   [color=PaleGreen]// Do the work. Second param is the animation to play to simulate working on the object.[/color]
   ST_WorkOnObject(oComputer, ANIMATION_LOOPING_USE_COMPUTER);

   [color=PaleGreen]// Trigger user-defined heartbeat event, if enabled.[/color]
   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).

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

 

sshot.jpg

 

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!!!

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...