Difference between revisions of "Basic Sim Status Button Indicator HUD"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "<lsl> // Generic Sim Status Button / Indicator // HUD / 1 prim // by Ackley Bing // December 2012 // // A HUD button for remote monitoring of sims. // Color indicates the sim sta…")
 
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(20 intermediate revisions by one other user not shown)
Line 1: Line 1:
<lsl>
<source lang="lsl2">
// Generic Sim Status Button / Indicator
// Generic Sim Status Button Indicator
// HUD / 1 prim
// HUD / 1 prim
// by Ackley Bing
// by Ackley Bing
// December 2012
//
//
// A HUD button for remote monitoring of sims.
// A HUD button for remote monitoring of sims.
Line 10: Line 9:
// When the sim goes down it turns red/black
// When the sim goes down it turns red/black
//
//
// To use put this in a prim and attach to your preferred HUD location.
// To use:  Put this in a prim and attach to your preferred HUD location.
// Go to the sim you want to monitor and and click the prim
// Go to the sim you want to monitor and and click the prim
// Click and HOLD the hud button to choose another sim.
// Click and HOLD the hud button (5 seconds) to choose another sim.
//
//
// Modify // Attach / Connect this to your HUD/Vehicle/etc any way you like.
// Modify // Attach / Connect this to your HUD/Vehicle/etc any way you like.


integer listenhandle;
string homeregion;
string homeregion;
key datarequestID;
SimStutusButtonColor(string data)
 
SetHomeButtonColor(string data)
{
{
     if ( data == "up" ) llSetPrimitiveParams( [ PRIM_COLOR, 4, <0.0,1.0,0.0>, 1.0 ] ); // set color to green
    vector simstatuscolor;
    else if ( data == "down" ) llSetPrimitiveParams( [ PRIM_COLOR, 4, <1.0,0.0,0.0>, 1.0 ] ); // set color to red
     if (data=="") simstatuscolor = <0.0,0.0,0.0>;  // set color to black
    else if ( data == "starting" || data == "stopping" ) llSetPrimitiveParams( [ PRIM_COLOR, 4, <1.0,1.0,0.0>, 1.0 ] ); // set color to yellow
    else
     else llSetPrimitiveParams( [ PRIM_COLOR, 4, <0.0,0.0,0.0>, 1.0 ] ); // set color to black
    {
        if ( data == "up" ) simstatuscolor = <0.0,1.0,0.0>; // set color to green
        else if ( data == "down" ) simstatuscolor = <1.0,0.0,0.0>; // set color to red
        else if ( data == "starting" || data == "stopping" ) simstatuscolor = <1.0,1.0,0.0>; // set color to yellow
        // if (homeregion!="") llOwnerSay(": http://maps.secondlife.com/secondlife/"+(llEscapeURL(homeregion))+" is "+data+"."); // uncomment if you want constant chat notifications
     }
    if (homeregion=="") simstatuscolor = <0.0,0.0,0.0>;
    llSetPrimitiveParams( [ PRIM_COLOR, 4, simstatuscolor, 1.0 ] );
    llSetText(homeregion, simstatuscolor, 1.0*(homeregion!="") );
}
}
default
default
{
{
Line 33: Line 36:
     {
     {
         llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
         llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
         SetHomeButtonColor("");
         SimStutusButtonColor("");
     }
     }
     touch_start(integer n)
     touch_start(integer n)
     {
     {
         llResetTime();
         llResetTime();
        llSetTimerEvent(30.0);
     }
     }
     touch_end(integer n)
     touch_end(integer n)
     {
     {
         if(llGetTime()<5.0 && homeregion != "") datarequestID=llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
         if(llGetTime()<5.0 && homeregion != "") llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
         else llDialog(llGetOwner(), "Is "+llGetRegionName()+" your home?", ["Yes","No"], (listenhandle = llListen(1, "", llGetOwner(), "")));
         else
        {
            llSetTimerEvent(30.0);
            llListenRemove(1);
            llListen(1, "", llGetOwner(), "");
            llDialog(llGetOwner(), "Monitor Sim Status for "+llGetRegionName()+"?", ["Yes","No","Reset"], 1);
        }
     }
     }
     listen(integer channel, string name, key id, string message)
     listen(integer channel, string name, key id, string message)
     {
     {
         if (message=="Yes")
         if (message!="Yes" && message!="No")
         {
         {
             llSetTimerEvent(30.0);
             if (message=="Reset") llResetScript();
             datarequestID=llRequestSimulatorData(homeregion=llGetRegionName(),DATA_SIM_STATUS);
             return;
         }
         }
         if (message=="No")
         else
         {
         {
             llSetTimerEvent(0.0);
             if (message=="No")
             SetHomeButtonColor(homeregion="");
            {
                if (homeregion=="") return;
                llSetTimerEvent(0.0);
                homeregion="";
            }
            else homeregion=llGetRegionName();
            llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
             llSetPrimitiveParams( [ PRIM_NAME, homeregion+" Sim Status" ] );
         }
         }
     }
     }
     timer()
     timer()
     {
     {
         if (listenhandle) llListenRemove(listenhandle--);
         llListenRemove(1);
         if (homeregion!="") llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
         if (homeregion!="") llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
        else llSetTimerEvent(0.0);
     }
     }
     dataserver(key requested, string data)
     dataserver(key requested, string data)
     {
     {
         if (requested==datarequestID) llOwnerSay("http://maps.secondlife.com/secondlife/"+llEscapeURL(homeregion)+" is "+data+(string)(datarequestID=""));
         SimStutusButtonColor(data);
        SetHomeButtonColor(data);
     }
     }
     run_time_permissions(integer perms)
     run_time_permissions(integer perms)
Line 73: Line 88:
     }
     }
}
}
</lsl>
</source>
[[Category:LSL Library]]

Latest revision as of 18:44, 22 January 2015

// Generic Sim Status Button Indicator
// HUD / 1 prim
// by Ackley Bing
//
// A HUD button for remote monitoring of sims.
// Color indicates the sim status
// Green = SIM available
// When the sim goes down it turns red/black
//
// To use:  Put this in a prim and attach to your preferred HUD location.
// Go to the sim you want to monitor and and click the prim
// Click and HOLD the hud button (5 seconds) to choose another sim.
//
// Modify // Attach / Connect this to your HUD/Vehicle/etc any way you like.

string homeregion;
SimStutusButtonColor(string data)
{
    vector simstatuscolor;
    if (data=="") simstatuscolor = <0.0,0.0,0.0>;  // set color to black
    else
    {
        if ( data == "up" ) simstatuscolor = <0.0,1.0,0.0>;  // set color to green
        else if ( data == "down" ) simstatuscolor = <1.0,0.0,0.0>;  // set color to red
        else if ( data == "starting" || data == "stopping" ) simstatuscolor = <1.0,1.0,0.0>;  // set color to yellow
        // if (homeregion!="") llOwnerSay(": http://maps.secondlife.com/secondlife/"+(llEscapeURL(homeregion))+" is "+data+"."); // uncomment if you want constant chat notifications
    }
    if (homeregion=="") simstatuscolor = <0.0,0.0,0.0>;
    llSetPrimitiveParams( [ PRIM_COLOR, 4, simstatuscolor, 1.0 ] );
    llSetText(homeregion, simstatuscolor, 1.0*(homeregion!="") );
}
default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
        SimStutusButtonColor("");
    }
    touch_start(integer n)
    {
        llResetTime();
    }
    touch_end(integer n)
    {
        if(llGetTime()<5.0 && homeregion != "") llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
        else
        {
            llSetTimerEvent(30.0);
            llListenRemove(1);
            llListen(1, "", llGetOwner(), "");
            llDialog(llGetOwner(), "Monitor Sim Status for "+llGetRegionName()+"?", ["Yes","No","Reset"], 1);
        }
    }
    listen(integer channel, string name, key id, string message)
    {
        if (message!="Yes" && message!="No")
        {
            if (message=="Reset") llResetScript();
            return;
        }
        else
        {
            if (message=="No")
            {
                if (homeregion=="") return;
                llSetTimerEvent(0.0);
                homeregion="";
            }
            else homeregion=llGetRegionName();
            llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
            llSetPrimitiveParams( [ PRIM_NAME, homeregion+" Sim Status" ] );
        }
    }
    timer()
    {
        llListenRemove(1);
        if (homeregion!="") llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
        else llSetTimerEvent(0.0);
    }
    dataserver(key requested, string data)
    {
        SimStutusButtonColor(data);
    }
    run_time_permissions(integer perms)
    {
        llTakeControls((perms && PERMISSION_TAKE_CONTROLS)*CONTROL_BACK, TRUE, TRUE);
    }
}