User:Toady Nakamura/Simple Listener

From Second Life Wiki
< User:Toady Nakamura
Revision as of 15:07, 28 January 2014 by Toady Nakamura (talk | contribs) (added simple listener)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  • Place this script in any prim.
  • Say /33 red ... /33 green ... or ... /33 blue
  • If you are the prim's owner, the prim will change color.

<lsl> integer CHN = 33; // zero channel is public chat - use a different one integer listener; // records if the listener is on or off (1 or 0) key owner; // holds the owner's key ID default {

   state_entry()
   {   
       llListenRemove(listener); // clear any old listeners
       owner = llGetOwner(); // find out who owns prim
       listener = llListen(CHN,"",owner,""); // open a listener for just the owner
   }
   
   listen(integer channel,string name,key id,string msg)
   { 
       string p = llToLower(message); // convert the message heard to lower case
       if(owner==llGetOwnerKey(id))
       {
            if (p == "red") // if what is heard is "red"
           {
               llSetColor(<1,0,0>, ALL_SIDES);  // turn the prim red on all sides
           }
           else if (p == "green")
           {
               llSetColor(<0,1,0>, ALL_SIDES);
           }
           else if (p  == "blue")
           {
               llSetColor(<0,0,1>, ALL_SIDES);
           }
           else  // if the message is none of the above ... 
           {
               llSetColor(<1,1,1>, 0);  // just the top of the box will turn white
               llOwnerSay(p);  // and it will tell you the message in open chat
           }
       llListenRemove(listener); // close that session
       listener = llListen(CHN,"",owner,""); // open a new one
   }
   
   on_rez(integer start_param) 
   {
       llResetScript();
   }
   

} </lsl>