FollowRandomAvatar.cs 937 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using libsecondlife;
  5. namespace OpenSim.RegionServer.world.scripting.Scripts
  6. {
  7. public class FollowRandomAvatar : Script
  8. {
  9. public FollowRandomAvatar()
  10. : base(LLUUID.Random())
  11. {
  12. OnFrame += MyOnFrame;
  13. }
  14. private void MyOnFrame(IScriptContext context)
  15. {
  16. LLVector3 pos = context.Entity.Pos;
  17. IScriptReadonlyEntity avatar;
  18. if (context.TryGetRandomAvatar(out avatar))
  19. {
  20. LLVector3 avatarPos = avatar.Pos;
  21. float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
  22. float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
  23. LLVector3 newPos = new LLVector3(x, y, pos.Z);
  24. context.Entity.Pos = newPos;
  25. }
  26. }
  27. }
  28. }