Difference between revisions of "User:PixelProphet Lane/Scripts"

From Second Life Wiki
Jump to navigation Jump to search
Line 401: Line 401:
         llSay(0,"/me has "+scripts+" scripts attached using a total of "+memory);
         llSay(0,"/me has "+scripts+" scripts attached using a total of "+memory);
         llSetObjectName(ONAME);
         llSetObjectName(ONAME);
    }
}
</lsl>
}}
{{box|Grid Status Feed|
This script will periodically query the Second Life Grid Status Feed and will check to see the latest post is from the same day the request was made. If so, the script can optionally display title, link and description of the latest feed post to inform you. Posts from yesterday will not be displayed.
This script operates in a prim rezzed on your parcel, or inside an attachment.
If you are using this script in an attachment, the data will be displayed using llOwnerSay.
If you are using this script in a prim not attached to you, it will check if you are on the same region, and if so, use llOwnerSay.
If you are on a different region, it will check your online status and use llInstantMessage if you are online.
If you are offline, the script will not inform you.
<lsl>
/*
######## Grid Status Feed by PixelProphet Lane #########
######## Leave it at home, or carry it around with you #
*/
integer SEND_TITLE = TRUE;  //include title in IM ? FALSE = no, TRUE = yes
integer SEND_LINK = TRUE;  //include link in IM ? FALSE = no, TRUE = yes
integer SEND_DESC = TRUE;  //include description in IM ? FALSE = no, TRUE = yes
integer IS_ATTACHED = FALSE;
string KEYWORD_ALERT = ""; //Define a string of characters that trigger a keyword alert (Firestorm Viewer), or leave empty
string FEED_URL = "http://status.secondlifegrid.net/feed";
string PUB_DATE = "nothing";
key HTTP_REQID;
key DATA_REQID;
key OWNER;
RequstOnlineStatus()
{
    DATA_REQID = llRequestAgentData(OWNER, DATA_ONLINE);
}
RequestFeedData()
{
    HTTP_REQID = llHTTPRequest(FEED_URL,[],"");   
}
string Today()
{
    list months_short = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    list ldate = llParseString2List(llGetDate(),["-"],[]);
    string day = (string)llList2Integer(ldate, 2);
    string month = llList2String(months_short, (llList2Integer(ldate, 1)-1));;
    string year = llList2String(ldate, 0);
    return day+" "+month+" "+year;
}
default
{
    on_rez(integer arg)
    {
        if (OWNER != llGetOwner())
            llResetScript();
    }
   
    state_entry()
    {
        if (!SEND_TITLE && !SEND_LINK && !SEND_DESC)
        {
            llOwnerSay("Please set at least one of SEND_TITLE,SEND_LINK or SEND_DESC to 1");
            return;
        }
        OWNER = llGetOwner();
        llSetTimerEvent(300);
        if ((IS_ATTACHED = llGetAttached()) != 0  || <0.0, 0.0, 0.0> != llGetAgentSize(OWNER))
            RequestFeedData();
        else
            RequstOnlineStatus();
    }
   
    attach(key id)
    {
        IS_ATTACHED = llGetAttached();
    }
   
    dataserver(key queryid, string data)
    {
        if (queryid != DATA_REQID)
            return;
        if (data == "1")
            RequestFeedData();   
    }
    http_response (key request_id, integer status, list metadata, string body)
    {
        if (request_id != HTTP_REQID)
            return;
        if (status == 200) //Under normal circumstances the server will return 200
        {
            //body = llGetSubString(body, 0, 2048); //In future HTTP Requests may receive a lot more than 2048 bytes
            integer begin = llSubStringIndex(body, "<pubDate>") + 9;
            integer end = llSubStringIndex(body, "</pubDate>") - 1;
            string data;
            if (~begin && ~end) //If <pubDate> wasn't found, no need for further processing
            {
                data = llGetSubString(body, begin, end);
                if (-1 == llSubStringIndex(data,Today())) //Only posts from today
                    return;
                if (data != "" && data != PUB_DATE) //Make sure data even contains something
                {
                    PUB_DATE = data;
                    begin = llSubStringIndex(body, "<item>") + 6; //Get the beginning of first item
                    end = llSubStringIndex(body, "</item>") - 1; //Get the end of first item
                    string item = llGetSubString(body, begin, end); //Crop the string
                    string data = KEYWORD_ALERT;           
                    if (SEND_TITLE)
                    {
                        begin = llSubStringIndex(item, "<title>") + 7;
                        end = llSubStringIndex(item, "</title>") - 1;
                        if (~begin && ~end)
                            data += "\n"+llGetSubString(item, begin, end);
                    }
                    if (SEND_LINK)
                    {
                        begin = llSubStringIndex(item, "<link>") + 6;
                        end = llSubStringIndex(item, "</link>") - 1;
                        if (~begin && ~end)
                            data += "\n"+llGetSubString(item, begin, end); 
                    }
                    if (SEND_DESC)
                    {
                        begin = llSubStringIndex(item,  "<description>") + 22; //len <description><![CDATA[
                        end = llSubStringIndex(item, "</description>") - 4;
                        item = llGetSubString(item, begin, end); //Crop the string
                        if (~begin && ~end)
                            data += "\n"+item; 
                    }
                    if (data != KEYWORD_ALERT) //did we even get any data ?
                    {
                        if (IS_ATTACHED || <0.0, 0.0, 0.0> != llGetAgentSize(OWNER)) //attached, or owner on region
                            llOwnerSay(data);
                        else
                            llInstantMessage(OWNER, data);   
                    }
                }
            }
        }
    }
   
    timer()
    {
        if (IS_ATTACHED || <0.0, 0.0, 0.0> != llGetAgentSize(OWNER))
            RequestFeedData();
        else
            RequstOnlineStatus();   
     }
     }
}
}
</lsl>
</lsl>
}}
}}

Revision as of 15:06, 18 April 2012


Real Object Inventory To Dialog


Show Agent Script Count and memory


Grid Status Feed