OsNpcCreate

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (some syntax modification (may be major or minor))
(Simplified the code to use llDetectedPos(0), and also changed the name of the NPC to be gender-neutral.)
Line 5: Line 5:
 
// touch to create npc in front of this emitter
 
// touch to create npc in front of this emitter
 
// Npc will walk to the toucher, then will greet them.
 
// Npc will walk to the toucher, then will greet them.
// touch again to destroy
+
// Touch again to remove the NPC
  
 
key npc;
 
key npc;
Line 15: Line 15:
 
     {
 
     {
 
         vector npcPos = llGetPos() + <1,0,0>;
 
         vector npcPos = llGetPos() + <1,0,0>;
         npc = osNpcCreate("Jane", "Bot", npcPos, llGetOwnerKey(llGetKey()));
+
         npc = osNpcCreate("ImYour", "Clone", npcPos, llGetOwnerKey(llGetKey()));
        list rtn = llGetObjectDetails(llDetectedKey(number), [OBJECT_POS]);
+
         toucherPos = llDetectedPos(0);
         toucherPos = llList2Vector(rtn, 0);
+
 
         state hasNPC;
 
         state hasNPC;
 
     }
 
     }
Line 26: Line 25:
 
     state_entry()
 
     state_entry()
 
     {
 
     {
         osNpcMoveTo(npc, toucherPos + <1,0,0>); // This is currently unworkable
+
         osNpcMoveTo(npc, toucherPos + <1,0,0>); // osNpcMoveTo will currently not work as intended.
 
         osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc));
 
         osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc));
 
     }
 
     }
Line 41: Line 40:
 
|description=*Creates a NPC(Non Player Character) clone named '''firstname''' '''lastname''' at '''position''' from an already existing avatar  '''cloneFrom'''.
 
|description=*Creates a NPC(Non Player Character) clone named '''firstname''' '''lastname''' at '''position''' from an already existing avatar  '''cloneFrom'''.
 
*Note: This function may not work as you have intended. See [http://opensimulator.org/mantis/view.php?id=5148 Mantis #5148] for more information.
 
*Note: This function may not work as you have intended. See [http://opensimulator.org/mantis/view.php?id=5148 Mantis #5148] for more information.
 +
*Note: Since revision [http://opensimulator.org/viewgit/?a=commit&p=opensim&h=59f548cda82facef003fb7309180412254a234a1 r/16413], dated Aug 1st, 2011, this function works again, with the caveat that osNpcCreate will only clone avatars currently in the region.
 
|
 
|
 
}}
 
}}

Revision as of 19:00, 1 August 2011

key osNpcCreate(string firstname, string lastname, vector position, key cloneFrom)
  • Creates a NPC(Non Player Character) clone named firstname lastname at position from an already existing avatar cloneFrom.
  • Note: This function may not work as you have intended. See Mantis #5148 for more information.
  • Note: Since revision r/16413, dated Aug 1st, 2011, this function works again, with the caveat that osNpcCreate will only clone avatars currently in the region.
Threat Level High
Permissions No permissions specified
Delay No function delay specified
Example(s)
// 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
 
key npc;
vector toucherPos;
 
default
{
    touch_start(integer number)
    {
        vector npcPos = llGetPos() + <1,0,0>;
        npc = osNpcCreate("ImYour", "Clone", npcPos, llGetOwnerKey(llGetKey()));
        toucherPos = llDetectedPos(0);
        state hasNPC;
    }
}
 
state hasNPC
{
    state_entry()
    {
        osNpcMoveTo(npc, toucherPos + <1,0,0>); // osNpcMoveTo will currently not work as intended.
        osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc));
    }
 
    touch_start(integer number)
    {
        osNpcSay(npc, "Good bye!");
        osNpcRemove(npc);
        npc = NULL_KEY;
        state default;
    }
}
Personal tools
General
About This Wiki