Change font size
It is currently Fri Aug 17, 2018 7:44 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 3   [ 21 posts ]
Go to page 1, 2, 3  Next
Author Message
 Post subject: MRM Script Examples
PostPosted: Wed Oct 27, 2010 7:20 am 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
Hi Folks.

Effective from October 27-2010
OpenSim Version: OpenSim 0.7.1 Dev a4e95c0-r/14263

As many MRM Script Example sources have disappeared, I am posting a couple here which are Still Working in 0.7.x OpenSim.

Rules to Use MRM:
1) The Owner MUST be the Creator of the actual Script File.
2) The Owner MUST be the Creator of the Prim containing the Script.
* These are there for Safety & Security and prprevents anyone else from using MRM Scripts on a region which they are not Owner of.

These MRM Settings as given to me by Adam Frisby Himself which allows the continued use of MRM. The Security components were not completed and so he said use these settings and they will work and indeed they do.
OpenSim.ini Settings
{L_CODE}:
[MRM]
     Enabled = true
     Sandboxed = false   ; default true
     SandboxLevel = "Internet"
     OwnerOnly = true


MRM-Send Script
{L_CODE}:
//MRM:C#
/*=======================================================================================================*/
using OpenSim.Region.OptionalModules.Scripting.Minimodule;

namespace OpenSim{
   class MiniModule : MRMBase
   {
      int chan = 9299;
      public override void Start()
        {   
            Host.Object.OnTouch += OnTouched;
            Host.Object.Say("Starting up script....(MRM)");
            Host.Object.Text = "MRM: Touch to make Object talk on channel " + chan; 
        }

      void OnTouched(IObject sender, TouchEventArgs e)
        {
          Host.Object.Say("Hello, I was Touched!",chan);                                     
        }
      public override void Stop()
        {
        }   
   }
}


MRM-Receive Script
{L_CODE}:
//MRM:C#
//
//*=============================================================
using OpenSim.Region.OptionalModules.Scripting.Minimodule;

namespace OpenSim{


    class MiniModule : MRMBase
    {
        public override void Start()
        {
            Host.Object.Say("Starting up script...(MRM)");
            World.OnChat += World_OnChat;
            Host.Object.Say("Subscribed to World.OnChat..");
            Host.Object.OnTouch += OnTouched;
            Host.Object.Text = "MRM : listen for Chat on non-0 Channels";
        }

        void World_OnChat(IWorld sender, ChatEventArgs e)
        {
            if (e.Sender is IAvatar && e.Channel == 9299)
            {
                Host.Object.Say("Rcvd msg on Channel " + e.Channel + " from " + e.Sender.GlobalID + " message is "+ e.Text);
            }
            else if(e.Sender is IObject && e.Channel == 9299)
            {
                Host.Object.Say("Rcvd msg on Channel " + e.Channel + " from and Object called " +e.Sender.GlobalID + " message is "+ e.Text);
            }
        }

        void OnTouched(IObject sender, TouchEventArgs e)
        {
            Host.Object.Say("Say something on a Channel other then 0 ( default ) i.e. /1 Hello ");
        }

        public override void Stop()
        {

        }
    }
}


MRM-Telehubs still work, as posted here in the Forums.

If Anyone else has MRM Scripts they wish to share, please Post them in this Thread to keep them easy to find. Please contribute your finds and examples that are known to work.

Thanks in Advance.
PS: This Topic is only stickied for 14 days from the time of Posting.

_________________
No further support of any kind, for any of my materials. Use as/is whereis.
PLEASE UNSTICKY Any Stickied Posting by myself.


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Wed Oct 27, 2010 2:01 pm 
Furious Typer
User avatar

Joined: Thu Nov 20, 2008 6:22 am
Posts: 126
Hi,

I still have my old examples i've made a while ago, but also a new one. As a new function made it finally into the 0.7 release, here is how it works :



{L_CODE}:
//MRM:C#
/*=============================================================

================================================================*/

using OpenMetaverse;
using OpenSim.Region.OptionalModules.Scripting.Minimodule;

namespace OpenSim{
   
   class MiniModule : MRMBase
   {
     
      public int chat_channel = 123;
     
      public override void Start()
        {
           
            Host.Object.Say("Starting up script...(MRM)");
            World.OnChat += World_OnChat;
            Host.Object.OnTouch += OnTouched;
            Host.Object.Text = "MRM : Dialog";
        }

      void World_OnChat(IWorld sender, ChatEventArgs e)
      {
          if(e.Channel == chat_channel)
          {
              Host.Object.Say(e.Text);
          }
      }
       
      void OnTouched(IObject sender, TouchEventArgs e)
      {
          string[] buts = new string[] {"Hello","Hola","Hallo","Ni Hao"};
          Host.Object.Dialog(e.Avatar.GlobalID, "Choose your greeting",buts,chat_channel);
      }

      public override void Stop()
      {
           
      }
   }
}



The Dialog function need the uuid of the Avatar to send the Dialog to ( which can be found in the event object of the touch event, so e.Avatar.GlobalID ) a string containing the Title or Description of the Dialog, an array of strings for the dialog buttons, and the chat-channel to send the string value of the button that has been clicked by the User. In this example, the text of the button that has been clicked is just repeated on the public chat channel.


I will post the other scripts later.

Unfortunately, i can't ignore that the MRM Core isn't developed any further by the Moment. There are still some serious Bugs in MRM which makes working with it still a bit annoying, and maybe also dangerous for your sim, as running MRM's sandboxed, in a separate AppDomain, still isn't working as supposed.
As i still think, that MRM's are a really powerfull tool for OpenSim Scripters, i can only hope that there might be a c# Guru out there, who might me able to fix some of the more serious flaws in MRM.

regards

Ziah


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Wed Oct 27, 2010 2:15 pm 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
THANK YOU ... THANK YOU... THANK YOU !!! :D

I'm Soooo Glad your still about the place, I was saddened to see your examples gone when Elgg was removed and I was not sure you were still around here.

Nice to see you Ziah !

_________________
No further support of any kind, for any of my materials. Use as/is whereis.
PLEASE UNSTICKY Any Stickied Posting by myself.


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Wed Oct 27, 2010 2:16 pm 
Furious Typer
User avatar

Joined: Thu Nov 20, 2008 6:22 am
Posts: 126
Hi again,

here's another, older one, but i like it as it demonstrates some cool tricks you can do with MRM's:
{L_CODE}:
//MRM:C#

/*=============================================================

================================================================*/


using System.Timers;
using OpenMetaverse;
using OpenSim.Region.OptionalModules.Scripting.Minimodule;

namespace OpenSim{



   class MiniModule : MRMBase
   {

        Timer repeater = new Timer();
        string avs_in_region;
        private Vector3 obj_pos;

        void GetUsers(object source, ElapsedEventArgs e)
        {
            //List the users, currently present on this Sim..
            avs_in_region = "";
            float av_dist = 0.0f;
            IAvatar[] avs = World.Avatars;
            for (int i = 0; i < avs.Length; i++)
            {
               if(avs[i].IsChildAgent) // the avatar is not in the current Region, but on a Neighbour Region
               {
                  avs_in_region += "(C:) ";
               }
               avs_in_region += avs[i].Name;
               avs_in_region += " " + avs[i].WorldPosition;
               av_dist = Vector3.Distance(obj_pos,avs[i].WorldPosition);
               avs_in_region += "  Distance : " + av_dist +"\n";
            }
            Host.Object.Text = avs_in_region;
            if(avs.Length == 0)
            {
               //Nobody here, so we can suspend the timer..
               repeater.Enabled = false;
               Host.Object.Text = "MRM : No Avatars present. Offline.";
            }           
        }
       
        void Repeat(int interval)
        {   
            //Activate the Timer
            repeater.Interval = interval;
            repeater.Elapsed += new ElapsedEventHandler(GetUsers);             
            repeater.AutoReset = true;
            repeater.Enabled = true;
        }
       
        public override void Start()
        {
            Host.Object.Say("Starting up script...(MRM)");
            World.OnNewUser += OnUser; 
            Host.Object.Text = "MRM : Execute Task every nn Seconds";
            obj_pos = Host.Object.WorldPosition;
            Repeat(10000);
        }

        public void OnUser(IWorld world, NewUserEventArgs e)
        {
           //Someone entered the Simulator, if the Timer was suspended, reactivate...
           if(!repeater.Enabled)
           {
                  repeater.Enabled = true;
           }
        }
 
        public override void Stop()
        {
            repeater.Enabled = false;
        }
   }
}


1. the use of the System.Timers. A good Example of how you can use the whole power of c# in MRM's. System.Timers is used as a scheduler to trigger recurring tasks.
2. Use of the 'World' Object, here, World.Avatars, for a quick access to all Objects, and/or Avatars in a Sim. I use it do suspend a script when nobody is in the Sim to see the result.
3. Use of the OnUser Event. Here used to wake the script, if suspended, as soon as a new Avatar enters the Sim.


regards

Ziah


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Fri Oct 29, 2010 3:55 pm 
Furious Typer
User avatar

Joined: Thu Nov 20, 2008 6:22 am
Posts: 126
...and another one : Making a HttpRequest from a MRM Script :

{L_CODE}:
//MRM:C#
/*=============================================================

================================================================*/
using System.IO;
using System.Net;
using System.Text;
using OpenSim.Region.OptionalModules.Scripting.Minimodule;
using OpenMetaverse;

namespace OpenSim{

   class MiniModule : MRMBase
   {
     
     
   
      public override void Start()
        {   
            Host.Object.OnTouch += OnTouched;
            Host.Object.Text = "Touch to make a http Request to geocoder.us"; 
        }
   
   
      void OnTouched(IObject sender, TouchEventArgs e)
        {
           
           try
            {
                StringBuilder sb = new StringBuilder();

                byte[] buf = new byte[8192];
                HttpWebRequest request =
                    (HttpWebRequest) WebRequest.Create("http://rpc.geocoder.us/service/csv?address=1600+Pennsylvania+Ave,+Washington+DC");
                HttpWebResponse response = (HttpWebResponse) request.GetResponse();

                Stream resStream = response.GetResponseStream();

                string tempString = null;
                int count = 0;

                do
                {
                    count = resStream.Read(buf, 0, buf.Length);
                    if (count != 0)
                    {
                        tempString = Encoding.ASCII.GetString(buf, 0, count);
                        sb.Append(tempString);
                    }
                } while (count > 0);
                Host.Object.Say(sb.ToString());
            }
            catch (WebException)
            {
                Host.Object.Say("WebException occured");
            }                                               
        }

      public override void Stop()
        {

        }   
   }
}


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Fri Oct 29, 2010 4:00 pm 
Furious Typer
User avatar

Joined: Thu Nov 20, 2008 6:22 am
Posts: 126
This one uses a Webservice :

{L_CODE}:
//MRM:C#
/*=============================================================

================================================================*/

using System.Xml;
using OpenSim.Region.OptionalModules.Scripting.Minimodule;
using OpenMetaverse;

namespace OpenSim{

   class MiniModule : MRMBase
   {
     
     
   
      public override void Start()
        {   
            Host.Object.OnTouch += OnTouched;
            Host.Object.Say("Starting up script...(MRM)");
            Host.Object.Text = "Touch to get actual London Time"; 
        }
   
   
      void OnTouched(IObject sender, TouchEventArgs e)
        {
           try
            {
                // Retrieve XML document 
                XmlTextReader reader = new XmlTextReader("http://www.nanonull.com/TimeService/TimeService.asmx/getCityTime?city=London"); 
 
                // Skip non-significant whitespace 
                reader.WhitespaceHandling = WhitespaceHandling.Significant; 
                reader.MoveToContent();
               
                Host.Object.Say(reader.ReadElementString("string"));
            }
            catch (XmlException)
            {
                Host.Object.Say("Exception occured");
            }
                                             
        }

      public override void Stop()
        {


        }   
   }
}



isn't it cool how much easier it is to query a XML - Webservice? You just have to find the right element in the XML - Response...

regards

Ziah


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Sun Oct 31, 2010 5:51 pm 
Furious Typer
User avatar

Joined: Thu Nov 20, 2008 6:22 am
Posts: 126
and here are two smaller scripts which are just introducing some MRM Function which are maybe not commonly know to everybody...

1. Owner and Creator
{L_CODE}:
//MRM:C#
/*=============================================================

================================================================*/

using OpenSim.Region.OptionalModules.Scripting.Minimodule;

namespace OpenSim{
   
   class MiniModule : MRMBase
   {
      public override void Start()
        {
           
            Host.Object.Say("Starting up script...(MRM)");
            Host.Object.OnTouch += OnTouched;
            Host.Object.Text = "MRM : Say Creator and Owner";
        }
       
       void OnTouched(IObject sender, TouchEventArgs e)
       {
           Host.Object.Say("I was Created by : " + Host.Object.CreatorID);
           Host.Object.Say("My Owner is      : " + Host.Object.OwnerID);
        }

        public override void Stop()
        {
           
        }

   }
}


The Host.Object.CreatorID and Host.Object.OwnerID are new Properties that came with 0.7....


2. Touch Args
{L_CODE}:
//MRM:C#
/*=============================================================

================================================================*/

using OpenSim.Region.OptionalModules.Scripting.Minimodule;

namespace OpenSim{
   
   class MiniModule : MRMBase
   {
      public override void Start()
        {
           
            Host.Object.Say("Starting script...(MRM)");
            Host.Object.OnTouch += OnTouched;
            Host.Object.Text = "MRM : show Args deliverd by touch event..";
        }
               
       void OnTouched(IObject sender, TouchEventArgs e)
       {
           Host.Object.Say("TouchEventArgs :\n");
           Host.Object.Say(e.Avatar.Name + " " + e.Avatar.WorldPosition);
           Host.Object.Say("BiNormal : " + e.TouchBiNormal);
           Host.Object.Say("MaterialIndex : " + e.TouchMaterialIndex);
           Host.Object.Say("Normal : " + e.TouchNormal);
           Host.Object.Say("Position : " + e.TouchPosition);
           Host.Object.Say("TouchST : " + e.TouchST);
           Host.Object.Say("TouchUV : " + e.TouchUV);
        }

        public override void Stop()
        {
         
        }
   }
}


The Touch Event comes with a lot of Information. This is similar to the LSL llDetectedTouch* Functions.


regards

Ziah


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Wed Nov 03, 2010 10:37 am 
Furious Typer
User avatar

Joined: Thu Nov 20, 2008 6:22 am
Posts: 126
Here's a importat hint if you want to use World.Objects.Create. This Function contains a pitfall ( or Bug ? ). When i first used that function, it looked like nothing has happened and it took me a while to figure out what was wrong. Here's the working code :

{L_CODE}:
//MRM:C#
/*=============================================================

================================================================*/
using System;
using OpenMetaverse;
using OpenSim.Region.OptionalModules.Scripting.Minimodule;

namespace OpenSim{
   
   class MiniModule : MRMBase
   {
      
       
        private Vector3 new_pos = new Vector3(0.0f,0.0f,0.0f);   
        private Vector3 dftl_scale = new Vector3(0.5f,0.5f,0.5f);
      
      public override void Start()
        {
           
            Host.Object.Say("Starting up script...(MRM)");
            Host.Object.OnTouch += OnTouched;
            Host.Object.Text = "MRM : touch to create an Object";
        }


               
       void OnTouched(IObject sender, TouchEventArgs e)
       {
           Host.Object.Say("Creating a new Object...");
           new_pos = Host.Object.WorldPosition;
           new_pos.Z += 1.0F;
           IObject newobj = World.Objects.Create(new_pos);
           
           //Important, as new Object is created with Size 0...
           newobj.Scale = dftl_scale;
         
        }

        public override void Stop()
        {
           
        }

   }
}



The import part is this :

{L_CODE}:
           //Important, as new Object is created with Size 0...
           newobj.Scale = dftl_scale;


Yes, the Prim created by that Function has initially the size 0, which makes it invisible. So it's important to apply at least a something like (0.5f,0.5f,0.5f) to it.
The Object-Reference that is returned by that Function can of course also be use to apply all other Properties like Color, Textur, Shape etc...

regards

Ziah


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Thu Nov 25, 2010 11:48 am 
Furious Typer
User avatar

Joined: Thu Nov 20, 2008 6:22 am
Posts: 126
Just a Question....wouldn't be the wiki a better place for the Script Collection?


Top
 Profile  
 
 Post subject: Re: MRM Script Examples
PostPosted: Thu Nov 25, 2010 3:53 pm 
OSG Elite
User avatar

Joined: Wed Mar 11, 2009 3:57 pm
Posts: 444
Well, as things have progressed along, the OSGrid has more or less become the defacto resource for a lot of information related to OpenSimulator in general.

While the OpenSim.Wiki went fallow for quite sometime it seems to be getting some revival (Since November.01) but nothing overly significant as yet. I feel a large part of the reason for the state of the wiki is that it's not as user friendly and the search system was busted for over a year until just recently when Terravus found the cause and repaired it.

There was also some talk in late 2009/early 2010 about the entire OpenSimulator.org site being redone which I know for some folks pretty much dampened their enthusiasm to work on something that was apparently going to either go away or evolve into something completely different.

_________________
No further support of any kind, for any of my materials. Use as/is whereis.
PLEASE UNSTICKY Any Stickied Posting by myself.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 3   [ 21 posts ]
Go to page 1, 2, 3  Next


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net