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
Particles Special_Particle_Sensor__Brain_  

Special_Particle_Sensor__Brain_

Special Particle Sensor _Brain_.lsl

Category: Particles
By : Christopher Omega
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Special_Particle_Sensor__Brain_
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Special_Particle_Sensor__Brain__1.lsl
1
2 // Special Particle Sensor "Brain" Script
3 // Written by Christopher Omega
4 //
5 // Tasks:
6 // Listen to the owner.
7 // Parse the owner's message,
8 // Signal individual locators to reset
9 // Or point at a certain object within
10 // 96 meters of the apparatus.
11
12 // Global Variables
13 // targetName Stores the name of the object that's being looked for.
14 string targetName = "";
15
16 // Global Constants
17 // LOCATOR_ALL_LOCATORS A constant defining when the message sent by this script is meant for all locators.
18 integer LOCATOR_ALL_LOCATORS = -1;
19
20 // SENSOR_TYPE_ALL A constant that tells the sensor to look for (ACTIVE|PASSIVE|AGENT).
21 // 7 is just the integer form of (ACTIVE|PASSIVE|AGENT)
22 integer SENSOR_TYPE_ALL = 7;
23
24 // SENSOR_MAX_RANGE A constant defining the max. range of the sensor to run. As of SL v1.2.13, it is 96.0 meters.
25 float SENSOR_MAX_RANGE = 96.0;
26
27 // MESSAGE_PARAMETER_SEPERATOR A constant that is used as a seperator in parsing lists sent as strings.
28 string MESSAGE_PARAMETER_SEPERATOR = "|~|";
29
30 // strStartsWith()
31 // Returns a boolean-integer that tells if the string starts with the prefix.
32 // @param str The string to search.
33 // @param prefix The prefix of str to find.
34 // @return TRUE or FALSE, if str starts with prefix.
35 integer strStartsWith(string str, string prefix) {
36 return (llSubStringIndex(str, prefix) == 0);
37 }
38
39 // contactLocator()
40 // Sends a message to the locators.
41 // @param locatorNumber The number identifyer of the locater to send the message to. LOCATOR_ALL_LOCATORS to send to all.
42 // @param parameters The parameters to send to the locator.
43 // @param command The command to send to the locator.
44 contactLocator(integer locatorNumber, string parameters, string command) {
45 integer linkNumber = locatorNumber + 2;
46
47 if(locatorNumber == LOCATOR_ALL_LOCATORS) linkNumber = LINK_ALL_OTHERS;
48
49 llMessageLinked(linkNumber, 0, parameters, command);
50 }
51
52 // pointLocatorAt()
53 // Sends a message to the locator specified by locatorNumber
54 // Telling it to point itself and its particle system at a
55 // target defined by targetId and targetPosition.
56 // @param locatorNumber The particle emitter to tell to point.
57 // @param targetId The UUID (key) of the target to point at.
58 // @param targetPosition The position, in region-local coordinates, of the target.
59 pointLocatorAt(integer locatorNumber, key targetId, vector targetPosition) {
60 list paramList = [targetId, targetPosition];
61 contactLocator(locatorNumber, llDumpList2String(paramList, MESSAGE_PARAMETER_SEPERATOR), "POINT_AT");
62 }
63
64 // resetLocator()
65 // Kills the particle system emininating from the locator defined by locatorNumber.
66 // @param locatorNumber The particle emitter in which to shut off. LOCATOR_ALL_LOCATERS to turn off all.
67 resetLocator(integer locatorNumber) {
68 contactLocator(locatorNumber, "", "RESET"); // Turn off the particles.
69 }
70
71 default {
72 state_entry() {
73 llSay(0, "Running.");
74 llListen(0, "", llGetOwner(), "");
75 resetLocator(LOCATOR_ALL_LOCATORS);
76 }
77 listen(integer chan, string name, key id, string msg) {
78 if(strStartsWith(msg, "#reset")) {
80 resetLocator(LOCATOR_ALL_LOCATORS);
81 }
82 else if(strStartsWith(msg, "#find ")) {
83 resetLocator(LOCATOR_ALL_LOCATORS);
84
85 targetName = llDeleteSubString(msg, 0, 5); // Delete "#find " from msg
86
87 llSensor(targetName, NULL_KEY, SENSOR_TYPE_ALL, SENSOR_MAX_RANGE, TWO_PI);
88 llSay(0, "Searching for " + targetName);
89 }
90 }
91 no_sensor()
92 {
93 llSay(0, targetName + " not found within a distance of "
94 + (string) SENSOR_MAX_RANGE + " meters.");
95
97 }
98 sensor(integer numDetected) {
99 integer i;
100 for (i = 0; i < numDetected; i++) {
101 key targetKey = llDetectedKey(i);
102 vector targetPos = llDetectedPos(i);
103 llSay(0, targetName + " found at " + (string) targetPos
104 + " with key " + (string) targetKey);
105 pointLocatorAt(i, targetKey, targetPos);
106 }
107 }
108 }
109 // END //

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