Advertisement
innula

build menu list of avatars on region

Oct 3rd, 2023
1,585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. integer iMax;
  2. integer iHandle;
  3. integer iChannel;
  4.  
  5. key kToucher;
  6. key kChosenUUID;
  7. list lNames;
  8. list lUUIDs;
  9. list lTemp;
  10. list lDialogLabels;
  11. list lMenuChoices;
  12.  
  13. list lMenuButtons( integer vIntPag )
  14. {
  15.     integer vIdxBeg = 10 * (~-vIntPag);          //-- 10 * (vIntPag - 1), enclose "~-X" in parens to avoid LSL bug
  16.     integer vIdxMax = -~(~([] != lMenuChoices) / 10); //-- (llGetListLength( lMenuChoices ) - 1) / 10 + 1
  17.     list vLstRtn =
  18.       llListInsertList(
  19.         llList2List( lMenuChoices, vIdxBeg, vIdxBeg + 9 ), //-- grab 10 dialog buttons
  20.         (list)("  <<---(" + (string)(vIntPag + (-(vIntPag > 1) | vIdxMax - vIntPag)) + ")"), //-- back button
  21.         -1 ) + //-- inserts back button at index 9, pushing the last menu item to index 10
  22.       (list)("  (" + (string)(-~((vIntPag < vIdxMax) * vIntPag)) + ")--->>"); //-- add fwd button at index 11
  23.    
  24.     return //-- fix the order to L2R/T2B
  25.       llList2List( vLstRtn, -3, -1 ) + llList2List( vLstRtn, -6, -4 ) +
  26.       llList2List( vLstRtn, -9, -7 ) + llList2List( vLstRtn, -12, -10 );
  27. }
  28.  
  29. string strCaption = "Please choose someone:";
  30. string strChoice;
  31. default {
  32.   state_entry() {
  33.     iChannel = -((integer)(10000 + llFrand(9999999)));
  34.   }
  35.  
  36.   attach(key id) {
  37.     if(id){
  38.       llRequestPermissions(id, PERMISSION_TAKE_CONTROLS);//needed to run in no script areas
  39.     }
  40.   }
  41.  
  42.   run_time_permissions(integer perm) {
  43.     if(perm & PERMISSION_TAKE_CONTROLS){
  44.       llTakeControls(CONTROL_ML_LBUTTON, FALSE, TRUE);
  45.     }
  46.   }
  47.  
  48.   touch_end(integer num_detected) {
  49.  
  50.     kToucher = llDetectedKey(0);
  51.     lTemp = llGetAgentList(AGENT_LIST_REGION, []);//build list of avatars on the region
  52.  
  53.     lNames =[];//clear the lists of existing contents
  54.     lUUIDs= [];
  55.     lDialogLabels=[];
  56.     lMenuChoices=[];
  57.  
  58.     iMax = -llGetListLength(lTemp);
  59.     do{ //loop through lTemp and populate the lists
  60.       key k = llList2Key(lTemp,iMax);
  61.       lNames +=[llGetDisplayName(k)];
  62.       lUUIDs +=[k];
  63.     }
  64.     while(++iMax);
  65.  
  66.     integer counter = 0 ;
  67.     iMax = llGetListLength(lNames);
  68.     do{
  69.         lDialogLabels += [(string)(counter + 1)+": "+llList2String(lNames, counter)+"\n"];
  70.         lMenuChoices +=[(string)(counter + 1)];
  71.     }
  72.     while(++counter < iMax);
  73.     llOwnerSay("lMenuChoices is "+llList2CSV(lMenuChoices));
  74.  
  75.     llListenRemove(iHandle); // close
  76.     iHandle = llListen(iChannel, "", "", "");
  77.  
  78.       string str = "";
  79.       integer i;
  80.       //Display the first 10 sites in dialog
  81.       for (i=0;i<10;++i)
  82.       {
  83.           str += llList2String(lDialogLabels,i);
  84.       }
  85.  
  86.       llDialog(kToucher, strCaption+"\n"+str, lMenuButtons(1), iChannel);
  87.  
  88.   }
  89.  
  90.   listen(integer channel, string name, key id, string message) {
  91.  
  92.     if(!llSubStringIndex(message, "  ")){//if the first two characters of the message are leading spaces, then it's the forward or back button
  93.       string str  = "";
  94.       integer menu =  (integer)llGetSubString( message, -~llSubStringIndex( message, "(" ), -1 );
  95.       integer i;
  96.       for (i=(10*(menu - 1));i<(10*menu);++i){
  97.           str += llList2String(lDialogLabels,i);
  98.       }
  99.       llDialog(kToucher, strCaption+"\n"+str, lMenuButtons(menu), iChannel);
  100.     }
  101.     else{
  102.         integer n = (integer)message -1;
  103.         llRegionSayTo(kToucher, 0, "You chose: " + strChoice = llList2String(lNames,n)+", uuid "+(string)(kChosenUUID = llList2Key(lUUIDs, n)));
  104.     }
  105.   }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement