Hello I need the same functionality. To track when user arrive and when left. When arrives works good as expected, but doesn't work when user left. I can't detect who left. I use code above with a little bit difference. Can somebody tell me what I'm doing wrong ? Why departures is empty?
list im_recipients = []; // a list of the keys of the people who will get IMed
float timer_interval = 10.0; // how often to scan the area
list jsonText;
list previous_visitors; // a list of the people who were in the area for the last scan, a global value to preserve it between scans
list current_visitors;
default
{
state_entry ()
{
llSetTimerEvent (timer_interval); // start the timer (and wait for it to trigger)
}
timer ()
{
list arrivals;
list departures;
current_visitors = llGetAgentList (AGENT_LIST_PARCEL, []); // get the list of who's here now
integer count = llGetListLength(current_visitors);
while (count) // for each current visitor (if any), working backwards through the list (beacuse it's easier)
{
key visitor = llList2Key (current_visitors, --count); // decrement the counter (to convert it to a list index, and also set it up for the while loop test next iteration) and get the visitor's key
if (llListFindList (previous_visitors, [visitor]) == -1) // are they in the list of people who were here last time?
{
arrivals += llGetDisplayName (visitor); // if not, add their name to the list of new arrivals
jsonText = llList2Json(JSON_ARRAY, ["AvatarOnline", llGetDisplayName(visitor), "timestamp", llGetTimestamp()]);
llHTTPRequest("http://159.223.99.18:8080",[ HTTP_METHOD,"POST"],jsonText);
}
}
integer count = llGetListLength(previous_visitors);
while (count) // for each visitor who was here last time
{
key visitor = llList2Key(previous_visitors, --count);
llOwnerSay(llGetDisplayName(visitor));
if (llListFindList(current_visitors, [visitor]) == -1) // are they still here?
{
departures += llGetDisplayName(visitor); // if not, add their name to the list of departures
jsonText = llList2Json(JSON_ARRAY, ["AvatarOffline", llGetDisplayName(visitor), "timestamp", llGetTimestamp()]);
llHTTPRequest("http://159.223.99.18:8080",[HTTP_METHOD,"POST"], jsonText);
}
}
previous_visitors = current_visitors; // save the list of current visitors for next time;
}
}