OsNpcCreate

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(23 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{osslfunc|
+
{{osslfunc
threat_level = High
+
|threat_level=High
|
+
|permissions=${OSSL|osslNPC}
function_syntax = <source lang="lsl">
+
|delay=0
key osNpcCreate(string firstname, string lastname, vector position, key cloneFrom);
+
|function_syntax=key osNpcCreate(string firstname, string lastname, vector position, string cloneFrom)
</source>
+
 
|
+
key osNpcCreate(string firstname, string lastname, vector position, string cloneFrom, integer options)
ossl_example = <source lang="lsl">
+
|ossl_example=<source lang="lsl">
// touch to create npc in front of this emitter
+
// touch to create a NPC clone of the toucher in front of this emitter
// Npc will walk to the toucher, then will greet them.
+
// NPC will move to the toucher, then will greet them.
// touch again to destroy
+
// Touch again to remove the NPC
  
 
key npc;
 
key npc;
Line 19: Line 19:
 
     {
 
     {
 
         vector npcPos = llGetPos() + <1,0,0>;
 
         vector npcPos = llGetPos() + <1,0,0>;
         npc = osNpcCreate("Jane", "Bot", npcPos, llGetOwnerKey(llGetKey()));
+
        osAgentSaveAppearance(llDetectedKey(0), "appearance");
        list rtn = llGetObjectDetails(llDetectedKey(number), [OBJECT_POS]);
+
        // coud use avatar UUID directly in osNpcCreate, but then NPC appearance is not persisted
         toucherPos = llList2Vector(rtn, 0);
+
         npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance");
 +
         toucherPos = llDetectedPos(0);
 
         state hasNPC;
 
         state hasNPC;
 
     }
 
     }
Line 30: Line 31:
 
     state_entry()
 
     state_entry()
 
     {
 
     {
         osNpcMoveTo(npc, toucherPos + <1,0,0>); // This is currently unworkable
+
         osNpcMoveTo(npc, toucherPos + <3,0,0>);  
 
         osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc));
 
         osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc));
 
     }
 
     }
Line 36: Line 37:
 
     touch_start(integer number)
 
     touch_start(integer number)
 
     {
 
     {
         osNpcSay(npc, "Good bye!");
+
         osNpcSay(npc, "Goodbye!");
 
         osNpcRemove(npc);
 
         osNpcRemove(npc);
 
         npc = NULL_KEY;
 
         npc = NULL_KEY;
Line 43: Line 44:
 
}
 
}
 
</source>
 
</source>
|  
+
|description=*Creates an NPC named '''firstname''' '''lastname''' at '''position''' from avatar appearance resource '''cloneFrom'''
additional_info = *Creates a NPC(Non Player Character) clone named '''firstname''' '''lastname''' at '''position''' from an already existing avatar '''cloneFrom'''.
+
|additional_info= Some more useful info:
*Note: This function may not work as you have intended. See [http://opensimulator.org/mantis/view.php?id=5148 Mantis #5148] for more information.
+
* NPC stands for Non-Player Character.
|
+
* You can clone an appearance from a saved appearance notecard name or UUID, or from the UUID of an avatar logged into the same region or sim.
 +
* You can create and load appearance notecards with the following functions: [[osOwnerSaveAppearance]], [[osAgentSaveAppearance]], [[osNpcLoadAppearance]], [[osNpcSaveAppearance]].
 +
* '''In current OpenSimulator development code (from commit c4972e77 on Thu Jan 12 2012), an overloaded version of osNpcCreate() has been added.'''
 +
** This has the signature key osNpcCreate(string firstname, string lastname, vector position, string cloneFrom, integer options).
 +
** The options field can be either OS_NPC_CREATOR_OWNED or OS_NPC_NOT_OWNED.
 +
** OS_NPC_CREATOR_OWNED will create an 'owned' NPC that will only respond to osNpc* commands issued from scripts that have the same owner as the one that created the NPC.
 +
** OS_NPC_NOT_OWNED will create an 'unowned' NPC that will respond to any script that has OSSL permissions to call osNpc* commands.
 +
** Example: "key npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance", OS_NPC_CREATOR_OWNED);"
 +
** The existing osNpcCreate() function without the options field will continue to exist.
 +
* From git master commit 3b59af22 on Friday Jan 13 2012 (after the OpenSimulator 0.7.2 release), the avatar created by the existing osNpc* function without the options parameter will create an 'owned' NPC rather than an 'unowned' one.  Please see the discussion above for information on these terms.  This is a hopefully rare case where the behaviour of an existing function changes slightly.  If you continue to need an 'unowned' NPC, please use the OS_NPC_NOT_OWNED option described above.
 +
* Use OS_NPC_SENSE_AS_AGENT option if you would like for the created NPC to be able to be detected via a sensor and want to maintain llSensor() compatibility with type AGENT.
 +
* OS_NPC_OBJECT_GROUP  with it the npc will be created with the group of the object with the script, if that object owner is member of that group. This should allow parcel access by group to work now, and not much else. The group Title will also be set, it the region option NoNPCGroup is not active.
 +
*This function was added in 0.7.3-post-fixes
 +
 
 +
 
 
}}
 
}}

Revision as of 20:55, 25 September 2019

key osNpcCreate(string firstname, string lastname, vector position, string cloneFrom)

key osNpcCreate(string firstname, string lastname, vector position, string cloneFrom, integer options)

  • Creates an NPC named firstname lastname at position from avatar appearance resource cloneFrom
Threat Level High
Permissions ${OSSL|osslNPC}
Extra Delay 0 seconds
Example(s)
// touch to create a NPC clone of the toucher in front of this emitter
// NPC will move 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>;
        osAgentSaveAppearance(llDetectedKey(0), "appearance");
        // coud use avatar UUID directly in osNpcCreate, but then NPC appearance is not persisted
        npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance");
        toucherPos = llDetectedPos(0);
        state hasNPC;
    }
}
 
state hasNPC
{
    state_entry()
    {
        osNpcMoveTo(npc, toucherPos + <3,0,0>); 
        osNpcSay(npc, "Hi there! My name is " + llKey2Name(npc));
    }
 
    touch_start(integer number)
    {
        osNpcSay(npc, "Goodbye!");
        osNpcRemove(npc);
        npc = NULL_KEY;
        state default;
    }
}
Notes
Some more useful info:
  • NPC stands for Non-Player Character.
  • You can clone an appearance from a saved appearance notecard name or UUID, or from the UUID of an avatar logged into the same region or sim.
  • You can create and load appearance notecards with the following functions: osOwnerSaveAppearance, osAgentSaveAppearance, osNpcLoadAppearance, osNpcSaveAppearance.
  • In current OpenSimulator development code (from commit c4972e77 on Thu Jan 12 2012), an overloaded version of osNpcCreate() has been added.
    • This has the signature key osNpcCreate(string firstname, string lastname, vector position, string cloneFrom, integer options).
    • The options field can be either OS_NPC_CREATOR_OWNED or OS_NPC_NOT_OWNED.
    • OS_NPC_CREATOR_OWNED will create an 'owned' NPC that will only respond to osNpc* commands issued from scripts that have the same owner as the one that created the NPC.
    • OS_NPC_NOT_OWNED will create an 'unowned' NPC that will respond to any script that has OSSL permissions to call osNpc* commands.
    • Example: "key npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance", OS_NPC_CREATOR_OWNED);"
    • The existing osNpcCreate() function without the options field will continue to exist.
  • From git master commit 3b59af22 on Friday Jan 13 2012 (after the OpenSimulator 0.7.2 release), the avatar created by the existing osNpc* function without the options parameter will create an 'owned' NPC rather than an 'unowned' one. Please see the discussion above for information on these terms. This is a hopefully rare case where the behaviour of an existing function changes slightly. If you continue to need an 'unowned' NPC, please use the OS_NPC_NOT_OWNED option described above.
  • Use OS_NPC_SENSE_AS_AGENT option if you would like for the created NPC to be able to be detected via a sensor and want to maintain llSensor() compatibility with type AGENT.
  • OS_NPC_OBJECT_GROUP with it the npc will be created with the group of the object with the script, if that object owner is member of that group. This should allow parcel access by group to work now, and not much else. The group Title will also be set, it the region option NoNPCGroup is not active.
  • This function was added in 0.7.3-post-fixes
Personal tools
General
About This Wiki