
Script to count unique traffic and payment info stats on an area. Or get the object itself at https://www.xstreetsl.com/modules.php?name=Marketplace&file=item&ItemID=1339636
CODE
float SCAN_WIDTH = 30.0;
float SCAN_INTERVAL = 30.0;
float gScanWidth;
rotation gRotChange;
list gKeysSeen;
list gTodoList;
integer gTodoCount = 0;
key gQueryId;
integer gNoPayInfo = 0;
integer gPayOnFile = 0;
integer gPayUsed = 0;
string GetText()
{
return "\n" +
"scanned avatars = " + (string)llGetListLength (gKeysSeen) + "\n" +
"no payment info on file = " + (string)gNoPayInfo + "\n" +
"payment info on file = " + (string)gPayOnFile + "\n" +
"payment info used = " + (string)gPayUsed + "\n" +
(string)llGetFreeMemory() + " bytes free";
}
DoUpdate()
{
if (gTodoCount == 0)
{
// nothing on the todo list - rotate a little and rescan
llSetRot (llGetRot() * gRotChange);
llSensor ("", "", AGENT, 96.0, SCAN_WIDTH);
}
else
{
// pull one avatar id off the todo list and ask for payment info
key id = llList2Key (gTodoList, 0);
gTodoList = llDeleteSubList (gTodoList, 0, 0);
gTodoCount--;
gQueryId = llRequestAgentData (id, DATA_PAYINFO);
// todo: set a timer to watch for dataserver never responding
// todo: instead of the above, link message to memory scripts
}
}
default
{
state_entry()
{
llOwnerSay ("scanning..");
llSetText ("", ZERO_VECTOR, 1.0);
llSetObjectDesc("");
gScanWidth = SCAN_WIDTH * DEG_TO_RAD;
gRotChange = llEuler2Rot (<0.0, 0.0, gScanWidth>);
DoUpdate();
}
sensor (integer count)
{
integer i;
list todo;
for (i = 0; i < count; i++)
{
key id = llDetectedKey(i);
// seen this avatar before?
if (llListFindList (gKeysSeen, [id]) == -1)
{
gKeysSeen += id;
// already on the todo list?
if (llListFindList (gTodoList, [id]) == -1)
{
//llOwnerSay ("new id: " + (string)id);
gTodoList += id;
gTodoCount++;
}
}
}
if (gTodoCount == 0)
{
// nothing new on the todo list.. rescan after a pause
llSetTimerEvent (SCAN_INTERVAL);
}
else
{
// stuff on the todo list.. start processing it now
DoUpdate();
}
}
no_sensor()
{
// i'm lonely!! schedule a date
llSetTimerEvent (SCAN_INTERVAL);
}
touch_start (integer count)
{
// spam anybody daring to touch me with stats
string text = GetText();
integer i;
for (i = 0; i < count; i++)
{
llInstantMessage (llDetectedKey(i), text);
}
}
dataserver (key id, string data)
{
if (id == gQueryId)
{
gQueryId = "";
integer info = (integer)data;
// update stats based on payment info
if (info == 0)
{
// no payment info on file
gNoPayInfo++;
}
else
{
if ((info & 0x02) != 0)
{
// payment info used
gPayUsed++;
}
else
if ((info & 0x01) != 0)
{
// payment info on file
gPayOnFile++;
}
else
{
// er..
llOwnerSay ("wha?? data = " + data);
}
}
if (llGetFreeMemory() < 1500)
{
// don't want the stack & heap kissing so don't do the next update
llSetText ("full!" + GetText(), <1.0, 1.0, 1.0>, 1.0);
llSetObjectDesc (GetText());
}
else
{
DoUpdate();
}
}
}
on_rez (integer param)
{
llResetScript();
}
timer()
{
llSetTimerEvent (0.0);
DoUpdate();
}
}