Simple radar script example (llGetAgentList) - SLUniverse Forums
Navigation » SLUniverse Forums > Development Discussion and Support > Scripting > Script Library » Simple radar script example (llGetAgentList)


Script Library Post useful scripts here.

 
Reply
 
LinkBack Thread Tools Display Modes
Old 05-09-2012, 08:05 AM   #1 (permalink)
The Purple
 
Chalice Yao's Avatar
HEYOO!
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 8,121
My Mood:
SL Join Date: 20. January 2007
Client: NaCl
Simple radar script example (llGetAgentList)

Heyooh!

I decided to port my little in-world radar script example using the new llGetAgentList into this library!

Procedure:

1. Make/drag-copy around 20 cubes. Or really, how many you want. Basically you need 1 cube + amount of avatars you want to display.

2. Link all cubes

3. Put this script into the root cube:

Code:
list lTemp;
list lTargets; // List of Agents
key kTemp;
integer iPrimCount; // Amount of prims
integer iTemp;
integer iLast; // Last amount of targets
string md5; // Md5 of agent list
clear()
{
    // Clean text
    iTemp=iPrimCount;
     do
      llSetLinkPrimitiveParamsFast((iPrimCount+1) - iTemp=~-iTemp,[PRIM_TEXT,"",<1,1,1>,1]);
    while(iTemp);
    // Get agents
    lTargets=[];
    if(iTemp=((lTemp=llGetAgentList(AGENT_LIST_REGION,[]))!=[]))
    do
      lTargets+=[kTemp=llList2Key(lTemp,iTemp=~-iTemp),llKey2Name(kTemp)];
    while(iTemp);
    // Save md5 of target list, and amount of targets
    md5=llMD5String(llDumpList2String(lTemp," "),111);
    iLast=(lTargets!=[])/2;
}


build()
{
    // Put together prims
    if((iTemp=llGetNumberOfPrims()) > 1)
    do
        llSetLinkPrimitiveParamsFast(iTemp,[PRIM_SIZE,<0.01,0.01,0.01>,PRIM_POSITION,<0,0,0.2 + (0.1 * iTemp)>]);
    while((iTemp=~-iTemp) > 1);
}


default
{
    state_entry()
    {
        // Start stuff
        iPrimCount=llGetNumberOfPrims()-1;
        build();
        clear();
        llSetTimerEvent(2);
    }
    on_rez(integer foo)
    {
        clear();
    }
    changed(integer change)
    {
        // Clear/rebuild prims on region change/relink
        if(change & CHANGED_REGION)
            clear();
        else if(change & CHANGED_LINK)
        {
            build();
            clear();
        }
    }
    timer()
    {
        // If llGetAgentList() has a differet md5 than the one we stored, avatars changed
        if(md5!=llMD5String(llDumpList2String(lTemp=llGetAgentList(AGENT_LIST_REGION,[])," "),111))
        {
            // empty list and re-fill
            lTargets=[];
            if(iTemp=lTemp!=[])
            do
                lTargets+=[kTemp=llList2Key(lTemp,iTemp=~-iTemp),llKey2Name(kTemp)];
            while(iTemp);
            md5=llMD5String(llDumpList2String(lTemp," "),111);
            // Clean text prims that are now empty
            if((iTemp=((lTargets!=[])/2)) < iLast)
                do
                    llSetLinkPrimitiveParamsFast(1 + iTemp=-~iTemp,[PRIM_TEXT,"",<1,1,1>,1]);
                while(iTemp < iLast);
            iLast=(lTargets!=[])/2;
        }
        // If we have links, display stuff
        if(llGetNumberOfPrims() > 1)
        if(iTemp=lTargets!=[])
        {
            do
            {
                iTemp=~-iTemp;
                llSetLinkPrimitiveParamsFast(2+ iTemp/2,[PRIM_TEXT,llList2String(lTargets,iTemp+1)+" "+llList2String(llGetObjectDetails(llList2Key(lTargets,iTemp=~-iTemp),[OBJECT_POS]),0),<1,1,1>,1]);
            }
            while(iTemp);
        }
    }
}
Enjoy!

The finished product uses around 0.006 to 0.02ms of script time and simply lists all avatars in the sim. I've tried to make it as efficient as possible. It isn't a nice display of distance or anything, just an example on how to realize a low-lag radar.

Scripters, take note on how I use the md5 to check for changes in the agent list, and how I only clean up prims if that happens. This is much more reliable than checking llGetRegionAgentCount for changes in the list, as during lag it could theoretically happen that one enters while another leaves, causing false displays.

EDIT:

Forgot to add, you can delink/add new prims to it anytime. it will adjust them.

EDIT:

Removed an obsolete integer variable.
__________________
"Have you ever noticed that anybody driving slower than you is an idiot, and anyone going faster than you is a maniac?" - George Carlin

Last edited by Chalice Yao; 05-10-2012 at 04:39 AM. Reason: Slight mod to the code.
Chalice Yao is offline   Reply With Quote
1 User Likes This:
Old 05-09-2012, 08:26 AM   #2 (permalink)
Senior Member
 
Phoebe Avro's Avatar
 
Join Date: Sep 2011
Posts: 557
Business: The House of Avro
mmh i get :

Object: Object [script:New Script] Script run-time error
Object: Stack-Heap Collision
Phoebe Avro is offline   Reply With Quote
Old 05-09-2012, 08:30 AM   #3 (permalink)
ADOLF HEIGHTLER
 
Imnotgoing Sideways's Avatar
 
Join Date: Jun 2008
Location: Darkly Cute :: Ferguson
Posts: 7,781
My Mood:
SL Join Date: November, 2007
Business: Darkly Cute
Client: NOT the same one I used yesterday... (<.<)
Send a message via Yahoo to Imnotgoing Sideways Send a message via Skype™ to Imnotgoing Sideways
All I get is a stack heap collision... (._.)
__________________
Link
Imnotgoing Sideways is online now   Reply With Quote
Old 05-09-2012, 08:33 AM   #4 (permalink)
(adeon.writer)
 
Adeon Writer's Avatar
 
Join Date: Apr 2010
Posts: 7,290
Oh I have a bit of code that returns one of 8 Unicode arrow directions to point to their relative direction of an inputed coordinate. (assuming this is for a HUD)

Will post
Adeon Writer is offline   Reply With Quote
Old 05-09-2012, 08:41 AM   #5 (permalink)
The Purple
 
Chalice Yao's Avatar
HEYOO!
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 8,121
My Mood:
SL Join Date: 20. January 2007
Client: NaCl
Ack. Forgot to adjust something after my change. It should work now :3
Chalice Yao is offline   Reply With Quote
Old 05-09-2012, 08:45 AM   #6 (permalink)
Senior Member
 
Phoebe Avro's Avatar
 
Join Date: Sep 2011
Posts: 557
Business: The House of Avro
thxx its working now
Phoebe Avro is offline   Reply With Quote
Old 05-09-2012, 07:25 PM   #7 (permalink)
ADOLF HEIGHTLER
 
Imnotgoing Sideways's Avatar
 
Join Date: Jun 2008
Location: Darkly Cute :: Ferguson
Posts: 7,781
My Mood:
SL Join Date: November, 2007
Business: Darkly Cute
Client: NOT the same one I used yesterday... (<.<)
Send a message via Yahoo to Imnotgoing Sideways Send a message via Skype™ to Imnotgoing Sideways
This time it took 5 minutes before SHC. (o.o)
Imnotgoing Sideways is online now   Reply With Quote
Old 05-10-2012, 03:16 AM   #8 (permalink)
The Purple
 
Chalice Yao's Avatar
HEYOO!
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 8,121
My Mood:
SL Join Date: 20. January 2007
Client: NaCl
SHC?
Chalice Yao is offline   Reply With Quote
Old 05-10-2012, 04:40 AM   #9 (permalink)
The Purple
 
Chalice Yao's Avatar
HEYOO!
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 8,121
My Mood:
SL Join Date: 20. January 2007
Client: NaCl
Another small edit to add a missing variable assignment in the list update.

Teaches me not to make any good looking changes to the code -while posting it here- 's solid now tho.
Chalice Yao is offline   Reply With Quote
Old 05-10-2012, 07:10 AM   #10 (permalink)
ADOLF HEIGHTLER
 
Imnotgoing Sideways's Avatar
 
Join Date: Jun 2008
Location: Darkly Cute :: Ferguson
Posts: 7,781
My Mood:
SL Join Date: November, 2007
Business: Darkly Cute
Client: NOT the same one I used yesterday... (<.<)
Send a message via Yahoo to Imnotgoing Sideways Send a message via Skype™ to Imnotgoing Sideways
Stack Heap Collision. I was frustrated and lazy last night. (._.)
Imnotgoing Sideways is online now   Reply With Quote
Old 05-10-2012, 08:40 AM   #11 (permalink)
Imp
 
Gabriell Anatra's Avatar
Who are you?
 
Join Date: Nov 2010
Location: In between.
Posts: 2,827
SL Join Date: Early '06 or late '05, not sure.
Client: Singularity, mostly.
Mine did that upon rezzing. I could restart the script and it would run normally though.
Gabriell Anatra is offline   Reply With Quote
Old 05-10-2012, 09:40 AM   #12 (permalink)
The Purple
 
Chalice Yao's Avatar
HEYOO!
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 8,121
My Mood:
SL Join Date: 20. January 2007
Client: NaCl
I'm currently running the current script in a 88k traffic sim with 76 avatars there. Are you making sure you're compiling it as mono, Immy?
Chalice Yao is offline   Reply With Quote
Old 05-10-2012, 09:45 AM   #13 (permalink)
ADOLF HEIGHTLER
 
Imnotgoing Sideways's Avatar
 
Join Date: Jun 2008
Location: Darkly Cute :: Ferguson
Posts: 7,781
My Mood:
SL Join Date: November, 2007
Business: Darkly Cute
Client: NOT the same one I used yesterday... (<.<)
Send a message via Yahoo to Imnotgoing Sideways Send a message via Skype™ to Imnotgoing Sideways
Mono + 48 prim linkset + minor adjustments to the build() routine to keep all 48 prims within the visual bounds of my home. Sim consistently at 2 avatars. Though, I haven't looked at your latest update. I'll tinker tonight. (^_^)

I'll be working on turning it into a HUD by adding chat-range notification. With that, I can totally quit using my Mystitool. =^-^=
Imnotgoing Sideways is online now   Reply With Quote
Old 05-10-2012, 09:54 AM   #14 (permalink)
The Purple
 
Chalice Yao's Avatar
HEYOO!
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 8,121
My Mood:
SL Join Date: 20. January 2007
Client: NaCl
Quote:
Originally Posted by Imnotgoing Sideways View Post
Though, I haven't looked at your latest update.
Ah, yes ;P That'd do it.
Chalice Yao is offline   Reply With Quote
1 User Laughed:
1 User Said Thanks:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On