Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Merging two 'online' scripts.

Keelia DeCuir
Registered User
Join date: 18 Feb 2007
Posts: 19
05-23-2007 15:23
Hi, I have two scripts, the Online Status Indicator v1.6 and another from Moopf Murray's site. I have been hacking at each script in an attempt to get what I'm after, but don't know where to go from here, I am not a scripter! I want a script where I can say an avatar name and the object will give the blue dialog menu with the avatars online status and give another blue menu if/when the status changes.

The Online Status script, I have got to a stage where it will give the status of the owner or landowner only, and keeps giving the status at the set 30 second interval. I don't know how to tell the script to only give the blue menu if the status has changed.

CODE

list dialog = ["OK"];
integer dialog_channel = 1111;
key target = "";
integer flags;
integer gIsOnline = FALSE;
integer gLandOwner = FALSE;
key gKey = NULL_KEY;
string avatarName = "";
float UPDATE_INTERVAL = 30.0;

updateStatus(string s)
{
key k = llGetLandOwnerAt(llGetPos());

if(s=="1")
{
gIsOnline = TRUE;
}
else
{
gIsOnline = FALSE;
}
}



key getWhom()
{
if(gKey == NULL_KEY)
{
if(gLandOwner)
{
return llGetLandOwnerAt(llGetPos());
}
else
{
return llGetOwner();
}
}
else
{
return gKey;
}
}



doUpdate()
{
llRequestAgentData(getWhom(),DATA_ONLINE);
}

updateName()
{
llRequestAgentData(getWhom(),DATA_NAME);
}

enable()
{
updateName();
doUpdate();
llSetTimerEvent(1);
llWhisper(0,"Online status display enabled.");
}

disable()
{
llWhisper(0,"Online status display disabled.");
}



default
{
state_entry()
{
llListen(0, "", llGetOwner(), "");
enable();
llWhisper(0,"Type /ol help for a list of commands");
}

on_rez(integer n)
{
llResetScript();
}

dataserver(key req, string data)
{
if(data == "1" || data == "0")
{
updateStatus(data);
}
else
{
avatarName = data;
llSetTimerEvent(UPDATE_INTERVAL);
}
}

timer()
{
doUpdate();
if(gIsOnline)
{
llDialog(llGetOwner(),avatarName + " is Online", dialog, dialog_channel);
}
else
{
llDialog(llGetOwner(),avatarName + " is Offline", dialog, dialog_channel);
}
}

listen(integer number, string name, key id, string msg)
{
if (llGetSubString(msg, 0,0) != "/")
{
return;
}
list argv = llParseString2List(msg, [" "], []);
integer argc = llGetListLength(argv);
string cmd = llToLower(llList2String(argv, 0));
if(cmd == "/ol")
{
string arg = llToLower(llList2String(argv, 1));
if(arg=="on")
{
enable();
}
else if(arg=="off")
{
disable();
}
else if(arg=="land")
{
gLandOwner = TRUE;
gKey = NULL_KEY;
updateName();
}
else if(arg=="key")
{
gKey = llList2Key(argv,2);
updateName();
}
else if(arg=="me")
{
gLandOwner = FALSE;
gKey = NULL_KEY;
updateName();
}
else if(arg=="help")
{
llWhisper(0,"/ol on - activate online status display");
llWhisper(0,"/ol off - disable online status display");
llWhisper(0,"/ol land - display online status for owner of this land");
llWhisper(0,"/ol me - display your online status");
}
}
}

}






The second script I have got to the stage where I can say any avatar name and get the online status.

CODE

key requestID;
key id;
list dialog = ["OK"];
string avatarName;
integer dialog_channel = 1111;
integer listenID;

default
{
state_entry()
{
llListenRemove(listenID);

listenID = llListen(100,"",llGetOwner(),"");
}

listen( integer chan, string name, key id, string msg )
{
string avatarName = llDumpList2String(llParseString2List(msg,[" "],[]),"+");

requestID = llHTTPRequest("http://www.sldata.com/public/name2key/query.php?avname="+avatarName,[HTTP_METHOD,"GET"],"");
}

http_response(key request_id, integer status, list metadata, string body)
{
//Check for a success response
if (status == 200 && request_id == requestID)
{

//Split the response up into its parts
list bits = llParseString2List(body,[","],[]);

//Extract the avatar name
string avatarName = llList2String(bits,0);

//Extract the avatar key
string avatarKey = llList2String(bits,1);

//If the avatar key == -1 then the service couldn't find the avatar
if (avatarKey == "-1")
{
llOwnerSay("There is no avatar named "+avatarName);
}
else
{
//Otheriwse we found the avatar and we ouput the key
llRequestAgentData(avatarKey, DATA_ONLINE);
}
}
else {
//If the system isn't available this code block will run
llOwnerSay("Sorry, the service is not currently available");
}
}
dataserver(key req, string data)
{
if(data == "1")
{
llDialog(llGetOwner(), "Online", dialog, dialog_channel);
}
else
{
llDialog(llGetOwner(), "Offline", dialog, dialog_channel);
}
}
}


If someone can help me or at least give me a kick in the right direction, I would be grateful!

Thanks

Keelia
Ultralite Soleil
Registered User
Join date: 31 Aug 2006
Posts: 108
05-23-2007 15:35
Short version: Your script will have to maintain a list of all the avatar names you've said so far, and their online/offline status. Then when it does the regular 30 second check, instead of saying "NAME is online/offline", it will only say something if the current status is different from the status you stored for that avatar in your list.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-24-2007 00:57
The other problem being that until you know the target avatar's key you cannot obtain any information about them. So you will need to use a name2key database lookup to obtain this.
_____________________
I'm back......
Keelia DeCuir
Registered User
Join date: 18 Feb 2007
Posts: 19
05-24-2007 04:35
Thank you for your reply,

So if I only want to keep track of one person at a time, can it store only the current avatar and 'erase' the rest? If so, how do I go about doing this?

Thanks

Keelia
Ultralite Soleil
Registered User
Join date: 31 Aug 2006
Posts: 108
05-24-2007 05:04
Then it becomes simpler. You just need one string variable (CurrentAvatarName) and one integer variable (CurrentAvatarStatus). These should be global variables, declared at the top of the script. Whenever you say a name, store the name in CurrentAvatarName, overwriting whatever was there before. Whenever you retrieve that avatar's status, compare the status you just got with the status stored in CurrentAvatarStatus. If they are different, have the script speak the status. If they are the same, speak nothing. In either case, store the new status in CurrentAvatarStatus.