Files
opensim/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs
lbsa71 f12ceff692 * The world can not contain ScriptFactories that creates unique instances of scripts for entities.
* Created Scripts folder to house trusted Scripts
* The test script now lives in Scripts/FollowRandomAvatar.cs
2007-04-03 20:08:30 +00:00

38 lines
937 B
C#

using System;
using System.Collections.Generic;
using System.Text;
using libsecondlife;
namespace OpenSim.RegionServer.world.scripting.Scripts
{
public class FollowRandomAvatar : Script
{
public FollowRandomAvatar()
: base(LLUUID.Random())
{
OnFrame += MyOnFrame;
}
private void MyOnFrame(IScriptContext context)
{
LLVector3 pos = context.Entity.Pos;
IScriptReadonlyEntity avatar;
if (context.TryGetRandomAvatar(out avatar))
{
LLVector3 avatarPos = avatar.Pos;
float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
LLVector3 newPos = new LLVector3(x, y, pos.Z);
context.Entity.Pos = newPos;
}
}
}
}