User:Jana Kamachi/tut email

From Second Life Wiki
Jump to navigation Jump to search

If you like this script, or any script I've released, please post on my Talk page, or I'll most likely never see it o: If you want to improve a script, just go for it!


This is a simple two part system. One of them, the master script, controls sending out the messages while the slaves actually do the work. Its much faster and efficent compared to alot of the ones out there.

Part one: Master script.

This is the control script. It takes a key on channel 50, and sends messages typed on channel 4.

key target;
list used = [0,0,0,0,
             0,0,0,0,
             0,0,0,0,
             0,0,0,0,
             0,0,0,0
            ];

_send(string subj, string msg){
      integer i=0;
      for(i=0;i<20;i++){
          if(llList2Integer(used,i) == 0){
              llSetObjectDesc(subj);
              llMessageLinked(LINK_SET,i,msg,target);
              used = llListReplaceList(used,[20],i,i);
              //llOwnerSay((string)i + "::" + (string)msg);
              if(subj == "msg"){
                llSetObjectName(llKey2Name(llGetOwner()));
                llOwnerSay(msg);
                }
              return;
          }
      } 
}

default
{
    state_entry()
    {
        llListen(50,"",llGetOwner(),"");
        llListen(4,"",llGetOwner(),"");
        llOwnerSay("/50 <key> - where to send to");
        llOwnerSay("/4 <message> - what to send");
        llSetTimerEvent(1);
    }
    
    listen(integer c, string name, key id, string msg){
        if(c == 50){
            target = (key)msg;
        }
        if(c == 4){
            _send("msg",msg);
        }
    }
    
    timer(){
        integer i;
        
           for(i=0;i<20;i++){
                if(llList2Integer(used,i) > 0){
                    used = llListReplaceList(used,(list)(llList2Integer(used,i) - 1),i,i);
                }    
           }   
    }
}

Part Two: Slave script.

This part can be a bit tricky. Since it uses its name to decide when its supposed to do the work, it must be named properly. make 20 of these, named "t 0", "t 1", "t 2", ect. until you reach "t 19". Heres the code:

default
{
    link_message(integer s_n,integer num, string str, key id){
        if("t " + (string)num == llGetScriptName()){
            llEmail((string)id + "@lsl.secondlife.com",llGetObjectDesc(),str);  
        }   
    }
}