Difference between revisions of "LlGetParcelPrimOwners"

From Second Life Wiki
Jump to navigation Jump to search
Line 6: Line 6:
|func_footnote=Requires owner-like permissions for the parcel.
|func_footnote=Requires owner-like permissions for the parcel.
|spec
|spec
|caveats=*The object must be owned by the land owner or if the land is owned by a group then it must be deeded to the group or owned by a group officer (or similar rank).
|caveats=
* The object has the same permisions to view prim parcel owners as its owner.
* Only works when the when the owner is in the sim
** If the object is deeded, it will always work regardless of the previous owner's status
|constants
|constants
|examples=
|examples=
<lsl>
<lsl>
// Script by Steamy Latte.
// Script by Falados Kapuskas
// The owner of the object must be the owner of the parcel.
// Sets object text to the name of everyone who owns objects on the parcel,
// and the number of prims they own.
// Looks better after the first iteration.
// Refreshes every 10 seconds.


// Comment Miki Gymnast:
// The object has the same permisions to view prim parcel owners
// Warning: this script will cause a stack/heap collision if there are group owned objects,
// as its owner (In About Land >> Objects >> Object Owners )
// because name of group owned objects will always be "" and the script will continously
// add then data to the lists after the db requests.
// Changing ** OwnerNames = OwnerNames + [""];  ** to ** OwnerNames = OwnerNames + ["Group"]
// and skipping the first db-request could be a quick hack, but the script is all together much
// to overloaded for an example.


// Example: If you can't return group object, you won't see group objects
// If you can't return any objects, an empty list will be returned.
// If the prim is deeded to the right group, it should always get a full list


list OwnerKeys;
// Note: Only works when the when the owner is in the Sim
list OwnerNames;
//      Deeded objects always work (group is always online?)
list OwnerQueries;


GetOwnerList()
// -- SETTINGS (Edit These!) -- //
 
integer REFRESH_TIMER = 600;            // Refresh Time (in seconds)
vector  PARCEL_POS    = <128,128,0>;    // A Region coordinate of a point in the parcel
integer PAGE_SIZE    = 8;              // Number of owners to display per page on the prim
integer DATA_TIMEOUT  = 10;            // Number of seconds to wait before giving up on dataserver events
 
// -- END SETTINGS -- //
 
list gQueryKeys;
list gQueryIndex;
list gNames;
list gPrims;
 
key gDataserver_Name;
 
integer gPageNumber;
integer gPageMax;
//Updates the internal list of prim owners
//Returns TRUE if there were prim owners
//Returns FALSE if the prim owner list was empty
integer UpdateOwnerList()
{
{
        list parcelPrims = llGetParcelPrimOwners(<128,128,50>);
    list owner_prim = llGetParcelPrimOwners(PARCEL_POS);
         string listString = "";
    //Empty List either means no prims in the parcel
        integer idx;
    //Or we couldn't get the list.  The latter is more likely
        for(idx=0; idx<llGetListLength(parcelPrims); idx+=2)
    if( owner_prim == [] )
        {
    {
            key ownerKey = llList2Key(parcelPrims, idx);
        llSetText("[ERROR]\n Couldn't get Parcel Prim Owners",<1,0,0>,1.0);
            string ownerName = llKey2Name(ownerKey);
         return FALSE;
            if (ownerName == "")
    }
            {
    integer i;
                ownerName = OwnerNameLookup(ownerKey);
    integer n = llGetListLength(owner_prim) / 2;
                if (ownerName == "")
   
                {
    //Reset the lists
                    OwnerQueries = OwnerQueries + [llRequestAgentData(ownerKey, DATA_NAME)];
    gPrims = [];
                    OwnerKeys = OwnerKeys + [ownerKey];
    gNames = [];
                    OwnerNames = OwnerNames + [""];
    gQueryKeys = [];
                    // Get the owner key if no name is available.
    gQueryIndex = [];
                    ownerName = ownerKey;
   
                }
   
             }
    for( i = 0; i < n; ++i)
            integer numObjects = llList2Integer(parcelPrims, idx+1);
    {
             if (listString != "")
        key owner = llList2Key(owner_prim,i*2);
            {
        string name = llKey2Name(owner);
                listString = listString + "\n";
        if( name == "" ) { //Not in the sim
            }
       
             listString = listString + ownerName + ": " + (string)numObjects;
            //Add to the query list
            gNames += ["[Unknown]"];
             gQueryIndex += [llGetListLength(gNames) - 1];
             gQueryKeys += [owner];
        } else {
             gNames += [name];
         }
         }
         llSetText(listString, <1,1,1>, 1);
         gPrims += llList2Integer(owner_prim,i*2+1);
    }
    gPageNumber = 0;
    gPageMax = llCeil( (float)llGetListLength(gNames) / PAGE_SIZE );
    return TRUE;
}
}


string OwnerNameLookup(key ownerKey)
 
// Shows the prim owners starting at index 9*page
// Returns TRUE if there are more pages
// Returns FALSE otherwise
integer ShowPrimOwners(integer page)
{
{
     integer listOffset = llListFindList(OwnerKeys, [ownerKey]);
     integer len = llGetListLength(gNames);
     if (listOffset < 0)
    integer offset = len-page*PAGE_SIZE;
         return "";
    if(  offset < 0 )
     return llList2String(OwnerNames, listOffset);
    {
}
        return FALSE;
    }
    integer i;
   
 
    integer end = (integer)( llListStatistics(LIST_STAT_MIN,[len,(page+1)*PAGE_SIZE]) );
     string text;
    for( i = PAGE_SIZE*page; i < end; ++i)
    {
         text += llList2String(gNames,i) + " - " + (string)llList2Integer(gPrims,i) + "\n";
     }
    llSetText(text,<1,1,1>,1.0);
    return TRUE;
}  


// Set-up phase
default
default
{
{
     state_entry()
     state_entry()
     {
     {
         llSetTimerEvent(10);
         llSetText("",<1,1,1>,1.0);
         OwnerNames = [];
         if(UpdateOwnerList())
         OwnerKeys = [];
         {
        OwnerQueries = [];
            if( gQueryKeys == [] )
         GetOwnerList();
            {
                state display;
            } else {
                state lookup;
            }
         }
     }
     }
     timer()
     // If there is an error, touch to reset
    touch_start(integer i){llResetScript();}
}
 
// Display the list
// Allow page flipping via touch
state display
{
    state_entry()
     {
     {
         GetOwnerList();
         ShowPrimOwners(gPageNumber);
        llSetTimerEvent(REFRESH_TIMER);
     }
     }
     dataserver(key queryId, string data)
     touch_start(integer i)
     {
     {
         llOwnerSay("Got Owner name: " + data);
         if( !ShowPrimOwners(++gPageNumber) )
        integer queryNumber = llListFindList(OwnerQueries, [queryId]);
        if (queryNumber < 0)
         {
         {
             llOwnerSay("Problem, query returned name " + data + ", but unknown query ID.");
             gPageNumber = 0;
            ShowPrimOwners(0);
         }
         }
         else
    }
    timer()
    {
         state default;
    }
}
 
// Look up all names for people that are not in the sim
// Go to the display state when finished
state lookup
{
    state_entry()
    {
        if( gQueryKeys == [] ) state display;
        llSetTimerEvent(DATA_TIMEOUT);
        gDataserver_Name = llRequestAgentData( llList2Key(gQueryKeys,0) , DATA_NAME );
    }
    dataserver( key request_id, string data)
    {
        if( request_id == gDataserver_Name )
         {
         {
             OwnerNames = llListReplaceList(OwnerNames, [data], queryNumber, queryNumber);
             llSetText("Loading Names .. " + (string)llGetListLength(gQueryKeys),<1,.5,0>,1.0);
            if( llStringTrim(data,STRING_TRIM) != "" )
            {
                integer i = llList2Integer(gQueryIndex,0);
                gNames = llListReplaceList(gNames,[data],i,i);
            }
            gQueryKeys = llDeleteSubList(gQueryKeys,0,0);
            gQueryIndex = llDeleteSubList(gQueryIndex,0,0);
           
            if( gQueryKeys != [] )
            {
                llSetTimerEvent(DATA_TIMEOUT);
                gDataserver_Name = llRequestAgentData( llList2Key(gQueryKeys,0) , DATA_NAME );
            } else {
                state display;
            }
         }
         }
    }
    timer()
    {
        //Skip it, move on
        gQueryKeys = llDeleteSubList(gQueryKeys,0,0);
        gQueryIndex = llDeleteSubList(gQueryIndex,0,0);
        gDataserver_Name = llRequestAgentData( llList2Key(gQueryKeys,0) , DATA_NAME );
     }
     }
}</lsl>
}</lsl>

Revision as of 02:33, 30 June 2009

Summary

Function: list llGetParcelPrimOwners( vector pos );

Returns a list of all residents who own objects on the parcel at pos and with individual prim counts.
The list is formatted as [ key agentKey1, integer agentCount1, key agentKey2, integer agentCount2, ... ], and sorted by agent key with a maximum of 100 strides.

• vector pos

Requires owner-like permissions for the parcel.

Caveats

  • This function causes the script to sleep for 2.0 seconds.
  • The object has the same permisions to view prim parcel owners as its owner.
  • Only works when the when the owner is in the sim
    • If the object is deeded, it will always work regardless of the previous owner's status
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> // Script by Falados Kapuskas

// The object has the same permisions to view prim parcel owners // as its owner (In About Land >> Objects >> Object Owners )

// Example: If you can't return group object, you won't see group objects // If you can't return any objects, an empty list will be returned. // If the prim is deeded to the right group, it should always get a full list

// Note: Only works when the when the owner is in the Sim // Deeded objects always work (group is always online?)

// -- SETTINGS (Edit These!) -- //

integer REFRESH_TIMER = 600; // Refresh Time (in seconds) vector PARCEL_POS = <128,128,0>; // A Region coordinate of a point in the parcel integer PAGE_SIZE = 8; // Number of owners to display per page on the prim integer DATA_TIMEOUT = 10; // Number of seconds to wait before giving up on dataserver events

// -- END SETTINGS -- //

list gQueryKeys; list gQueryIndex; list gNames; list gPrims;

key gDataserver_Name;

integer gPageNumber; integer gPageMax;

//Updates the internal list of prim owners //Returns TRUE if there were prim owners //Returns FALSE if the prim owner list was empty integer UpdateOwnerList() {

   list owner_prim = llGetParcelPrimOwners(PARCEL_POS);
   //Empty List either means no prims in the parcel
   //Or we couldn't get the list.  The latter is more likely
   if( owner_prim == [] ) 
   {
       llSetText("[ERROR]\n Couldn't get Parcel Prim Owners",<1,0,0>,1.0);
       return FALSE;
   }
   integer i;
   integer n = llGetListLength(owner_prim) / 2;
   
   //Reset the lists
   gPrims = [];
   gNames = [];
   gQueryKeys = [];
   gQueryIndex = [];
   
   
   for( i = 0; i < n; ++i)
   {
       key owner = llList2Key(owner_prim,i*2);
       string name = llKey2Name(owner);
       if( name == "" ) { //Not in the sim
       
           //Add to the query list
           gNames += ["[Unknown]"];
           gQueryIndex += [llGetListLength(gNames) - 1];
           gQueryKeys += [owner];
       } else {
           gNames += [name];
       }
       gPrims += llList2Integer(owner_prim,i*2+1);
   }
   gPageNumber = 0;
   gPageMax = llCeil( (float)llGetListLength(gNames) / PAGE_SIZE );
   return TRUE;

}


// Shows the prim owners starting at index 9*page // Returns TRUE if there are more pages // Returns FALSE otherwise integer ShowPrimOwners(integer page) {

   integer len = llGetListLength(gNames);
   integer offset = len-page*PAGE_SIZE;
   if(  offset < 0 )
   {
       return FALSE;
   }
   integer i;
   
   integer end = (integer)( llListStatistics(LIST_STAT_MIN,[len,(page+1)*PAGE_SIZE]) );
   string text;
   for( i = PAGE_SIZE*page; i < end; ++i)
   {
       text += llList2String(gNames,i) + " - " + (string)llList2Integer(gPrims,i) + "\n";
   }
   llSetText(text,<1,1,1>,1.0);
   return TRUE;

}

// Set-up phase default {

   state_entry()
   {
       llSetText("",<1,1,1>,1.0);
       if(UpdateOwnerList())
       {
           if( gQueryKeys == [] )
           {
               state display;
           } else {
               state lookup;
           }
       }
   }
   // If there is an error, touch to reset
   touch_start(integer i){llResetScript();}

}

// Display the list // Allow page flipping via touch state display {

   state_entry()
   {
       ShowPrimOwners(gPageNumber);
       llSetTimerEvent(REFRESH_TIMER);
   }
   touch_start(integer i)
   {
       if( !ShowPrimOwners(++gPageNumber) )
       {
           gPageNumber = 0;
           ShowPrimOwners(0);
       }
   }
   timer()
   {
       state default;
   }

}

// Look up all names for people that are not in the sim // Go to the display state when finished state lookup {

   state_entry()
   {
       if( gQueryKeys == [] ) state display;
       llSetTimerEvent(DATA_TIMEOUT);
       gDataserver_Name = llRequestAgentData( llList2Key(gQueryKeys,0) , DATA_NAME );
   }
   dataserver( key request_id, string data)
   {
       if( request_id == gDataserver_Name )
       {
           llSetText("Loading Names .. " + (string)llGetListLength(gQueryKeys),<1,.5,0>,1.0);
           if( llStringTrim(data,STRING_TRIM) != "" )
           {
               integer i = llList2Integer(gQueryIndex,0);
               gNames = llListReplaceList(gNames,[data],i,i);
           }
           gQueryKeys = llDeleteSubList(gQueryKeys,0,0);
           gQueryIndex = llDeleteSubList(gQueryIndex,0,0);
           
           if( gQueryKeys != [] )
           {
               llSetTimerEvent(DATA_TIMEOUT);
               gDataserver_Name = llRequestAgentData( llList2Key(gQueryKeys,0) , DATA_NAME );
           } else {
               state display;
           }
       }
   }
   timer()
   {
       //Skip it, move on
       gQueryKeys = llDeleteSubList(gQueryKeys,0,0);
       gQueryIndex = llDeleteSubList(gQueryIndex,0,0);
       gDataserver_Name = llRequestAgentData( llList2Key(gQueryKeys,0) , DATA_NAME ); 
   }
}</lsl>

Deep Notes

Search JIRA for related Issues

Signature

function list llGetParcelPrimOwners( vector pos );