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 Persist_NPC_thru_a_reboot  

Persist_NPC_thru_a_reboot

from http://opensimulator.org/wiki/OSSL_...

Category: OpenSim NPC
By : Marcus Llewellyn
Created: 2013-07-30 Edited: 2013-07-30
Worlds: OpenSim

the Zip file

Download all files for Persist_NPC_thru_a_reboot
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Persist_NPC_thru_a_reboot_1.lsl
1
2 key npc = NULL_KEY;
3 string firstname = "Dwight";
4 string lastname = "Smith";
5 integer dead = FALSE;
6
7 default
8 {
10 // Setup and rez the NPC.
11 key temp = (key)llGetObjectDesc();
12 if(llKey2Name(temp) != "") {
13 // An NPC matching the UUID stored in the object description
14 // already exists, so just retrieve the UUID.
15 npc = temp;
16 } else if(dead == FALSE) {
17 // Create a new instance of the NPC, record the UUID in the
18 // object's description, and set starting rotation. NPC
19 // rotation and location are inherited from the controlling
20 // object with an offset.
21 npc = osNpcCreate(firstname, lastname, llGetPos() + <1.0,0.0,0.0>, llGetOwner());
23 osNpcSetRot(npc, llGetRot() * (llEuler2Rot(<0, 0, 90> * DEG_TO_RAD)));
24 }
25 // Have the NPC say a greeting, and set up persistance timer and
26 // listen for commands.
27 osNpcSay(npc, firstname + " " + lastname + ", at your service.");
29 llListen(0, "", NULL_KEY, "");
30
31 }
32
33 timer() {
34 // Our NPC UUID stored in the object description should match the
35 // UUID of our existing NPC. If it does not, we presume an untimely
36 // demise, and initiate resurrection by simply reseting our script.
37 key temp = (key)llGetObjectDesc();
38 if(llKey2Name(temp) == "" && dead == FALSE) {
40 }
41 }
42
43 listen(integer channel, string name, key id, string msg) {
44 if(llToLower(msg) == "kill") {
45 // Kill the NPC, set a flag so it stays dead, and misquote
46 // John Donne.
47 osNpcSay(npc, "Send not to know for whom the bell tolls, it tolls for me!");
48 osNpcRemove(npc);
49 dead = TRUE;
50 } else if(llToLower(msg) == "start" && dead == TRUE) {
51 // Create a new instance of our NPC, and set flag for
52 // persistance checks.
53 npc = osNpcCreate(firstname, lastname, llGetPos() + <1.0,0.0,0.0>, llGetOwner());
55 osNpcSetRot(npc, llGetRot() * (llEuler2Rot(<0, 0, 90> * DEG_TO_RAD)));
56 osNpcSay(npc, firstname + " " + lastname + ", at your service.");
57 dead = FALSE;
58 } else if(llToLower(msg) == "start" && dead == FALSE) {
59 // Don't do anything significant if the NPC is still incarnate.
60 osNpcSay(npc, "I'm already alive, boss.");
61 }
62 }
63 }

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