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
NPC NPC Manager  

NPC Manager

Wear or rez to ground, then touch to be able to globally or selectively remove NPCs from a region

Category: NPC
By : Aine Caoimhe
Created: 2015-11-24 Edited: 2015-11-24
Worlds: OpenSim

the Zip file

Download all files for NPC Manager
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Paramour NPC Manager.lsl
1 // Paramour NPC Manager
2 // by Aine Caoimhe (Mata Hari)(c. LACM) April 2015
3 // Provided under Creative Commons Attribution-Non-Commercial-ShareAlike 4.0 International license.
4 // Please be sure you read and adhere to the terms of this license: https://creativecommons.org/licenses/by-nc-sa/4.0/
5 //
6 // Wear or rez to ground, then touch to be able to globally or selectively remove NPCs from a region
7 // OSSL functions required:
9 // osNpcRemove()
10 // osIsNpc()
11 //
12 // USER SETTINGS
13 float dialogTimeout=60.0; // how long to wait before timing out the dialog if no response received
14 integer ownerOnlyTouch=TRUE; // TRUE = only owner to can touch to activate, FALSE = anyone can use it
15 string floatyText="Paramour NPC Manager\n(right-click and take a copy)"; // text to have floating above the object or supply an empty string ( "") for none
16 vector floatyTextColour=<1.000, 0.906, 0.502>; // LSL vector colour to use for the text (<0.0, 0.0, 0.0> = black, <1.0, 1.0, 1.0> = white)
17 //
18 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
19 // DON'T CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU'RE DOING
20 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
21 list npcList;
22 integer indNpc;
23 list globalButtons=["DONE","-","KILL ALL","< PREV","RESCAN","NEXT >"];
24 integer myChannel;
25 integer handle;
26 key user;
27
28 showMenu()
29 {
30 string txtDia="Select a NPC to remove\nor KILL ALL to remove all NPCs\nor RESCAN to refresh the list\n\nNPCs currently in the region: "+(string)(llGetListLength(npcList)/4-1)+"\n";
31 list butDia;
32 integer i=indNpc;
33 while(llGetListLength(butDia)<6)
34 {
35 if((i*4)>=llGetListLength(npcList)) butDia=butDia+["-"];
36 else
37 {
38 butDia=[]+butDia+[(string)i];
39 txtDia+="\n"+(string)i+". "+llList2String(npcList,i*4+2)+" at "+llList2String(npcList,i*4+3);
40 }
41 i++;
42 }
43 butDia=[]+globalButtons+llList2List(butDia,3,5)+llList2List(butDia,0,2);
44 handle=llListen(myChannel,"",user,"");
45 llSetTimerEvent(dialogTimeout);
46 llDialog(user,txtDia,butDia,myChannel);
47 }
48 doRemoveNpc(integer ind)
49 {
50 if(llGetAgentSize(llList2Key(npcList,ind+1))!=ZERO_VECTOR) osNpcRemove(llList2Key(npcList,ind+1));
51 llRegionSayTo(user,0,"Removed NPC "+llList2String(npcList,ind+2)+" from location "+llList2String(npcList,ind+3));
52 npcList=[]+llDeleteSubList(npcList,ind,ind+3);
53 }
54 doKillAll()
55 {
56 integer i;
57 integer l=llGetListLength(npcList);
58 for (i=4;i<l;i+=4)
59 {
60 if(llGetAgentSize(llList2Key(npcList,i+1))!=ZERO_VECTOR) osNpcRemove(llList2Key(npcList,i+1));
61 }
62 llRegionSayTo(user,0,"All NPCs in the region have now been removed");
63 finishedUsing();
64 }
65 finishedUsing()
66 {
67 user=NULL_KEY;
68 npcList=[];
69 indNpc=0;
70 }
71 stopListening()
72 {
73 llSetTimerEvent(0.0);
74 llListenRemove(handle);
75 }
76 doRescan()
77 {
78 list inRegion=osGetAvatarList(); // UUUID | POS | NAME
79 vector myPos=llGetPos();
80 npcList=["distance","UUID","name","location"];
81 integer l=llGetListLength(inRegion);
82 integer i;
83 for (;i<l;i+=3)
84 {
85 if(
86 osIsNpc(llList2Key(inRegion,i))
87 )
88 npcList=[]+npcList+
89 [
90 llVecDist(myPos,llList2Vector(inRegion,i+1)),
91 llList2Key(inRegion,i),
92 llList2Key(inRegion,i+2),
93 vec2Int0String(llList2Vector(inRegion,i+1))
94 ];
95 }
96 if(llGetListLength(npcList)<=4) indNpc=0;
97 else
98 {
99 npcList=[]+llListSort(npcList,4,TRUE);
100 indNpc=1;
101 }
102 }
103 checkIndex()
104 {
105 if((indNpc*4)>=llGetListLength(npcList)) indNpc=1;
106 if(indNpc==-5) indNpc=(integer)(llGetListLength(npcList)/4.0 -6.0);
107 if(indNpc<1) indNpc=1;
108 }
109 string vec2Int0String(vector vConvert)
110 {
111 // returns a vector as a string with values rounded to nearest whole number
112 string r="<"+(string)(llRound(vConvert.x))+", "+(string)(llRound(vConvert.y))+", "+(string)(llRound(vConvert.z))+">";
113 return r;
114 }
115 default
116 {
118 {
119 myChannel=0x80000000|(integer)("0x"+(string)llGetKey());
120 finishedUsing();
121 llSetText(floatyText,floatyTextColour,1.0);
122 }
123 timer()
124 {
125 llRegionSayTo(user,0,"Dialog has timed out. Please touch me again to resume");
126 stopListening();
127 finishedUsing();
128 }
129 on_rez(integer food)
130 {
132 }
133 changed (integer change)
134 {
135 if(change & CHANGED_REGION_START) llResetScript();
138 }
140 {
141 key toucher=llDetectedKey(0);
142 if(toucher!=user)
143 {
144 if(user==NULL_KEY)
145 {
146 if(ownerOnlyTouch && (toucher!=llGetOwner())) llRegionSayTo(toucher,0,"Sorry, only the owner can use this");
147 else
148 {
149 doRescan();
150 if(!indNpc) llRegionSayTo(toucher,0,"There are currently no NPCs in this region");
151 else
152 {
153 user=toucher;
154 showMenu();
155 }
156 }
157 }
158 else llRegionSayTo(toucher,0,"Sorry, this is already being used by someone else");
159 }
160 else showMenu();
161 }
162 listen(integer channel, string name, key who, string message)
163 {
164 stopListening();
165 if(message=="DONE") finishedUsing();
166 else if(message=="KILL ALL") doKillAll();
167 else if(message=="-") showMenu();
168 else if(message=="RESCAN")
169 {
170 doRescan();
171 showMenu();
172 }
173 else if((message=="< PREV")||(message=="NEXT >"))
174 {
175 if(message=="NEXT >") indNpc+=6;
176 else indNpc-=6;
177 checkIndex();
178 showMenu();
179 }
180 else
181 {
182 // message is number of the NPC to remove
183 doRemoveNpc(4*((integer)message));
184 if(llGetListLength(npcList)<=4)
185 {
186 llRegionSayTo(user,0,"There are no more NPCs remaining in the region");
187 finishedUsing();
188 }
189 else
190 {
191 checkIndex();
192 showMenu();
193 }
194 }
195 }
196 }

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