NPC Creator (Owner Use Only) // Example UUID of e24a9015-f5ca-452b-8c95-d32e34cb9d64 is "Ai Austin" on Openvue grid. // touch to create npc in front of this emitter // Npc will walk to the toucher, then will greet them. // Touch again to remove the NPC // http://opensimulator.org/wiki/OSSLNPC // http://opensimulator.org/wiki/OsNpcCreate // http://opensimulator.org/wiki/OsNpcRemove // http://opensimulator.org/wiki/OsNpcMoveTo // http://opensimulator.org/wiki/OsNpcSay string npcNoteCard = "NPC Appearance"; key npc; vector toucherPos; default { state_entry() { llSetText("NPC Creator (Owner Use Only)",<0.6,0.6,0.6>, 1.0); } touch_start(integer number) { vector npcPos = llGetPos() + <1,0,0>; llSay(0,(string)llDetectedKey(number)); if (llDetectedKey(0) == llGetOwner()) { osAgentSaveAppearance(llDetectedKey(0), npcNoteCard); npc = osNpcCreate("Ai", "Tutor", npcPos, npcNoteCard); // below for specific logged in avatar cloning via UUID // npc = osNpcCreate("ImYour", "Clone", npcPos, "e24a9015-f5ca-452b-8c95-d32e34cb9d64"); // below or temp copy of NPC without saving appearance // npc = osNpcCreate("ImYour", "Clone", npcPos, llGetOwnerKey(llGetKey())); toucherPos = llDetectedPos(0); state hasNPC; } else llSay(0,"Sorry, I only make NPCs for "+llKey2Name(llGetOwner())+"\n You are "+llKey2Name(llDetectedKey(number))); } } state hasNPC { state_entry() { osNpcMoveTo(npc, toucherPos + <3,0,-5>); // -5 to make sure it lands - if avatar is on land osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc)+". I am (s)he as you are (s)he as you are me and we are all together."); } touch_start(integer number) { osNpcSay(npc, "Good bye!"); osNpcRemove(npc); npc = NULL_KEY; state default; } } NPC Sit and Stand // osNpcSit(, , OS_NPC_SIT_NOW) // e.g. osNpcSit(npc, llGetKey(), OS_NPC_SIT_NOW); // target object must have sit positon set explicitly // osNpcStand() // touch to create npc in front of this emitter // Npc will walk to the toucher, then will greet them. // Touch again to remove the NPC // http://opensimulator.org/wiki/OSSLNPC // http://opensimulator.org/wiki/OsNpcCreate // http://opensimulator.org/wiki/OsNpcRemove // http://opensimulator.org/wiki/OsNpcMoveTo // http://opensimulator.org/wiki/OsNpcSay string npcNoteCard = "NPC Appearance"; key npc; vector toucherPos; default { state_entry() { llSetText("NPC Sitdown (Owner Use Only)",<0.6,0.6,0.6>, 1.0); } touch_start(integer number) { vector npcPos = llGetPos() + <1,0,0>; llSay(0,(string)llDetectedKey(number)); if (llDetectedKey(0) == llGetOwner()) { osAgentSaveAppearance(llDetectedKey(0), npcNoteCard); npc = osNpcCreate("Sitting", "Clone", npcPos, npcNoteCard); // below for specific logged in avatar cloning via UUID // npc = osNpcCreate("ImYour", "Clone", npcPos, "e24a9015-f5ca-452b-8c95-d32e34cb9d64"); // below or temp copy of NPC without saving appearance // npc = osNpcCreate("ImYour", "Clone", npcPos, llGetOwnerKey(llGetKey())); toucherPos = llDetectedPos(0); state hasNPC; } else llSay(0,"Sorry, I only make NPCs for "+llKey2Name(llGetOwner())+"\n You are "+llKey2Name(llDetectedKey(number))); } } state hasNPC { state_entry() { osNpcSit(npc, llGetKey(), OS_NPC_SIT_NOW); // osNpcMoveTo(npc, toucherPos + <3,0,-5>); // -5 to make sure it lands - if avatar is on land osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc)+" and I am sitting down."); } touch_start(integer number) { osNpcStand(npc); osNpcMoveTo(npc, toucherPos + <3,0,-5>); // -5 to make sure it is on land osNpcSay(npc, "Good bye!"); osNpcRemove(npc); npc = NULL_KEY; state default; } } SetSitTarget // typical seating position for 0.5m cube default { state_entry() { llSitTarget(<0.275,0.0,0.55>,ZERO_ROTATION); } } GiveObjectUUID // Returns key (and linked number of part of a link set) of object script is in // Can add to object to get UUID and then delete the script from object contents // Can record UUID provided in object description for convenience. default { state_entry() { llOwnerSay(llGetKey()); // llOwnerSay(llGetLinkKey(llGetLinkNumber())); } } NPC Remover - All NPCs in Region // sim-wide NPC killer // kill all of NPCs in this SIM // Attempts to kill agents too, but it will silently fail // http://opensimulator.org/wiki/OsNpcRemove default { touch_start(integer number) { list avatars = llList2ListStrided(osGetAvatarList(), 0, -1, 3); integer i; llSay(0,"NPC Removal: No avatars will be harmed or removed in this process!"); for (i=0; i 15-Oct-2011 // NPC Persistance Example created by Marcus Llewellyn. // This script is in the Public Domain. key npc = NULL_KEY; string firstname = "Ai"; string lastname = "Austin"; integer dead = FALSE; default { state_entry() { // Setup and rez the NPC. key temp = (key)llGetObjectDesc(); if (llKey2Name(temp) != "") { // An NPC matching the UUID stored in the object description // already exists, so just retrieve the UUID. npc = temp; } else if (dead == FALSE) { // Create a new instance of the NPC, record the UUID in the // object's description, and set starting rotation. NPC // rotation and location are inherited from the controlling // object with an offset. npc = osNpcCreate(firstname, lastname, llGetPos() + <1.0,0.0,0.0>, llGetOwner()); llSetObjectDesc((string)npc); osNpcSetRot(npc, llGetRot() * (llEuler2Rot(<0, 0, 90> * DEG_TO_RAD))); } // Have the NPC say a greeting, and set up persistance timer and // listen for commands. osNpcSay(npc, firstname + " " + lastname + ", at your service."); llSetTimerEvent(10); llListen(0, "", NULL_KEY, ""); } timer() { // Our NPC UUID stored in the object description should match the // UUID of our existing NPC. If it does not, we presume an untimely // demise, and initiate resurrection by simply reseting our script. key temp = (key)llGetObjectDesc(); if (llKey2Name(temp) == "" && dead == FALSE) { llResetScript(); } } listen(integer channel, string name, key id, string msg) { if (llToLower(msg) == "kill") { // Kill the NPC, set a flag so it stays dead, and say something appropriate osNpcSay(npc, "I am gone!"); osNpcRemove(npc); dead = TRUE; } else if (llToLower(msg) == "start" && dead == TRUE) { // Create a new instance of our NPC, and set flag for // persistance checks. npc = osNpcCreate(firstname, lastname, llGetPos() + <1.0,0.0,0.0>, llGetOwner()); llSetObjectDesc((string)npc); osNpcSetRot(npc, llGetRot() * (llEuler2Rot(<0, 0, 90> * DEG_TO_RAD))); osNpcSay(npc, firstname + " " + lastname + ", at your service."); dead = FALSE; } else if (llToLower(msg) == "start" && dead == FALSE) { // Don't do anything significant if the NPC is still incarnate. osNpcSay(npc, "I'm already alive."); } } }