OSSLNPC

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Introduction)
Line 14: Line 14:
  
 
NPCs created user these scripts cannot leave the region in which they were born.  If you want region crossing behaviour, please look at the options on the [[NPC]] wiki page.
 
NPCs created user these scripts cannot leave the region in which they were born.  If you want region crossing behaviour, please look at the options on the [[NPC]] wiki page.
 +
 +
NPC appearance is saved and loaded by serializing the appearance data structure to a notecard present in the same prim as the script.  The required textures should be preserved when an OAR is saved and loaded.
 +
 +
This functionality is at an early stage and method signatures could change, certainly before the release of OpenSim 0.7.2.  However, we hope to avoid this.
  
 
=Functions=
 
=Functions=
Line 21: Line 25:
  
 
  osNpcCreate(string firstname, string lastname, vector position, string notecard):key
 
  osNpcCreate(string firstname, string lastname, vector position, string notecard):key
 +
 +
The notecard is the name of the notecard containing a serialized avatar appearance, or its asset UUID.  In previous versions of create, the user UUID could also be used, assuming that they were logged in to the region.  However, for security and interface simplicity, this option has been removed.  Please save an appearance to a notecard first, using osOwnerSaveAppearance() or osAgentSaveAppearance().
 +
 +
If the NPC is successfully created, then its user id is returned, which is required for all subsequent functions.
  
 
===osNpcRemove===
 
===osNpcRemove===
  
 
  osNpcRemove(key npc):void
 
  osNpcRemove(key npc):void
 +
 +
Remove the given avatar from the region.
  
 
==Get and Set==
 
==Get and Set==
 
===osNpcGetRot===
 
===osNpcGetRot===
 +
 +
Gets the rotation of the avatar.  Only the rotation around the Z plane in Euler rotation (horizontal rotation) has any meaning.
  
 
  osNpcGetRot(key npc):rotation
 
  osNpcGetRot(key npc):rotation
Line 34: Line 46:
  
 
  osNpcSetRot(key npc, rotation rot):void
 
  osNpcSetRot(key npc, rotation rot):void
 +
 +
Set the rotation of the avatar.  Only setting the rotation in the Z plane in Euler rotation will have any meaningful effect (turning the avatar to point in one direction or another).  Setting X or Y Euler values will result in the avatar rotating in an undefined manner.
  
 
===osNpcGetPos===
 
===osNpcGetPos===
  
 
  osNpcGetPos(key npc):vector
 
  osNpcGetPos(key npc):vector
 +
 +
Return the current position of the NPC.
  
 
===osNpcMoveToTarget===
 
===osNpcMoveToTarget===
  
  osNpcMoveToTarget(key npc, vector position, int options):void
+
  osNpcMoveToTarget(key npc, vector target, int options):void
 +
 
 +
Move the avatar to a given target over time.  How the avatar will get there depends on the following options.
 +
 
 +
* OS_NPC_FLY - Fly the avatar to the given position.  The avatar will not land unless the OS_NPC_LAND_AT_TARGET option is also given.
 +
* OS_NPC_NO_FLY - Do not fly to the target.  The NPC will attempt to walk to the location.  If it's up in the air then the avatar will keep bouncing hopeless until another move target is given or the move is stopped
 +
* OS_NPC_LAND_AT_TARGET - If given and the avatar is flying, then it will land when it reaches the target.  If OS_NPC_NO_FLY is given then this option has no effect.
 +
 
 +
OS_NPC_FLY and OS_NPC_NO_FLY are options that cannot be combined - the avatar will end up doing one or the other.  If you want the avatar to fly and land at the target, then OS_NPC_LAND_AT_TARGET must be combined with OS_NPC_FLY.  For instance,
 +
 
 +
osNpcMoveToTarget(npc, llGetPos() + <9,9,5>, OS_NPC_FLY|OS_NPC_LAND_AT_TARGET);
  
 
===osNpcStopMoveToTarget===
 
===osNpcStopMoveToTarget===
  
 
  osNpcStopMoveToTarget(key npc):void
 
  osNpcStopMoveToTarget(key npc):void
 +
 +
Stop a current move to a target.
  
 
==Communication==
 
==Communication==
Line 52: Line 80:
  
 
  osNpcSay(key npc, string message):void
 
  osNpcSay(key npc, string message):void
 +
 +
Get the NPC to say the given message.
  
 
==Appearance==
 
==Appearance==
  
===osNpcLoadAppearance===
+
===osOwnerSaveAppearance===
  
osNpcLoadAppearance(key npc, string notecardNameOrUuid):void
+
 
 +
 
 +
===osAgentSaveAppearance===
  
 
===osNpcSaveAppearance===
 
===osNpcSaveAppearance===
  
 
  osNpcSaveAppearance(key npc, string notecardName):key
 
  osNpcSaveAppearance(key npc, string notecardName):key
 +
 +
===osNpcLoadAppearance===
 +
 +
osNpcLoadAppearance(key npc, string notecardNameOrUuid):void
 +
  
 
=Example=
 
=Example=
 +
 +
=Questions/Comments=
 +
 +
Please feel free to write any questions or comments you have about OSSL NPC functionality here.

Revision as of 16:59, 11 August 2011

This page is under active construction

Contents

Introduction

Since 12th August 2011, OpenSim had provided a number of functions for creating and manipulating NPCs. These replace the previous functions, that had stopped working by OpenSim 0.7.1.1 (possibly broken since OpenSim 0.6.9).

The general philosophy in creating these new functions is to

  1. Give script writers the simple tools needed to create more sophisticated behaviour.
  1. Avoid duplicating existing LSL and OSSL functions. For instance, finding out what state an agent is in can be done through llGetAgentInfo() rather than creating a special NPC function.

NPCs are controlled via a script which must be in the same region as the NPC. This could be housed in an attachment that is attached to the avatar.

NPCs created user these scripts cannot leave the region in which they were born. If you want region crossing behaviour, please look at the options on the NPC wiki page.

NPC appearance is saved and loaded by serializing the appearance data structure to a notecard present in the same prim as the script. The required textures should be preserved when an OAR is saved and loaded.

This functionality is at an early stage and method signatures could change, certainly before the release of OpenSim 0.7.2. However, we hope to avoid this.

Functions

Create and Remove

osNpcCreate

osNpcCreate(string firstname, string lastname, vector position, string notecard):key

The notecard is the name of the notecard containing a serialized avatar appearance, or its asset UUID. In previous versions of create, the user UUID could also be used, assuming that they were logged in to the region. However, for security and interface simplicity, this option has been removed. Please save an appearance to a notecard first, using osOwnerSaveAppearance() or osAgentSaveAppearance().

If the NPC is successfully created, then its user id is returned, which is required for all subsequent functions.

osNpcRemove

osNpcRemove(key npc):void

Remove the given avatar from the region.

Get and Set

osNpcGetRot

Gets the rotation of the avatar. Only the rotation around the Z plane in Euler rotation (horizontal rotation) has any meaning.

osNpcGetRot(key npc):rotation

osNpcSetRot

osNpcSetRot(key npc, rotation rot):void

Set the rotation of the avatar. Only setting the rotation in the Z plane in Euler rotation will have any meaningful effect (turning the avatar to point in one direction or another). Setting X or Y Euler values will result in the avatar rotating in an undefined manner.

osNpcGetPos

osNpcGetPos(key npc):vector

Return the current position of the NPC.

osNpcMoveToTarget

osNpcMoveToTarget(key npc, vector target, int options):void

Move the avatar to a given target over time. How the avatar will get there depends on the following options.

* OS_NPC_FLY - Fly the avatar to the given position.  The avatar will not land unless the OS_NPC_LAND_AT_TARGET option is also given.
* OS_NPC_NO_FLY - Do not fly to the target.  The NPC will attempt to walk to the location.  If it's up in the air then the avatar will keep bouncing hopeless until another move target is given or the move is stopped
* OS_NPC_LAND_AT_TARGET - If given and the avatar is flying, then it will land when it reaches the target.  If OS_NPC_NO_FLY is given then this option has no effect.

OS_NPC_FLY and OS_NPC_NO_FLY are options that cannot be combined - the avatar will end up doing one or the other. If you want the avatar to fly and land at the target, then OS_NPC_LAND_AT_TARGET must be combined with OS_NPC_FLY. For instance,

osNpcMoveToTarget(npc, llGetPos() + <9,9,5>, OS_NPC_FLY|OS_NPC_LAND_AT_TARGET);

osNpcStopMoveToTarget

osNpcStopMoveToTarget(key npc):void

Stop a current move to a target.

Communication

osNpcSay

osNpcSay(key npc, string message):void

Get the NPC to say the given message.

Appearance

osOwnerSaveAppearance

osAgentSaveAppearance

osNpcSaveAppearance

osNpcSaveAppearance(key npc, string notecardName):key

osNpcLoadAppearance

osNpcLoadAppearance(key npc, string notecardNameOrUuid):void


Example

Questions/Comments

Please feel free to write any questions or comments you have about OSSL NPC functionality here.

Personal tools
General
About This Wiki