Bot Global Remarks
From Virtual World Web Wiki
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(); } };