OsNpcCreate
From OpenSimulator
(Difference between revisions)
m (Add links to exemples using OS_NPC_CREATOR_OWNED and OS_NPC_NOT_OWNED) |
(Adding exemple with OS_NPC_SENSE_AS_AGENT) |
||
Line 55: | Line 55: | ||
} | } | ||
</source> | </source> | ||
+ | '''With OS_NPC_SENSE_AS_AGENT''' | ||
+ | <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> | ||
|additional_info= Some more useful info: | |additional_info= Some more useful info: | ||
* NPC stands for Non-Player Character. | * NPC stands for Non-Player Character. |
Revision as of 09:01, 4 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 // // 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."); } } } | |
Notes | |
Some more useful info:
|
See Also:
- osNpcCreate
- osNpcRemove