Jump to content
JuneBugs Club
Sign in to follow this  
JuneBug

ONLINE INDICATOR WITH EMAIL AND IM

Recommended Posts

Script to put in a permanently rezzed object to use as a pass thru email and im sender.

 

key kQuery;
integer iLine;
integer listener;
list AvKeys;
string Display;
integer ON = TRUE;
integer i;
integer newsum;
integer oldsum;
integer Dlisten;
integer DFlag;
key name_q;
key online_q;
key KeyNow;
key user;
string status;
string owner1 = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
string owner2 = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
string email_address = "email@yahoo.com";
string email_address1 = "email@gmail.com";

default 
{
    state_entry() 
    {
        if (llGetInventoryNumber(INVENTORY_NOTECARD) > 0)
        {
            iLine = 0;
            kQuery = llGetNotecardLine(llGetInventoryName(INVENTORY_NOTECARD,0), iLine);
        }
        else
        {
            llOwnerSay("The UUID notecard is missing from this device.");
        }
    }
    
    on_rez ( integer startup)
    {
        llResetScript();
    }
    
    changed (integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
 
    dataserver(key query_id, string data) 
    {
        if (query_id == kQuery) 
        {   
            if (data != EOF) 
            {
                key newkey = (key)llStringTrim(data, STRING_TRIM);
                if (newkey)
                {
                    AvKeys += newkey;
                    iLine++; 
                    kQuery = llGetNotecardLine(llGetInventoryName(INVENTORY_NOTECARD,0), iLine);
                }
                else
                {
                    llOwnerSay ( "Invalid key in the notecard: \"" + (string) newkey + "\".  Initialization cancelled.");
                }  
            }
            else
            {
                state running; // Finished reading UUIDs from notecard
            }
        }
    }
}

state running
{
    state_entry()
    {
        llSetColor(<0,1,0>, 5);
        DFlag = TRUE;
        llSetTimerEvent(10);
    }
    
    on_rez( integer startup)
    {
        llResetScript();
    }
    
    timer()
    {
        llSetText(Display,<1,1,1>,1.0* DFlag);
        if (oldsum != newsum)  // Notify owner of any change in online status
        {
            llInstantMessage(llGetOwner(),"Online Status Change \n" + Display);
        }
        Display = "";
        i = 0;
        KeyNow = (key)llList2String(AvKeys,0);
        name_q = llRequestAgentData(KeyNow,DATA_NAME);
        oldsum = newsum;
        newsum = 0;
    }
    
    dataserver(key query, string data)
    {
        string name;
        string status;
        if(name_q == query)
        {
            name = data;
            Display += name;
            online_q = llRequestAgentData(KeyNow,DATA_ONLINE); 
        }
        else if (online_q == query)
        {
            
            //status = (string)data;
                if (data == "0")
                {
                status = "Offline";
                }
                else if (data == "1")
                {
                status = "Online";
                }
                //llSay(0,(string) status);
            //newsum  += status;
            Display += " : " +(string) status + "\n";
            if ( ++i <= llGetListLength(AvKeys) )
            {
                KeyNow = (key)llList2String(AvKeys,i);
                name_q = llRequestAgentData(KeyNow,DATA_NAME);
            }
        }
    }
    
    touch_start(integer total_number)  // Switch timer ON/OFF, activate dialog options
    {
         llListenRemove(listener);//A previous user may not have responded. Make sure we don't leak!
        integer channel = ~(integer)llFrand(1000.0);
        listener = llListen(channel,"","","");
        user = llKey2Name(llDetectedKey(0));
        llTextBox(llDetectedKey(0),"Type a message here",channel);
    }
    
    listen (integer channel, string name, key id, string message)
    {
        if (status = "Online")
        {
            llInstantMessage(owner1, (string) user +" says "+ message);
            llInstantMessage(owner2, (string) user +" says "+ message);
        }
        else if (status = "Offline")
        {
           llEmail( email_address, "Email Subject", (string) user + " sent this message \n\n\n"+ message);
        llEmail( email_address1, "Email Subject", (string) user + " sent this message \n\n\n"+ message);
       
        }
        llListenRemove(listener);
    }
    
    changed (integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
} 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.