Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
OpenSim NPC NPC_Router  

NPC_Router

This script re-directs any NPC that collides with the object to a random destination selected from an internal list.
Once the routers are placed, a text label display can be toggled by touching it. This makes it easy to collect locations
Routers should be placed to facilitate collisions with the avatar capsules.
The real trick of this router design is the rotate calculations. These prevents the NPCs from walking backwards when assigned new targets "behind" them.

License:
You are free:
to Share — to copy, distribute and transmit the work
to Remix — to adapt the work
to make commercial use of the work
See http://creativecommons.org/licenses/by-sa/2.5/

Category: OpenSim NPC
By : DZ
Created: 2013-08-02 Edited: 2013-08-02
Worlds: OpenSim

the Zip file

Download all files for NPC_Router
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. NPC_Router_1.lsl
1 // OpenSimian NPC router
2 // Douglas Osborn MOSES version 2013May06
3
4 // Assign random destination to a NPC that collides with volume detect object
5 // Drop the script in a prim, resize and position the prim to facilitate collision with NPC av capsules
6
7 // Modify the list of destination vectors to reflect your layout.
8 // Router position text labels can be toggled by touching the prim. This also triggers the setpos()
9
10 // This design imlements rotation calculations to prevent NPC avatars from walking backwards
11 // Permissions and information about the rotation functions was here..
12 // http://wiki.secondlife.com/wiki/User:Pedro_Oval/Calculate_rotation_for_pointing_in_a_direction
13 // Due credit is here ... Written by Pedro Oval, 2011-01-11
14
15 rotation PointAtHoriz2Rot(vector target)
16 {
17 return llRotBetween(<1., 0., 0.>, <target.x, target.y, 0.>);
18 }
19
20 rotation PointAt2Rot(vector target)
21 {
22 rotation r = PointAtHoriz2Rot(target);
23 return llRotBetween(<1., 0., 0.>, target/r) * r;
24 }
25 // end of Pedros' rotation magic
26
27 list DestinationList = [<70.0,70.0,30.0>,<97.0,100.0,37.0>,<70.0,190.0,33.0>];
28
29 // Modify DestinationList.. Keep the list of vectors small to minimize processing
30 // Be VERY careful about assigning destinations outside of the region.
31 // NPC's will move in a direct line, design your "paths" to be as free of obstacles as possible
32
33 integer numDests = 0;
34 integer showPos = 0;
35
36 default
37 {
39 {
40 llVolumeDetect(TRUE); // Starts llVolumeDetect
41 numDests = llGetListLength(DestinationList);
42
43 }
44
45 touch_start (integer numtouches)
46 {
47 while(numtouches)
48 {
49 if(showPos)
50 {
51 llSetText("", ZERO_VECTOR, 0.0);
52 showPos=0;
53
54 // Comment out the following 2 lines if you do NOT want your targets to "snap" to integer value locations
55 vector newpos = llGetPos();
56 llSetPos(<llFloor(newpos.x),llFloor(newpos.y), llFloor(newpos.z)>);
57 }
58 else
59 {
60 showPos = 1;
62 llSay(0,(string) llGetPos());
63 }
64 numtouches--;
65 }
66 }
67
69 {
70 integer i = 0;
71 do
72 {
73 integer DestOffset = llFloor(llFrand(numDests));
74 vector NewDest = llList2Vector(DestinationList,DestOffset) ;
75 osNpcSetRot(llDetectedKey(i), PointAt2Rot(NewDest - llGetPos()));
76 osNpcMoveToTarget(llDetectedKey(i), NewDest, OS_NPC_NO_FLY);
77 }
78 while(num > ++i);
79 }
80
81 changed(integer change)
82 {
83 if(change & CHANGED_REGION_RESTART)
84 {
86 }
87 }
88 }

Back to the Best Free Tools in Second Life and OpenSim.