OSSLNPC/de

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(osNpcRemove)
Line 150: Line 150:
 
  osNpcRemove(key npc):void
 
  osNpcRemove(key npc):void
  
Entferne den angegebenen Avatar aus der Region. Beispiel bei [[osNpcRemove]].
+
Entfernt den angegebenen Avatar aus der Region. Beispiel bei [[osNpcRemove]].
  
 
== Get and Set ==
 
== Get and Set ==

Revision as of 11:45, 30 November 2018


Contents

Einführung

Seit OpenSimulator 0.7.2 stehen eine Reihe von Funktionen zum Erstellen und Bearbeiten serverseitiger NPCs (Non Player Characters) zur Verfügung.

NPCs werden über ein Skript gesteuert, das sich in derselben Region befinden muss wie der NPC. Dies könnte in einem Anhang untergebracht sein, der mit dem Avatar verbunden ist.

Serverseitige NPCs können die Region, in der sie geboren wurden, nicht verlassen.

Das serverseitige NPC-Erscheinungsbild wird gespeichert und geladen, indem die Erscheinungsdatenstruktur mit einer Notecard serialisiert wird, die sich im selben Prim wie das Skript befindet. Die erforderlichen Texturen bleiben erhalten, wenn ein OAR gespeichert und geladen wird.

Das aktuelle Erscheinungsdatenformat (wie in Notecards, die durch das Anschein von Speichern erstellt wurden) ist das gleiche, das für das OpenSimulator-Kabelformat verwendet wird, und ist daher nicht für die direkte Bearbeitung gedacht. Mit größter Sorgfalt ist dies möglich. Weitere Informationen finden Sie unter Appearance Formats Es wird jedoch nicht empfohlen, es sei denn, Sie müssen es wirklich tun.

Aktivieren

Um diese Funktionen nutzen zu können, benötigen Sie in der Datei OpenSim.ini die folgende Konfiguration

  1. Enabled = true, eingestellt im Abschnitt [NPC].
  2. Aktivieren der Skript-Engine

in config-include/osslEnable.ini

  1. AllowOSFunctions = true
  2. Überprüfen Sie den Wert von osslNPC, um die Rechte der meisten NPC-Funktionen festzulegen.

Sie müssen möglicherweise auch die Rechte von osAgentSaveAppearance() prüfen.

Siehe Configuring Simulator Parameters#Getting information about parameters wenn Sie überprüfen müssen, ob diese Parameter richtig eingestellt wurden.

Anmerkungen

  • Wenn Sie Ihren Avatar vor dem Speichern für die Modelldarstellung verwenden, müssen Sie einige Sekunden warten, bevor Sie einen Befehl zum Speichern der Darstellung aufrufen. Dies liegt daran, dass das Speichern des Erscheinungsbilds derzeit für einen Timer ausgeführt wird, um mehrere Erscheinungsaktualisierungen vom Viewer aus zu verwalten.
  • Wenn Sie Ihren Avatar zum Erscheinungsbild des Modells verwenden, müssen Sie Anhänge auf dem NPC neu positionieren
  1. Positionieren Sie es auf sich selbst
  2. Trennen Sie sie zum Inventar
  3. Bringen Sie sie wieder an
  4. Speichern Sie das Erscheinungsbild

Dies liegt daran, dass das Speichern von Erscheinungsdaten nicht das Speichern aktueller Anlagenpositionen auslöst.

Sensing

llAgentSensor() kann verwendet werden, um einen Sensor einzurichten, der anstelle von oder von anderen Regionsentitäten NPCs erkennt.

In OpenSimulator 0.7.2, erkennt der LSL-Sensoren NPCs als normale Agenten.

In OpenSimulator 0.7.3-rc1 werden NPCs, sofern nicht anders angegeben, nur mit dem OpenSimulator-spezifischen NPC-Flag erkannt.

//Author: mewtwo0641
 
list keys = []; 
key npc;
string toucher;
key toucherkey;
vector toucherPos;
integer npc_on = FALSE;
 
default
{ 
    touch_start(integer x)
    {   
        toucherkey = llDetectedKey(0);
        toucherPos = llDetectedPos(0);
        vector npcPos = llGetPos() + <1,1,1>;
 
        if(npc_on == FALSE)
        {    
            npc = osNpcCreate("Fred", "Flintstone", npcPos, toucherkey);
            npc_on = TRUE;
            llSensor("", "", AGENT | NPC, 96.0, PI); //Will always return NPC key regardless of npc create option
            return;
        }   
 
        if(npc_on == TRUE)
        {   
            osNpcRemove(npc);
            llResetScript();
        }   
    }   
 
    sensor(integer num)
    {   
        keys = []; 
        integer i = 0;
 
        for(i; i < num; i++)
        {   
            keys += llDetectedKey(i); 
        }   
 
        llOwnerSay(llDumpList2String(keys, "\n"));
    }   
 
    no_sensor()
    {   
        keys = [];   
    }   
}

Sie können NPCs dazu bringen, erneut als AGENTs erkannt zu werden, indem Sie die unten stehende Option OS_NPC_SENSE_AS_AGENT in osNpcCreate() verwenden.

Die Begründung ist, dass die Erkennung von NPCs als AGENTs standardmäßig dazu führen kann, dass einige Skripts unbrauchbar werden (z. B. Radargeräte, die nichts über NPCs wissen). Umgekehrt verhalten sich andere Skripts jedoch möglicherweise nicht wie erwartet, wenn NPCs nicht als Agenten erkannt werden (z. B. öffnen sich automatisch geöffnete Türen für Avatare für NPCs nicht).

llGetDetectedType() setzt das NPC-Flag, wenn ein NPC erkannt wurde. Wenn der NPC mit der Option OS_NPC_SENSE_AS_AGENT erstellt wurde, wird auch das Flag AGENT gesetzt.

Datenformate

Weitere Informationen zum Format zum Speichern von Erscheinungsinformationen in Notecards finden Sie unter Appearance Formats.

Funktionen

Erstellen und entfernen

osNpcCreate

osNpcCreate(string Vorname, string Nachname, vector position, string cloneFrom):key

cloneFrom kann sein:

  • Name der Notecard, die ein serialisiertes Avatar-Erscheinungsbild enthält, oder
  • Asset-UUID der Notecard oder
  • UUID eines Avatars, der in derselben Region angemeldet ist. Beachten Sie jedoch, dass dieses Erscheinungsbild nicht dauerhaft bleibt, wenn nicht osNpcSaveAppearance() aufgerufen wird.

Wenn der NPC erfolgreich erstellt wurde, wird seine UUID zurückgegeben, die für alle nachfolgenden Funktionen erforderlich ist. Ein Beispiel ist bei osNpcCreate verfügbar.

(Nur OpenSimulator 0.7.3-rc1 und höher). Dadurch wird ein NPC erstellt, der sich im Besitz des Erstellungsskripts befindet und mit dem OpenSimulator-Only-NPC-Flag für Sensoren erkannt wird.

osNpcCreate

OpenSimulator 0.7.3-rc1 onwards.

osNpcCreate(string Vorname, string Nachname, vector position, string cloneFrom, integer optionen):key

cloneFrom kann sein:

  • Name der Notecard, die ein serialisiertes Avatar-Erscheinungsbild enthält, oder
  • Asset-UUID der Notecard oder
  • UUID eines Avatars, der in derselben Region angemeldet ist. Beachten Sie jedoch, dass dieses Erscheinungsbild nicht dauerhaft bleibt, wenn nicht osNpcSaveAppearance() aufgerufen wird.

integer Ganzzahl ist eine Menge von Flags, die 0 oder eine oder mehrere sein können

  • OS_NPC_NOT_OWNED - Erstellen Sie einen nicht besetzten NPC.
  • OS_NPC_SENSE_AS_AGENT - Erstellen Sie einen NPC, der als AGENT mit LSL-Sensoren erfasst wird
  • OS_NPC_OBJECT_GROUP - Erstellen Sie einen NPC mit der Gruppe des Objekts mit dem Skript, wenn der Eigentümer dieses Objekts Mitglied dieser Gruppe ist.

Wenn der NPC erfolgreich erstellt wurde, wird seine UUID zurückgegeben, die für alle nachfolgenden Funktionen erforderlich ist. Ein Beispiel ist bei osNpcCreate verfügbar.

osNpcRemove

osNpcRemove(key npc):void

Entfernt den angegebenen Avatar aus der Region. Beispiel bei osNpcRemove.

Get and Set

osIsNpc

OpenSimulator 0.7.3-rc1 onwards.

osIsNpc(key npc):integer

Gibt TRUE zurück, wenn der angegebene Schlüssel ein NPC ist, andernfalls false.

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.

osNpcGetOwner

OpenSimulator 0.7.3-rc1 onwards.

osNpcGetOwner(key npc):key

Return the owner of the given NPC (i.e. the owner of the script that created it). If the NPC is unowned or the input key does not belong to an NPC then returns NULL_KEY.

Movement

osNpcMoveTo

osNpcMoveTo(key npc, vector position):void

An older function that performs an osNpcMoveToTarget() by flying and landing at the target.

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_RUNNING - if given, NPC avatar moves at running/fast flying speed, otherwise moves at walking/slow flying speed.

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.

Sitting and standing

osNpcSit

OpenSimulator 0.7.3-rc1 onwards.

osNpcSit(key npc, key target, int options):void

Sit an NPC on a prim target.

osNpcStand

OpenSimulator 0.7.3-rc1 onwards.

osNpcStand(key npc):void

Make an npc stand up.

Communication

osNpcSay

osNpcSay(key npc, string message):void 
osNpcSay(key npc, int channel, string message):void

Get the NPC to say the given message.

If channel is specified then the chat is said on the given channel. The channel parameter is only available in OpenSimulator 0.7.4 development code at this time.

osNpcShout

Only in OpenSimulator 0.7.4 development code at this time.

osNpcShout(key npc, int channel, string message):void

Get the NPC to shout the given message on the given channel.

osNpcWhisper

Only in OpenSimulator 0.7.4 development code at this time.

osNpcWhisper(key npc, int channel, string message):void

Get the NPC to whisper the given message on the given channel.

Animations

osNpcPlayAnimation

OpenSimulator 0.7.3-rc1 onwards.

osNpcPlayAnimation(key npc, string animation):void

Get an NPC to play an animation. The animation can either be a key or the name of an animation in the same inventory as the script.

osNpcStopAnimation

In OpenSimulator 0.7.3-rc1 there is a bug which makes this play the animation instead. This will be corrected for the final release but in the mean time please use osAvatarStopAnimation() instead.

osNpcStopAnimation(key npc, string animation):void

Get an NPC to stop playing an animation. The animation can either be a key or the name of an animation in the same inventory as the script.

Appearance

NPC appearance is manipulated by saving and loading appearance data to notecards from the same inventory as the invoking script.

osOwnerSaveAppearance

osOwnerSaveAppearance(string notecard):key

Save the owner's current appearance to a notecard in the prim's inventory. This includes body part data, clothing items and attachments. If a notecard with the same name already exists then it is replaced. The owner must be present in the region when this function is invoked. The baked textures for the owner (necessary to recreate appearance on the NPC) are saved permanently.

osAgentSaveAppearance

osAgentSaveAppearance(key agentId, string notecard):key

Save an arbitrary avatar's appearance to a notecard in the prim's inventory. This includes body part data, clothing items and attachments. If a notecard with the same name already exists then it is replaced. The avatar must be present in the region when this function is invoked. The baked textures for the avatar (necessary to recreate appearance on the NPC) are saved permanently.

osNpcSaveAppearance

osNpcSaveAppearance(key npc, string notecard):key

Save the NPC's current appearance to a notecard in the prim's inventory. This includes body part data, clothing items and attachments. If a notecard with the same name already exists then it is replaced. The avatar must be present in the region when this function is invoked. The baked textures for the avatar (necessary to recreate appearance) are saved permanently.

osNpcLoadAppearance

osNpcLoadAppearance(key npc, string notecard):void

Load appearance from a notecard. This notecard must contain appearance data created with one of the save appearance functions.


Touch

osNpcTouch

OpenSimulator 0.7.4 development code at this time.

osNpcTouch(key npc, key objectKey, integer linkNum)

Allows the NPC to touch objects.

Examples

NPC Automator

This is a rough example script for most of the current NPC functionality. One of its major current deficiencies is that it doesn't track more than one created avatar at a time. Please feel free to improve it.

key npc;
integer listenChannel = 10;
 
default
{
    // NPC manipulator adapted by justincc 0.0.3 released 20121025
    state_entry()
    {
        llListen(listenChannel,"",NULL_KEY,"");
        llSetText("Listening on " + listenChannel, <0, 255, 0>, 1);
        llOwnerSay("Say /" + (string)listenChannel + " help for commands");
    }  
 
    listen(integer channel, string name, key id, string msg)
    {
        if (msg != "")
        {
            list commands = llParseString2List(msg, [ " " ], []);
            string msg0 = llList2String(commands, 0);
            string msg1 = llList2String(commands, 1);            
            string msg2 = llList2String(commands, 2);
            string msg3 = llList2String(commands, 3);
 
            if (msg0 == "create")
            {
                if (msg1 != "")
                {
                    string notecardName = msg1;
 
                    npc = osNpcCreate("Jane", "Doe", llGetPos() + <5, 5, 0>, notecardName);
 
                    llOwnerSay("Created npc from notecard " + notecardName);
                }
                else
                {
                    llOwnerSay("Usage: create <notecard-name>");
                }
            }  
            else if (msg0 =="createm" && msg1 != "")
            {
                osOwnerSaveAppearance("appearance");
                vector pos = llGetPos();
                integer i;
                for (i = 0; i < (integer)msg1; i++)
                {
                    osNpcCreate("John", "Doe", pos + <8, 0, 0>, "appearance");
                    llSleep(1);
                }
            }
            else if (msg0 == "remove" && npc != NULL_KEY)
            {
                osNpcSay(npc, "You will pay for this with your liiiiiivvveeessss!!!.....");
                osNpcRemove(npc);
            }   
            else if (msg0 == "say" && npc != NULL_KEY)
            {
                osNpcSay(npc, "I am your worst Nightmare!!!!");
            }   
            else if (msg0 == "move")
            {
                if (msg1 != "" && msg2 != "" && npc != NULL_KEY)
                {                
                    vector delta = <(integer)msg1, (integer)msg2, 0>;
 
                    if (msg3 != "")
                    {
                        delta.z = (integer)msg3;
                    }
 
                    osNpcMoveTo(npc, osNpcGetPos(npc) + delta);                    
                }                            
                else
                {
                    llOwnerSay("Usage: move <x> <y> [<z>]");
                }
            }   
            else if (msg0 == "moveto")
            {
                if (msg1 != "" && msg2 != "" && npc != NULL_KEY)
                {                
                    vector pos = <(integer)msg1, (integer)msg2, 0>;
 
                    if (msg3 != "")
                    {
                        pos.z = (integer)msg3;
                    }
 
                    osNpcMoveTo(npc, pos);                    
                }                            
                else
                {
                    llOwnerSay("Usage: move <x> <y> [<z>]");
                }
            }            
            else if (msg0 == "movetarget" && npc != NULL_KEY)
            {
                osNpcMoveToTarget(npc, llGetPos() + <9,9,5>, OS_NPC_FLY|OS_NPC_LAND_AT_TARGET);
            }
            else if (msg0 == "movetargetnoland" && npc != NULL_KEY)
            {
                osNpcMoveToTarget(npc, llGetPos() + <9,9,5>, OS_NPC_FLY);
            }            
            else if (msg0 == "movetargetwalk" && npc != NULL_KEY)
            {
                osNpcMoveToTarget(npc, llGetPos() + <9,9,0>, OS_NPC_NO_FLY);                
            }
            else if (msg0 == "rot" && npc != NULL_KEY)
            {
                vector xyz_angles = <0,0,90>; // This is to define a 1 degree change
                vector angles_in_radians = xyz_angles * DEG_TO_RAD; // Change to Radians
                rotation rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation                
                rotation rot = osNpcGetRot(npc);
                osNpcSetRot(npc, rot * rot_xyzq);
            }
            else if (msg0 == "rotabs" && msg1 != "")
            {
                vector xyz_angles = <0, 0, (integer)msg1>;
                vector angles_in_radians = xyz_angles * DEG_TO_RAD; // Change to Radians
                rotation rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation                
                osNpcSetRot(npc, rot_xyzq);                
            }
            else if (msg0 == "animate" && npc != NULL_KEY)
            {
                osAvatarPlayAnimation(npc, "stabbed+die_2");
                llSleep(3);
                osAvatarStopAnimation(npc, "stabbed+die_2");
            }   
            else if (msg0 == "save" && msg1 != "" && npc != NULL_KEY)
            {
                osNpcSaveAppearance(npc, msg1);
                llOwnerSay("Saved appearance " + msg1 + " to " + npc);                
            }
            else if (msg0 == "load" && msg1 != "" && npc != NULL_KEY)
            {
                osNpcLoadAppearance(npc, msg1);
                llOwnerSay("Loaded appearance " + msg1 + " to " + npc);
            }
            else if (msg0 == "clone")
            {
                if (msg1 != "")
                {
                    osOwnerSaveAppearance(msg1);
                    llOwnerSay("Cloned your appearance to " + msg1);
                }
                else
                {
                    llOwnerSay("Usage: clone <notecard-name-to-save>");
                }
            }
            else if (msg0 == "stop" && npc != NULL_KEY)
            {
                osNpcStopMoveToTarget(npc);
            }
            else if (msg0 == "sit" && msg1 != "" && npc != NULL_KEY)
            {
                osNpcSit(npc, msg1, OS_NPC_SIT_NOW);
            }
            else if (msg0 == "stand" && npc != NULL_KEY)
            {
                osNpcStand(npc);
            }
            else if (msg0 == "help")
            {
                llOwnerSay("Commands are:");
                llOwnerSay("create <notecard-name> - Create NPC from a stored notecard");
                llOwnerSay("createm");       
                llOwnerSay("remove - Remove current NPC");     
                llOwnerSay("clone <notecard-name> - Clone own appearance to a notecard");
                llOwnerSay("load <notecard-name>  - Load appearance on notecard to current npc");
                llOwnerSay("save <notecard-name>  - Save appearance of current NPC to notecard");
                llOwnerSay("animate");
                llOwnerSay("move");
                llOwnerSay("moveto <x> <y> <z> - move to absolute position");
                llOwnerSay("movetarget");
                llOwnerSay("movetargetnoland");
                llOwnerSay("movetargetwalk");
                llOwnerSay("rot");
                llOwnerSay("say");
                llOwnerSay("sit <target-uuid>");
                llOwnerSay("stop");
                llOwnerSay("stand");
            }
            else
            {
                llOwnerSay("I don't understand [" + msg + "]");
            }
        }   
    }   
}

Wandering and Puppeteer

Wizardry and Steamworks provides free-to-use NPC extendable set of scripts, published under the GPLv3 license, that implements most of the NPC functions and allows you to conveniently create NPCs. There are several several scripts available at the time of writing:

  • Wandering NPCs is a script that just makes a non-interative NPC wander around in a given area.
  • NPC Puppeteer is a system that will allow you to playwright NPCs without too much knowledge of either LSL or OSSL.


OSW NPCs Controller

OpenSimWorld provides an NPC controller that supports interactive NPCs. The system allows you to give commands to NPCs through the local chat and to build complex behaviors through easy-to-write notecards. It also allows you to specify a "map" of your region so that the NPCs can walk through it.

More information

Questions/Comments

Please leave your questions and comments on this article's talk page.

Personal tools
General
About This Wiki