Respond to inworld chat
From libsecondlife
Contents |
Prerequisites
The following prerequisites are required in order for you to create your first bot by following this tutorial.
Real World
- This tutorial assumes that you were able to successfully build libsecondlife! If you have not compiled libsl, please follow the instructions on the Getting Started wikipage.
- Also, if you have no experience with the C# (c-sharp) programming language, I highly recommend that you stop now and please follow the list of links to csharp tutorials located here.
- A libsl bot that is able to login successfully. If you don't know how to create a libsl bot, please go to the "How to create a basic libSL bot" wikipage
The Code
Note: We are assuming that our main "SecondLife" variable is named "client." If you have a different name for this variable, please substitute the name accordingly
client.Self.OnChat += new AgentManager.ChatCallback(Self_OnChat); //run the above bit of code when you want to start processing all chat //make sure you have already defined "Self_OnChat" though! static void Self_OnChat(string message, ChatAudibleLevel audible, ChatType type, ChatSourceType sourceType, string fromName, LLUUID id, LLUUID ownerid, LLVector3 position) { //process chat here, see explanation of parameters below }
Parameters for Self_OnChat:
- message (string) What was said
- audible (not used)
- type (ChatType) How it was said (see this page on monodoc for the list of ChatTypes)
- sourceType (ChatSourceType) What kind of thing said it (System, Object, or Avatar)
- fromName (string) Whats the name of the person/object that said it
- id (LLUUID) Whats the key of the person/object that said it
- ownerid (LLUUID) If it was an object, who owns it?
- position (LLVector3) Where is the person/object that said it
Notes
- ChatType.Normal = Saying (20m range).. Do NOT use ChatType.Say, it is an obsolete version and will likely be removed in the near future.
- Try to check to see if the chattype is not "StartTyping" or "StoppTyping" before you process the text.. otherwise you get blank messages