Bot Global

From Virtual World Web Wiki
Jump to: navigation, search

The Bot JavaScript global object is available from server world scripts and provides methods and objects for creating, clothing, and working with NPC avatars

  • This is a JavaScript global object named Bot

Remarks [edit]

Here's a little example of the bot system in use. The script spawns a bot named "Mr. Botterson" at 5,0,5 and clothes it with object types for Legs, Torso, Hair and Feet. It then starts dancing. It creates a trigger volume around the bot as well. If you enter the trigger, the bot will send a chat message into the local chat channel telling you you can click on him. If you do, the bot will stop dancing and follow you around until you click on him again.

// Create a bot, named as requested
var botName = DOM.Self.Properties.GetString("BotName");
var avatar = Bot.Create("ham.creatures.male", botName, false); // initially invisible
 
// Cloth the avatar
avatar.Wear("Legs", "bfa290ba-0d97-11e2-8ef3-e0cb4e701b2c");
avatar.Wear("Torso", "5ae25c9e-0e5e-11e2-8ef3-e0cb4e701b2c");
avatar.Wear("Hair", "ef49dd5f-c0ec-11e3-a84a-00505692287c");
avatar.Wear("Feet", "02c5bf78-18b0-11e2-8ef3-e0cb4e701b2c");
 
// Copy an audio font from under our own DOM Tree onto the avatar
DOM.Self.QuerySelector("DOMAudioFont[Title='BotSounds']").Clone(avatar.Body);
 
// Spawn the avatar at the target
var spawn = avatar.Body.SpawnArea(1.0);
spawn.TargetID = DOM.Self.QuerySelector("DOMTarget[Title='Spawn']").ID;
spawn.Start();
 
// Start it dancing
avatar.StartAnimation("Dance", "PointVictor", true);
 
// Create a trigger volume for noticing an approaching player
var trigger = avatar.Body.CreateVolume({x:6.0, y:1.0, z:6.0});
 
// Set up a click handler to start and stop following
var follow = null;
avatar.Body.OnClick = function(part) {
    if (follow == null) {
        avatar.Say("I think I'll follow " + part.Name + " around for a while.");
        avatar.StopAnimation("Dance", "PointVictor");
        follow = avatar.Body.Follow(part.Controller);
        follow.Start();
    } else {
        avatar.Say("Ok I'll stop...");
        follow.Stop();
        avatar.StartAnimation("Dance", "PointVictor", true);
        follow = null;
    }
};
 
// Set up a volume trigger to handle a player approaching
trigger.OnEnter = function(part){
    if (follow == null){
        avatar.Body.AudioEvent("Whistle");
        avatar.Say("Hey " + part.Name + ", it's "+avatar.Title+"! Click on me!");
        var face = avatar.Body.FaceTarget(part.Controller, 360.0);
        face.Start();
    }
};

Methods

CreatureAvatarExtended Create(string creatureType, string title = NULL, bool initiallyVisible = true, DOMObjectExtended parent = NULL)
Creates a new AvatarExtended (Bot) of the requested creature type
PersonaAvatarExtended CreateForParticipant(ParticipantExtended participant, string title = NULL, bool initiallyVisible = true, bool previewAnimator = false, bool showClothing = true, string formName = NULL, DOMObjectExtended parent = NULL)
Creates a new PersonaAvatarExtended (Bot) that is a clone of the avatar of the persona of the participant provided. By default the bot's clothing matches that of the participant and will change with their clothing, unless you set showClothing=false. Any clothing you set on the avatar overrides the automatic clothing. If you provide null for a title, the persona's current name will be used. If you provide an empty string, no title will be shown. Any other title will be displayed as provided.
PersonaAvatarExtended CreateForPersona(Guid personaID, string title = NULL, bool initiallyVisible = true, bool previewAnimator = false, bool showClothing = true, string formName = NULL, DOMObjectExtended parent = NULL)
Creates a new PersonaAvatarExtended (Bot) that is the avatar of the provided persona ID. By default the bot's clothing matches that of the persona and will change with their clothing, unless you set showClothing=false. Any clothing you set on the avatar overrides the automatic clothing. If you provide null for a title, the persona's current name will be used. If you provide an empty string, no title will be shown. Any other title will be displayed as provided.
bool IsAvailable()
True if the Creature Manager component is installed