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

From Second Life Wiki
Jump to navigation Jump to search
m
Line 16: Line 16:
// 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.


string homeregion;
vector homepos;
key datarequestID;
integer listenhandle;
integer listenhandle;
string region;
SetHomeButtonColor(string data)
key datarequestID;
{
    vector simstatuscolor;
    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
    else simstatuscolor = <0.0,0.0,0.0>; // set color to black


vector SimStutus2Color(string data)
     llSetPrimitiveParams( [ PRIM_COLOR, 4, simstatuscolor, 1.0 ] );
{
     llSetText(homeregion, simstatuscolor, 1.0*(homeregion!="") );
     if ( data == "up" ) return <0.0,1.0,0.0>; // green
     else if ( data == "down" ) return <1.0,0.0,0.0>; // red
    else if ( data == "starting" || data == "stopping" ) return <1.0,1.0,0.0>; // yellow
    else return <0.0,0.0,0.0>; // black
}
}
 
string VecXY2String(vector Pos){return "/"+(string)((integer)Pos.x)+"/"+(string)((integer)Pos.y);}
default
default
{
{
Line 33: Line 37:
     {
     {
         llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
         llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
         llSetPrimitiveParams([PRIM_COLOR, 4, SimStutus2Color(""), 1.0]);
         SetHomeButtonColor("");
     }
     }
     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 && region != "") datarequestID=llRequestSimulatorData(region,DATA_SIM_STATUS);
         if(llGetTime()<5.0 && homeregion != "") datarequestID=llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
         else llDialog(llGetOwner(), "Monitor Sim Status for "+llGetRegionName()+"?", ["Yes","No"], (listenhandle = llListen(1, "", llGetOwner(), "")));
         else
        {
            llSetTimerEvent(30.0);
            llListenRemove(listenhandle);
            listenhandle = llListen(1, "", llGetOwner(), "");
            llDialog(llGetOwner(), "Monitor Sim Status for "+llGetRegionName()+"?", ["Yes","No"], 1);
        }
     }
     }
     listen(integer channel, string name, key id, string message)
     listen(integer channel, string name, key id, string message)
     {
     {
         if (message=="Yes") datarequestID=llRequestSimulatorData(region=llGetRegionName(),DATA_SIM_STATUS);
         if (message=="Yes")
         if (message=="No" && region=="") llSetPrimitiveParams([PRIM_COLOR, 4, SimStutus2Color(""), 1.0]);
        {
            homepos=llGetPos();
            datarequestID=llRequestSimulatorData(homeregion=llGetRegionName(),DATA_SIM_STATUS);
        }
         if (message=="No" && homeregion=="") SetHomeButtonColor("");
     }
     }
     timer()
     timer()
     {
     {
         if (listenhandle) llListenRemove(listenhandle--);
         llListenRemove(listenhandle);
         if (region!="") llRequestSimulatorData(region,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(region)+" is "+data+(string)(datarequestID=""));
         if (requested==datarequestID) llOwnerSay("Sim http://maps.secondlife.com/secondlife/"+(llEscapeURL(homeregion))+" is "+data+(string)(datarequestID=""));
         llSetPrimitiveParams([PRIM_COLOR, 4, SimStutus2Color(data), 1.0]);
         SetHomeButtonColor(data);
     }
     }
     run_time_permissions(integer perms)
     run_time_permissions(integer perms)
     {
     {
         llTakeControls((perms && PERMISSION_TAKE_CONTROLS)*CONTROL_BACK, TRUE, TRUE); // required to allow script to continue to operate in 'no-script' areas and has to be activated before entering the 'no-script' area.
         llTakeControls((perms && PERMISSION_TAKE_CONTROLS)*CONTROL_BACK, TRUE, TRUE);
     }
     }
}
}
</lsl>
</lsl>
[[Category:LSL Library]]
[[Category:LSL Library]]

Revision as of 19:12, 16 August 2014

<lsl> // Generic Sim Status Button Indicator // HUD / 1 prim // by Ackley Bing // January 2013 // // 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 to choose another sim. // // Modify // Attach / Connect this to your HUD/Vehicle/etc any way you like.

string homeregion; vector homepos; key datarequestID; integer listenhandle; SetHomeButtonColor(string data) {

   vector simstatuscolor;
   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
   else simstatuscolor = <0.0,0.0,0.0>;  // set color to black
   llSetPrimitiveParams( [ PRIM_COLOR, 4, simstatuscolor, 1.0 ] );
   llSetText(homeregion, simstatuscolor, 1.0*(homeregion!="") );

} string VecXY2String(vector Pos){return "/"+(string)((integer)Pos.x)+"/"+(string)((integer)Pos.y);} default {

   state_entry()
   {
       llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
       SetHomeButtonColor("");
   }
   touch_start(integer n)
   {
       llResetTime();
   }
   touch_end(integer n)
   {
       if(llGetTime()<5.0 && homeregion != "") datarequestID=llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
       else
       {
           llSetTimerEvent(30.0);
           llListenRemove(listenhandle);
           listenhandle = llListen(1, "", llGetOwner(), "");
           llDialog(llGetOwner(), "Monitor Sim Status for "+llGetRegionName()+"?", ["Yes","No"], 1);
       }
   }
   listen(integer channel, string name, key id, string message)
   {
       if (message=="Yes")
       {
           homepos=llGetPos();
           datarequestID=llRequestSimulatorData(homeregion=llGetRegionName(),DATA_SIM_STATUS);
       }
       if (message=="No" && homeregion=="") SetHomeButtonColor("");
   }
   timer()
   {
       llListenRemove(listenhandle);
       if (homeregion!="") llRequestSimulatorData(homeregion,DATA_SIM_STATUS);
       else llSetTimerEvent(0.0);
   }
   dataserver(key requested, string data)
   {
       if (requested==datarequestID) llOwnerSay("Sim http://maps.secondlife.com/secondlife/"+(llEscapeURL(homeregion))+" is "+data+(string)(datarequestID=""));
       SetHomeButtonColor(data);
   }
   run_time_permissions(integer perms)
   {
       llTakeControls((perms && PERMISSION_TAKE_CONTROLS)*CONTROL_BACK, TRUE, TRUE);
   }

} </lsl>