User:Cow Taurog/Online indicator

From Second Life Wiki
< User:Cow Taurog
Revision as of 17:24, 14 March 2009 by Cow Taurog (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

These scripts will make a simple online indicator that will turn red if the user is offline, yellow if they are online, and green if they are in the same sim. It will also show hovertext when clicked. Place all of these scripts in the same prim, the particle script is optional. You can leave the settings as they are to use yourself, or you can use another person's key. If that person isn't in the sim when you start the script for the first time, you'll have to enter their name in the settings also. The base script will send a link message with "online", "offline", or "currentsim" as the string, and the user's name as the id, which also makes it useful for applications besides this.

Base

<lsl> integer DEBUG=0; // 0-none, 1-minimal, 2-verbose key gkUser=""; // The UUID of the user you want to target, leave blank to use yourself string gsName=""; // Defined at startup from the key if blank, otherwise must belong to the key above float gfPollFreq=90; // How often to check the target's status integer giNum=39222; // The linkmessage channel to use to output data (offline, online, currentsim)

default{

   on_rez(integer param){llResetScript();}
   changed(integer change){if(change&CHANGED_OWNER){llResetScript();}}
   money(key id,integer amount){llInstantMessage(id,"Thanks, "+llKey2Name(id)+".");}

state_entry(){

       //llSetPayPrice(1,[1,5,10,100]);
       llAllowInventoryDrop(TRUE);
       if(gkUser==""){gkUser=llGetOwner();}
       if(gsName==""){gsName=llKey2Name(gkUser);}
       llSetTimerEvent(gfPollFreq);
       llRequestAgentData(gkUser,DATA_ONLINE);
   }
   timer(){
       llRequestAgentData(gkUser,DATA_ONLINE);
   }
   dataserver(key requested, string data){
       if(DEBUG==2){llOwnerSay("Dataserver: "+data);}
       if(data=="0"){
           llMessageLinked(LINK_SET,giNum,"offline",(key)gsName);
       }
       if(data=="1"){
           if(llGetAgentSize(gkUser)!=ZERO_VECTOR){
               llMessageLinked(LINK_SET,giNum,"currentsim",(key)gsName);
           }
           else{
               llMessageLinked(LINK_SET,giNum,"online",(key)gsName);
           }
       }
   }

} </lsl>

Text/color

<lsl> integer DEBUG=0; // 0-none, 1-minimal, 2-verbose integer giNum=39222; // The linkmessage channel to use to output data (offline, online, currentsim) string gsMess; string gsName;

default{

   on_rez(integer param){llResetScript();}
   changed(integer change){if(change&CHANGED_OWNER){llResetScript();}}
   state_entry(){llSetText("",<0,0,0>,1);}
   link_message(integer sender,integer num,string mess,key id){if(num==giNum){
       gsMess=mess;
       gsName=(string)id;
       if(gsMess=="online"){llSetColor(<1,1,0>,ALL_SIDES);}
       if(gsMess=="offline"){llSetColor(<1,0,0>,ALL_SIDES);}
       if(gsMess=="currentsim"){llSetColor(<0,1,0>,ALL_SIDES);}
   }}
   touch_start(integer num){
       if(gsMess=="online"){llSetText(gsName+" is online, and in another sim",<1,1,0>,1);}
       if(gsMess=="offline"){llSetText(gsName+" is offline",<1,0,0>,1);}
       if(gsMess=="currentsim"){llSetText(gsName+" is online, and in this sim",<0,1,0>,1);}
       llSleep(5);
       llSetText("",<0,0,0>,1);
   }

} </lsl>

Particle

<lsl> list glParticle; default{

   link_message(integer sender,integer num,string mess,key id){
       if(mess=="online"){state online;}
       if(mess=="currentsim"){state currentsim;}
       if(mess=="offline"){state offline;}
   }

} state online{

   link_message(integer sender,integer num,string mess,key id){
       if(mess=="online"){state online;}
       if(mess=="currentsim"){state currentsim;}
       if(mess=="offline"){state offline;}
       if(mess=="particleoff"){state particleoff;}
   }
   state_entry(){
       glParticle=[
           PSYS_SRC_TEXTURE,(string)"",
           PSYS_PART_START_SCALE,<0.5,0.5,0.5>,
           PSYS_PART_START_COLOR,<1.0,1.0,0.0>,
           PSYS_PART_START_ALPHA,1.0,
           PSYS_PART_END_SCALE,<0.5,0.5,0.5>,
           PSYS_PART_END_COLOR,<1.0,1.0,0.0>,
           PSYS_PART_END_ALPHA,1.0,
           PSYS_SRC_BURST_PART_COUNT,1,
           PSYS_SRC_BURST_RATE,5.0,
           PSYS_PART_MAX_AGE,5.0,
           PSYS_SRC_MAX_AGE,0.0,
           PSYS_SRC_PATTERN,PSYS_SRC_PATTERN_DROP, 
           PSYS_SRC_BURST_RADIUS,0.0,
           PSYS_SRC_ANGLE_BEGIN,0.0,
           PSYS_SRC_ANGLE_END,0.0,
           PSYS_SRC_OMEGA,ZERO_VECTOR, 
           PSYS_SRC_ACCEL,ZERO_VECTOR, 
           PSYS_SRC_BURST_SPEED_MIN,1.0,
           PSYS_SRC_BURST_SPEED_MAX,1.0,
           PSYS_SRC_TARGET_KEY,llGetKey(),            
           PSYS_PART_FLAGS,(0|PSYS_PART_EMISSIVE_MASK)
       ];  
       llParticleSystem(glParticle);
   }

} state currentsim{

   link_message(integer sender,integer num,string mess,key id){
       if(mess=="online"){state online;}
       if(mess=="currentsim"){state currentsim;}
       if(mess=="offline"){state offline;}
       if(mess=="particleoff"){state particleoff;}
   }
   state_entry(){
       glParticle=[
           PSYS_SRC_TEXTURE,(string)"",
           PSYS_PART_START_SCALE,<0.5,0.5,0.5>,
           PSYS_PART_START_COLOR,<0.0,1.0,0.0>,
           PSYS_PART_START_ALPHA,1.0,
           PSYS_PART_END_SCALE,<0.5,0.5,0.5>,
           PSYS_PART_END_COLOR,<0.0,1.0,0.0>,
           PSYS_PART_END_ALPHA,1.0,
           PSYS_SRC_BURST_PART_COUNT,1,
           PSYS_SRC_BURST_RATE,5.0,
           PSYS_PART_MAX_AGE,5.0,
           PSYS_SRC_MAX_AGE,0.0,
           PSYS_SRC_PATTERN,PSYS_SRC_PATTERN_DROP, 
           PSYS_SRC_BURST_RADIUS,0.0,
           PSYS_SRC_ANGLE_BEGIN,0.0,
           PSYS_SRC_ANGLE_END,0.0,
           PSYS_SRC_OMEGA,ZERO_VECTOR, 
           PSYS_SRC_ACCEL,ZERO_VECTOR, 
           PSYS_SRC_BURST_SPEED_MIN,1.0,
           PSYS_SRC_BURST_SPEED_MAX,1.0,
           PSYS_SRC_TARGET_KEY,llGetKey(),            
           PSYS_PART_FLAGS,(0|PSYS_PART_EMISSIVE_MASK)
       ];  
       llParticleSystem(glParticle);
   }

} state offline{

   link_message(integer sender,integer num,string mess,key id){
       if(mess=="online"){state online;}
       if(mess=="currentsim"){state currentsim;}
       if(mess=="offline"){state offline;}
       if(mess=="particleoff"){state particleoff;}
   }
   state_entry(){
       glParticle=[
           PSYS_SRC_TEXTURE,(string)"",
           PSYS_PART_START_SCALE,<0.5,0.5,0.5>,
           PSYS_PART_START_COLOR,<0.0,0.0,1.0>,
           PSYS_PART_START_ALPHA,1.0,
           PSYS_PART_END_SCALE,<0.5,0.5,0.5>,
           PSYS_PART_END_COLOR,<0.0,0.0,1.0>,
           PSYS_PART_END_ALPHA,1.0,
           PSYS_SRC_BURST_PART_COUNT,1,
           PSYS_SRC_BURST_RATE,5.0,
           PSYS_PART_MAX_AGE,5.0,
           PSYS_SRC_MAX_AGE,0.0,
           PSYS_SRC_PATTERN,PSYS_SRC_PATTERN_DROP, 
           PSYS_SRC_BURST_RADIUS,0.0,
           PSYS_SRC_ANGLE_BEGIN,0.0,
           PSYS_SRC_ANGLE_END,0.0,
           PSYS_SRC_OMEGA,ZERO_VECTOR, 
           PSYS_SRC_ACCEL,ZERO_VECTOR, 
           PSYS_SRC_BURST_SPEED_MIN,1.0,
           PSYS_SRC_BURST_SPEED_MAX,1.0,
           PSYS_SRC_TARGET_KEY,llGetKey(),            
           PSYS_PART_FLAGS,(0|PSYS_PART_EMISSIVE_MASK)
       ];  
       llParticleSystem(glParticle);
   }

} state particleoff{

   link_message(integer sender,integer num,string mess,key id){
       if(mess=="online"){state online;}
       if(mess=="currentsim"){state currentsim;}
       if(mess=="offline"){state offline;}
       if(mess=="particleoff"){state particleoff;}
   }
   state_entry(){
       llParticleSystem([]);
   }

} </lsl>