Re: tuuba LSL chat relay

From Whipped Ibis, 2 Years ago, written in Lua, viewed 2 times. This paste will die in 1 Second. This paste is a reply to tuuba LSL chat relay from rölli - view diff
URL https://paste.paivola.fi/view/2b54eacd Embed
Download Paste or View Raw
  1. string prefix;
  2. integer commsChannel;
  3. integer prefixBool;
  4. default
  5. {
  6.     on_rez(integer param)
  7.     {
  8.         llResetScript();  
  9.     }
  10.     state_entry()
  11.     {
  12.         prefix = "default";
  13.         prefixBool = FALSE;
  14.         commsChannel = -209138; // arbitrary negative number, important part is every relay uses the same one.
  15.         llOwnerSay("Chat Relay System initialized. The current prefix is set as: " + prefix + ". Say 'prefix' on channel 80 to change it.");
  16.         integer localListen = llListen(0,"","",""); //setup listen for nearby chat, used for picking up IC chatter.
  17.         integer cmdListen = llListen(80,"",llGetOwner(),""); //setup listen for channel 80, used for changing prefixes.
  18.         integer commsListen = llListen(commsChannel,"","",""); //setup listen for the channel used for communication between relays.
  19.     }
  20.    
  21.     listen(integer channel, string name, key id, string msg)
  22.     {
  23.        
  24.         if (channel == 80) //this entire thing just changes prefixes using channel 80. prefixBool is used to toggle between two different kinds of listening.
  25.         {
  26.             if (prefixBool == TRUE)
  27.             {
  28.                 prefix = msg;
  29.                 llOwnerSay("Prefix set to '" + prefix + "'.");
  30.                 prefixBool = FALSE;
  31.             }
  32.             else if (msg == "prefix")
  33.             {
  34.                 prefixBool = TRUE;
  35.                 llOwnerSay("Prefix change initiated. Say the new prefix on channel 80 now.");
  36.             }
  37.         }
  38.         else if (channel == 0 && id != llGetKey()) //channel 0 is nearby chat, the other requirement is that something other than the object itself said it.
  39.         {
  40.             string relayMessage = prefix+"थ"+name+"४"+msg; //weirdass glyphs are here just to try and prevent the message from having the separators.
  41.             llRegionSay(commsChannel,relayMessage);
  42.         }
  43.         else if (channel == commsChannel)
  44.         {
  45.             vector selfPos = llGetPos();
  46.             vector otherPos = llList2Vector(llGetObjectDetails(id, [OBJECT_POS]), 0);
  47.             if (llVecDist(selfPos,otherPos) > 20.0) //this whole vector thing is here to prevent an infinite loop by two nearby relays.
  48.             {
  49.                 integer prefixIndex = llSubStringIndex(msg,"थ");
  50.                 integer nameIndex = llSubStringIndex(msg,"४");
  51.            
  52.                 string relayedPrefix = llGetSubString(msg,0,prefixIndex-1);
  53.                 string relayedName = llGetSubString(msg,prefixIndex+1,nameIndex-1);
  54.                 string relayedMessage = llGetSubString(msg,nameIndex+1,llStringLength(msg)-1);
  55.            
  56.                 if (prefix == relayedPrefix)
  57.                 {
  58.                     string tempName = llGetObjectName();
  59.                     llSetObjectName(relayedName);
  60.                     llSay(0,relayedMessage);
  61.                     llSetObjectName(tempName);
  62.                 }
  63.             }
  64.         }
  65.     }
  66.    
  67. }
  68.  

Reply to "Re: tuuba LSL chat relay"

Here you can reply to the paste above