OsNpcCreate
From OpenSimulator
(Difference between revisions)
(Update Script) |
m (Change See Also) |
||
(6 intermediate revisions by one user not shown) | |||
Line 10: | Line 10: | ||
// | // | ||
// osNpcCreate Script Exemple | // osNpcCreate Script Exemple | ||
− | // | + | // Author: djphil |
// | // | ||
Line 43: | Line 43: | ||
llSetTimerEvent(0.0); | llSetTimerEvent(0.0); | ||
osNpcSay(npc, "Hello world!"); | osNpcSay(npc, "Hello world!"); | ||
+ | } | ||
+ | |||
+ | touch_start(integer number) | ||
+ | { | ||
+ | osNpcSay(npc, "Goodbye!"); | ||
+ | llSetTimerEvent(0.0); | ||
+ | osNpcRemove(npc); | ||
+ | npc = NULL_KEY; | ||
+ | state default; | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | '''With OS_NPC_SENSE_AS_AGENT:''' (It Needs the setting '''AllowSenseAsAvatar''' on '''true''' in section '''[NPC]''' of your OpenSim.ini) | ||
+ | <source lang="lsl"> | ||
+ | // | ||
+ | // osNpcCreate Script Exemple | ||
+ | // Authior: djphil | ||
+ | // | ||
+ | |||
+ | integer sens_as_agent = TRUE; | ||
+ | key npc; | ||
+ | |||
+ | default | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, "Touch to see osNpcCreate usage."); | ||
+ | |||
+ | if (sens_as_agent == TRUE) | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, "This with the use of the option OS_NPC_SENSE_AS_AGENT."); | ||
+ | } | ||
+ | |||
+ | else | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, "This without the use of the option OS_NPC_SENSE_AS_AGENT."); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | touch_start(integer number) | ||
+ | { | ||
+ | key toucher = llDetectedKey(0); | ||
+ | vector npcPos = llGetPos() + <1.0, 0.0, 1.0>; | ||
+ | osAgentSaveAppearance(toucher, "appearance"); | ||
+ | |||
+ | if (sens_as_agent == TRUE) | ||
+ | { | ||
+ | npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance", OS_NPC_SENSE_AS_AGENT); | ||
+ | } | ||
+ | |||
+ | else | ||
+ | { | ||
+ | npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance"); | ||
+ | } | ||
+ | |||
+ | state hasNPC; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | state hasNPC | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | llSetTimerEvent(5.0); | ||
+ | } | ||
+ | |||
+ | timer() | ||
+ | { | ||
+ | llSetTimerEvent(0.0); | ||
+ | key npc_owner = osNpcGetOwner(npc); | ||
+ | osNpcSay(npc, "Hello world!"); | ||
+ | |||
+ | if (sens_as_agent == TRUE) | ||
+ | { | ||
+ | llSensor("", npc, AGENT, 2.0, PI); | ||
+ | } | ||
+ | |||
+ | else | ||
+ | { | ||
+ | llSensor("", npc, NPC, 2.0, PI); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | touch_start(integer number) | ||
+ | { | ||
+ | osNpcSay(npc, "Goodbye!"); | ||
+ | llSetTimerEvent(0.0); | ||
+ | osNpcRemove(npc); | ||
+ | npc = NULL_KEY; | ||
+ | state default; | ||
+ | } | ||
+ | |||
+ | sensor(integer number) | ||
+ | { | ||
+ | if (sens_as_agent == TRUE) | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, (string)number + " NPC sense as agent deteced: " + llDetectedName(0)); | ||
+ | } | ||
+ | |||
+ | else | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, (string)number + " NPC sense as npc deteted: " + llDetectedName(0)); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | no_sensor() | ||
+ | { | ||
+ | if (sens_as_agent == TRUE) | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, "No NPC sense as agent is near me at present."); | ||
+ | } | ||
+ | |||
+ | else | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, "No NPC senss as npc is near me at present."); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | '''With OS_NPC_OBJECT_GROUP:''' (It Needs the setting '''NoNPCGroup''' on '''false''' in section '''[NPC]''' of your OpenSim.ini) | ||
+ | <source lang="lsl"> | ||
+ | // | ||
+ | // osNpcCreate Script Exemple | ||
+ | // Authior: djphil | ||
+ | // | ||
+ | |||
+ | key npc; | ||
+ | |||
+ | default | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, "Touch to see osNpcCreate usage."); | ||
+ | llSay(PUBLIC_CHANNEL, "This with the use of the option OS_NPC_OBJECT_GROUP."); | ||
+ | } | ||
+ | |||
+ | touch_start(integer number) | ||
+ | { | ||
+ | key toucher = llDetectedKey(0); | ||
+ | vector npcPos = llGetPos() + <1.0, 0.0, 1.0>; | ||
+ | osAgentSaveAppearance(toucher, "appearance"); | ||
+ | npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance", OS_NPC_OBJECT_GROUP); | ||
+ | state hasNPC; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | state hasNPC | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | llSetTimerEvent(5.0); | ||
+ | } | ||
+ | |||
+ | timer() | ||
+ | { | ||
+ | llSetTimerEvent(0.0); | ||
+ | key npc_owner = osNpcGetOwner(npc); | ||
+ | osNpcSay(npc, "Hello world!"); | ||
} | } | ||
Line 61: | Line 219: | ||
* '''In current OpenSimulator development code (from commit c4972e77 on Thu Jan 12 2012), an overloaded version of osNpcCreate() has been added.''' | * '''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). | ** 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. | + | ** The options field can be either OS_NPC_CREATOR_OWNED or OS_NPC_NOT_OWNED. For exemples, see [[osNpcGetOwner]] |
** 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_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. | ** 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);" | + | ** Example: "key npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance", OS_NPC_CREATOR_OWNED);". For full exemples, see [[osNpcGetOwner]] |
** The existing osNpcCreate() function without the options field will continue to exist. | ** 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. | * 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. | ||
Line 70: | Line 228: | ||
* 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. | * 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 | *This function was added in 0.7.3-post-fixes | ||
− | |||
− | |||
}} | }} | ||
+ | == See Also == | ||
+ | * [[osNpcCreate]] | ||
+ | * [[osNpcRemove]] |
Latest revision as of 18:50, 5 December 2020
key osNpcCreate(string firstname, string lastname, vector position, string cloneFrom)
key osNpcCreate(string firstname, string lastname, vector position, string cloneFrom, integer options) | |
| |
Threat Level | High |
Permissions | ${OSSL|osslNPC} |
Extra Delay | 0 seconds |
Example(s) | |
// // osNpcCreate Script Exemple // Author: djphil // key npc; default { state_entry() { llSay(PUBLIC_CHANNEL, "Touch to see osNpcCreate usage."); } touch_start(integer number) { key toucher = llDetectedKey(0); vector npcPos = llGetPos() + <1.0, 0.0, 1.0>; osAgentSaveAppearance(toucher, "appearance"); npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance"); state hasNPC; } } state hasNPC { state_entry() { llSetTimerEvent(5.0); } timer() { llSetTimerEvent(0.0); osNpcSay(npc, "Hello world!"); } touch_start(integer number) { osNpcSay(npc, "Goodbye!"); llSetTimerEvent(0.0); osNpcRemove(npc); npc = NULL_KEY; state default; } } With OS_NPC_SENSE_AS_AGENT: (It Needs the setting AllowSenseAsAvatar on true in section [NPC] of your OpenSim.ini) // // osNpcCreate Script Exemple // Authior: djphil // integer sens_as_agent = TRUE; key npc; default { state_entry() { llSay(PUBLIC_CHANNEL, "Touch to see osNpcCreate usage."); if (sens_as_agent == TRUE) { llSay(PUBLIC_CHANNEL, "This with the use of the option OS_NPC_SENSE_AS_AGENT."); } else { llSay(PUBLIC_CHANNEL, "This without the use of the option OS_NPC_SENSE_AS_AGENT."); } } touch_start(integer number) { key toucher = llDetectedKey(0); vector npcPos = llGetPos() + <1.0, 0.0, 1.0>; osAgentSaveAppearance(toucher, "appearance"); if (sens_as_agent == TRUE) { npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance", OS_NPC_SENSE_AS_AGENT); } else { npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance"); } state hasNPC; } } state hasNPC { state_entry() { llSetTimerEvent(5.0); } timer() { llSetTimerEvent(0.0); key npc_owner = osNpcGetOwner(npc); osNpcSay(npc, "Hello world!"); if (sens_as_agent == TRUE) { llSensor("", npc, AGENT, 2.0, PI); } else { llSensor("", npc, NPC, 2.0, PI); } } touch_start(integer number) { osNpcSay(npc, "Goodbye!"); llSetTimerEvent(0.0); osNpcRemove(npc); npc = NULL_KEY; state default; } sensor(integer number) { if (sens_as_agent == TRUE) { llSay(PUBLIC_CHANNEL, (string)number + " NPC sense as agent deteced: " + llDetectedName(0)); } else { llSay(PUBLIC_CHANNEL, (string)number + " NPC sense as npc deteted: " + llDetectedName(0)); } } no_sensor() { if (sens_as_agent == TRUE) { llSay(PUBLIC_CHANNEL, "No NPC sense as agent is near me at present."); } else { llSay(PUBLIC_CHANNEL, "No NPC senss as npc is near me at present."); } } } With OS_NPC_OBJECT_GROUP: (It Needs the setting NoNPCGroup on false in section [NPC] of your OpenSim.ini) // // osNpcCreate Script Exemple // Authior: djphil // key npc; default { state_entry() { llSay(PUBLIC_CHANNEL, "Touch to see osNpcCreate usage."); llSay(PUBLIC_CHANNEL, "This with the use of the option OS_NPC_OBJECT_GROUP."); } touch_start(integer number) { key toucher = llDetectedKey(0); vector npcPos = llGetPos() + <1.0, 0.0, 1.0>; osAgentSaveAppearance(toucher, "appearance"); npc = osNpcCreate("ImYour", "Clone", npcPos, "appearance", OS_NPC_OBJECT_GROUP); state hasNPC; } } state hasNPC { state_entry() { llSetTimerEvent(5.0); } timer() { llSetTimerEvent(0.0); key npc_owner = osNpcGetOwner(npc); osNpcSay(npc, "Hello world!"); } touch_start(integer number) { osNpcSay(npc, "Goodbye!"); llSetTimerEvent(0.0); osNpcRemove(npc); npc = NULL_KEY; state default; } } | |
Notes | |
Some more useful info:
|
[edit] See Also
- osNpcCreate
- osNpcRemove