Difference between revisions of "LlGetParcelPrimOwners"

From Second Life Wiki
Jump to navigation Jump to search
m
(Rewrite over complicated application script. Improve functionality)
Line 42: Line 42:
|examples=
|examples=
<lsl>
<lsl>
// Script by Falados Kapuskas
// Show a floating text list of prim owners on this parcel,
// Fix added by dominic Pyara
// Sorted by prim count per owner. Highest users first.
// Omei Qunhua
 
// The object has the same permisions to view prim parcel owners
// The object has the same permisions to view prim parcel owners
// as its owner (In About Land >> Objects >> Object Owners )
// as its owner (In About Land >> Objects >> Object Owners )
 
// Example: If you can't return group object, you won't see group objects
// 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 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
// If the prim is deeded to the right group, it should always get a full list
 
// Note: Only works on group owned land when the object owner is in the Sim
// Note: Only works on group owned land when the object owner is in the Sim
//      Deeded objects always work (group is always online?)
//      Deeded objects always work (group is always online?)
 
// -- SETTINGS (Edit These!) -- //
list    gListCountsAndOwners;       // Sorted list count+owner pairs
list   gListNamesAndCounts;       // List of owner names + prim counts
integer REFRESH_TIMER = 600;           // Refresh Time (in seconds)
integer gOffset;
vector  PARCEL_POS   = <128, 128, 0>;   // A Region coordinate of a point in the parcel
integer gIndex;
integer PAGE_SIZE    = 8;             // Number of owners to display per page on the prim
key     gDataserverID;
integer DATA_TIMEOUT  = 10;            // Number of seconds to wait before giving up on dataserver events
integer gListLength;
 
// -- END SETTINGS -- //
default
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;
     state_entry()
    if ( llGetParcelPrimCount(PARCEL_POS, PARCEL_COUNT_TOTAL, FALSE) > 0 )
     {
     {
         owner_prim = llGetParcelPrimOwners(PARCEL_POS);
         llSetText("Parcel Prim Owner List\n", <1,1,1>, 1);
         //Empty List either means no prims in the parcel
        list TempList = llGetParcelPrimOwners( llGetPos() );
        //Or we couldn't get the list.  The latter is more likely
         gListLength= llGetListLength(TempList);     
         if( owner_prim == [] )  
         if (!gListLength)
         {
         {
             llSetText("[ERROR]\n Couldn't get Parcel Prim Owners",<1,0,0>,1.0);
             llSetText("[ERROR]\n Couldn't get Parcel Prim Owners", <1,0,0>, 1);
            return FALSE;
        }
    }
    else
    {
            // no objects rezzed on parcel
            gPrims = gNames = gQueryKeys = gQueryIndex = [];
            return TRUE;
    }
    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);
         else
    }
    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";
    }
    if (text == "")
    {
        text = "No matching objects in parcel";
    }
    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 == [] )
             // Produce a copy of the list suitable for sorting by count, i.e. count then key
            integer x;
            for ( ; x < gListLength; x += 2)
             {
             {
                 state display;
                 gListCountsAndOwners += llList2Integer(TempList, x+1);
            } else {
                 gListCountsAndOwners += llList2String(TempList, x);
                 state lookup;
             }
             }
            // Sort the list in descending order of prim count
            gListCountsAndOwners = llListSort(gListCountsAndOwners, 2, FALSE);
            // Lookup each owner's name. Start at the beginning of our sorted list
            gDataserverID = llRequestAgentData( llList2String(gListCountsAndOwners, 1), DATA_NAME );
         }
         }
     }
     }
    // 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)
     dataserver( key request_id, string data)
     {
     {
         if( request_id == gDataserver_Name )
        string TempStr = "Parcel Prim Owner List\n";
         if ( request_id == gDataserverID )
         {
         {
             llSetText("Loading Names .. " + (string)llGetListLength(gQueryKeys),<1,.5,0>,1.0);
             gListNamesAndCounts += data;
             if( llStringTrim(data,STRING_TRIM) != "" )
            gListNamesAndCounts += llList2String(gListCountsAndOwners, gIndex); // process the count as a string
 
            gIndex += 2;              // bump through the strided list
             if (gIndex < gListLength )
             {
             {
                 integer i = llList2Integer(gQueryIndex,0);
                 // lookup name of next owner in our list
                 gNames = llListReplaceList(gNames,[data],i,i);
                 gDataserverID = llRequestAgentData( llList2String(gListCountsAndOwners, gIndex +1) , DATA_NAME );
             }
             }
             gQueryKeys = llDeleteSubList(gQueryKeys,0,0);
             integer x;
             gQueryIndex = llDeleteSubList(gQueryIndex,0,0);
             for (; x < 16; x+=2)       // show an 8-name subset of the list, starting at 'gOffset'
            if( gQueryKeys != [] )
             {
             {
                 llSetTimerEvent(DATA_TIMEOUT);
                 // If we run off the end of the list, we just pick up nulls, so no harm done
                 gDataserver_Name = llRequestAgentData( llList2Key(gQueryKeys,0) , DATA_NAME );
                 TempStr += llList2String(gListNamesAndCounts, gOffset+x) + " : " + llList2String(gListNamesAndCounts, gOffset+x+1) + "\n";
             } else {
            }
                 state display;
            llSetText(TempStr, <1,1,1>, 1);
             if ( (gListNamesAndCounts != []) > 14)      // If list is longer than 14 (7 owners + counts) ...
            {
                 gOffset += 2;  // scroll the list forwards
                llSleep(2);     // at 2 second intervals
             }
             }
         }
         }
     }
     }
     timer()
 
     touch_start(integer total_number)
     {
     {
         //Skip it, move on
         llResetScript();       // On touch, start the whole process over again
        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;
            }
     }
     }
}</lsl>
}
</lsl>
|helpers
|helpers
|also_functions
|also_functions

Revision as of 08:46, 15 February 2014

Summary

Function: list llGetParcelPrimOwners( vector pos );

Returns a list of all residents who own objects on the parcel at pos and with individual land impact used.
The list is formatted as [ key agentKey1, integer agentImpact1, key agentKey2, integer agentImpact2, ... ], and sorted by agent key with a maximum of 100 strides.

• vector pos position in region coordinates

Requires owner-like permissions for the parcel.

Specification

Ownership

  • If the parcel owner and object owner are the same (including if the object and parcel are both group owned):
    • All object owners are returned.
  • If the parcel is group owned but the object is owned by a member of the group, the function return depends upon what powers they have been granted:
    • If resident has the 'return group owned objects' power:
      • The return list includes the group and the LI of objects it owns on the parcel.
    • If the resident has the 'return group set objects' power:
      • The return list includes all owners who have objects set to the group on the parcel
    • If the resident has the 'return non-group objects' power
      • The return list includes all owners of objects that don't fall into the above two categories.
  • If none of the above cases match, an empty list will be returned.
Pseudocode
Pseudocode written in Javascript

<javascript> if(parcel_owner == object_owner)

   return all;

var r = []; if((parcel_owner is Group) && (object_owner in parcel_owner.members)) {

 if("return group owned objects" in parcel_owner.members[object_owner].powers)
   r = r.concat(group_owned_stride);
 if("return group set objects" in parcel_owner.members[object_owner].powers)
   r = r.concat(group_set_strides);
 if("return non-group objects" in parcel_owner.members[object_owner].powers)
   r = r.concat(non_group_strides);

} return r; </javascript>

Caveats

  • This function causes the script to sleep for 2.0 seconds.
  • Function WILL NOT work on group owned land if the owner of the object where this function resides is not currently online and connected to the sim (although now seems to be working for land owner on privately owned land even when the owner is not around).
    • These limitation can be overcome by deeding the object to a group the object owner is one of the owners of.
    • Remember to take a copy before deeding because you cannot undeed something.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> // Show a floating text list of prim owners on this parcel, // Sorted by prim count per owner. Highest users first. // Omei Qunhua

// 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 on group owned land when the object owner is in the Sim // Deeded objects always work (group is always online?)

list gListCountsAndOwners; // Sorted list count+owner pairs list gListNamesAndCounts; // List of owner names + prim counts integer gOffset; integer gIndex; key gDataserverID; integer gListLength;

default {

   state_entry()
   {
       llSetText("Parcel Prim Owner List\n", <1,1,1>, 1);
       list TempList = llGetParcelPrimOwners( llGetPos() );
       gListLength= llGetListLength(TempList);      
       if (!gListLength)
       {
           llSetText("[ERROR]\n Couldn't get Parcel Prim Owners", <1,0,0>, 1);
       }
       else
       {
           // Produce a copy of the list suitable for sorting by count, i.e. count then key 
           integer x;
           for ( ; x < gListLength; x += 2)
           {
               gListCountsAndOwners += llList2Integer(TempList, x+1);
               gListCountsAndOwners += llList2String(TempList, x);
           }
           // Sort the list in descending order of prim count
           gListCountsAndOwners = llListSort(gListCountsAndOwners, 2, FALSE);
           // Lookup each owner's name. Start at the beginning of our sorted list
           gDataserverID = llRequestAgentData( llList2String(gListCountsAndOwners, 1), DATA_NAME );
       }
   }
   dataserver( key request_id, string data)
   {
       string TempStr = "Parcel Prim Owner List\n";
       if ( request_id == gDataserverID )
       {
           gListNamesAndCounts += data;
           gListNamesAndCounts += llList2String(gListCountsAndOwners, gIndex);  // process the count as a string
           gIndex += 2;               // bump through the strided list
           if (gIndex < gListLength )
           {
               // lookup name of next owner in our list
               gDataserverID = llRequestAgentData( llList2String(gListCountsAndOwners, gIndex +1) , DATA_NAME );
           }
           integer x;
           for (; x < 16; x+=2)       // show an 8-name subset of the list, starting at 'gOffset'
           {
               // If we run off the end of the list, we just pick up nulls, so no harm done
               TempStr += llList2String(gListNamesAndCounts, gOffset+x) + " : " + llList2String(gListNamesAndCounts, gOffset+x+1) + "\n";
           }
           llSetText(TempStr, <1,1,1>, 1);
           if ( (gListNamesAndCounts != []) > 14)       // If list is longer than 14 (7 owners + counts) ...
           {
               gOffset += 2;   // scroll the list forwards
               llSleep(2);     // at 2 second intervals
           }
       }
   }
   touch_start(integer total_number)
   {
       llResetScript();        // On touch, start the whole process over again
   }

}

</lsl>

Deep Notes

Search JIRA for related Issues

Signature

function list llGetParcelPrimOwners( vector pos );