Chat Relay System

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

Reply to "Chat Relay System"

Here you can reply to the paste above