Script schomehelp

From The SchomEmunity Wiki
Jump to: navigation, search

This script is the one behind the help system in the help area at the centre of the co-op building.

The script responds to a message sent from the 'Touch for help' button (that's what the listen event is listening to on channel 81). This triggers the object to pop up and start spinning before doing the serious stuff...

The serious stuff being checking who from the help team is online (the ids will all need updating for the avatars used by the help team once on schomepark), instant messaging any that are online, and emailing the schome email box if no-one is online.

It will reset when told to, or else it will reset automatically after a given time period.

Some fine tuning to be done to the IM/online avatar stuff, but otherwise works well enough. As ever any questions just ask me for a guided tour and full explanation.



//   Schome Help Script - v1 Dan Seamans/Woop Superior

////////////////////////GLOBAL VARIABLES////////////////////////////

// help team email and help message
string helpemail = "schome-SL-help@open.ac.uk";
string helpmessage = "Someone is in need of help at the Schomebase help station.";

// timer period in seconds for help station auto reset
float autoresettimeperiod = 90;

//help team keys
//woopsuperior = "820b4b3e-368e-434b-9935-cfe9c98db787";
//euphloozie = "246f138f-3f59-4864-8896-a46e661f6f70";
//schomersimpson = "1cd8d7d0-5822-42ee-81f8-2dd36b7d6539";
//fajitulip = "21c0719e-af39-4461-8a41-4558d2521954";
//zedzhao = "34dd7122-6125-492a-9cb1-36c6fd3c1377";
list helpteamkeys = ["820b4b3e-368e-434b-9935-cfe9c98db787",
                     "246f138f-3f59-4864-8896-a46e661f6f70",
                     "1cd8d7d0-5822-42ee-81f8-2dd36b7d6539"];

// position variables
vector zoffset = <0.0,0.0,1.7>; // amount to displace object
vector objectRestPos;  // at rest position of object
vector objectPos; // keeps track of current position

// boolean flag for object state
// 0 = at rest, 1 = requesting help
integer helpstatus = 0;

// used as a boolean flag
integer anyoneonline = 0;
// used as counter of how many of team have been checked
integer helpteamchecked = 0;

// list of keys used for matching queryid in data server events
list keylist = [];

//////////////////////FUNCTIONS//////////////////////////////////

// function to reset help station to rest position
resetHelp()
{
    llSetPos(objectRestPos);
    helpstatus = 0;
    objectPos = objectRestPos;
    llTargetOmega( < 0, 0, 0 >, .2 * PI, 1.0 );
    llSetLocalRot(llEuler2Rot(<0,0,0>));
    llSetTimerEvent(0);
    llSay(81,"reset");
    
}

// function to send for help when button is pushed
// first check the team listed in helpteamkeys, if
// any are online IM them, if no-one is online send
// an email to help.
sendForHelp()
{
   // need to ensure some global variables are zeroed
   keylist=[]; 
   anyoneonline = 0; 
   helpteamchecked = 0;

   integer i;
      
    for (i=0; i<llGetListLength(helpteamkeys); i++)
    {
        keylist += llRequestAgentData(llList2String(helpteamkeys,i), DATA_ONLINE); 
    }
}

default
{
    state_entry()
    {
        objectRestPos = llGetPos();
        objectPos = objectRestPos;
        llListen(81,"",NULL_KEY,"");
    }

    //  listen event to respond to help and reset commands either
    //  from objects or avatars
    listen(integer channel, string name, key id, string message)
    {
        if (llToLower(message)=="help")
        {
            if (helpstatus == 0) {
                llTargetOmega( < 0, 0, 1 >, .2 * PI, 1.0 );
                objectPos += zoffset;
                llSetPos(objectPos);
                helpstatus = 1;
                sendForHelp();
                llSetTimerEvent(autoresettimeperiod);
            }
        }
        
        if (llToLower(message)=="reset")
        {
            resetHelp();
        }
        
    }
    
    dataserver(key queryid, string data)
    {
        helpteamchecked++; // increment number of team checked
        //llSay(0,"in dataserver, help team checked="+(string)helpteamchecked);
        //llSay(0,"queryid="+(string)queryid);

        if ((integer)data == 1)
        {
            anyoneonline = 1; // yes, someone is online 
            // so IM the helper
            integer r=0;
            for (r=0; r<llGetListLength(keylist); r++)
            { 
                if (queryid==llList2String(keylist,r))
                llInstantMessage(llList2String(helpteamkeys,r),helpmessage);
            }
        }

        if (helpteamchecked == llGetListLength(helpteamkeys)
            && anyoneonline == 0)
        {
            // no-one is online, inform local chat and send email
            llSay(0,"None of the team are online at the moment.");
            llSay(0,"An email has however been sent to the team.");
            llEmail(helpemail,"SCHOMEBASE HELP REQUIRED", helpmessage);    
        }
        else if (helpteamchecked == llGetListLength(helpteamkeys)
            && anyoneonline == 1)
        {
            llSay(0,"A member of the Schome help team will be with you soon.");         
        }    
    }
    
    timer()
    {
        if (helpstatus == 1) resetHelp();    
    }

}