Gayngel

Basic llCastRay script

Aug 14th, 2017
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Rez a prim and put this script in it contents. Take the prim and attach to HUD center.
  2.  
  3. list avibtns;
  4. list Targets;
  5. integer lchan;
  6. integer lhandle;
  7. key Owner;
  8. key Target;
  9. integer Trigger;
  10.  
  11.  
  12. list order_buttons(list buttons)
  13. {
  14.     return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) +
  15.         llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
  16. }
  17.  
  18. Timer()
  19. {
  20.     llSetTimerEvent(0.0);
  21.     llSetTimerEvent(120.0);
  22. }
  23.  
  24. default
  25. {
  26.  
  27.  
  28. state_entry()
  29. {
  30.  
  31. Owner = llGetOwner();
  32. lchan = -(integer) ( "0x" + (string) llGetKey() ) - 987653;
  33.  
  34.  
  35. }
  36.  
  37.  
  38. attach(key id)
  39. {
  40.  
  41.  if(id)
  42.  {
  43.   llRequestPermissions(id, PERMISSION_TRACK_CAMERA);
  44.   llOwnerSay("Focus your camera on an avatar then touch the HUD to target them.");
  45. }
  46.  
  47.   else
  48.   Trigger = FALSE;
  49.    
  50. }
  51.  
  52. run_time_permissions(integer perms)
  53. {
  54.    
  55.    if(perms & PERMISSION_TRACK_CAMERA )
  56.    {
  57.        
  58.        Trigger = TRUE;
  59.     }
  60.    
  61.    
  62. }
  63.  
  64.  
  65. touch_end(integer num)
  66. {
  67.  
  68. if(llDetectedKey(0) == Owner && Trigger)
  69. {
  70.    
  71.    
  72.    
  73. avibtns = [];  
  74.      
  75.  
  76. Targets = llCastRay(llGetCameraPos(),llGetCameraPos() + (llRot2Fwd(llGetCameraRot())*15),[ RC_MAX_HITS,10, RC_REJECT_TYPES, RC_REJECT_PHYSICAL | RC_REJECT_NONPHYSICAL | RC_REJECT_LAND  ]);
  77.  
  78.  
  79. /// Gets a list of the nearest 10 avatars that collide with ray cast from your line of sight within a max distance of 15 meters.  The line of sight is determined by casting a ray from camera position to a point so many meters away from the camera position's forward rotation. To change the distance of the ray just change the number the camera rotation is multiplied by. 1 = 1 meter.  Restricts collisions to avatars only by rejecting land and object collisions.
  80.      
  81.      if(llList2String(Targets,0) != "0") // if there are targets nearby
  82.      {
  83.       integer llength= llGetListLength(Targets);
  84.      
  85.        
  86.      
  87.    
  88.         integer i;
  89.        
  90.         for(i = 0; i < llength-2; i = i+2)
  91.         {
  92.            
  93.            
  94.             avibtns += [llKey2Name(llList2Key(Targets,i))] + [llList2Key(Targets,i)]; // Adds name of avatar + key to a list.
  95.            
  96.            
  97.         }
  98.  
  99.  
  100.  
  101.     llListenRemove(lhandle);
  102.     lhandle = llListen(lchan,"",Owner,"");
  103.    
  104.     Timer();
  105.        
  106.          llDialog(Owner,"\nSelect the person in your line of sight that you want to target, or click Cancel to cancel.", order_buttons(llList2ListStrided(avibtns,0,-1,2) +["Cancel"]),lchan);
  107.          }
  108.          
  109.          else
  110.          {
  111.              
  112.               llDialog(Owner,"\nThere are no targets nearby.", [],lchan);
  113.              
  114.              
  115.          }
  116.          
  117.  
  118.  
  119.   }
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.   listen(integer chan, string name, key id, string msg)
  128. {
  129.  
  130. if(chan == lchan)
  131. {
  132.  
  133. if(msg != "Cancel")
  134. {
  135.    integer aviidx = llListFindList(avibtns,[msg]); // Finds the name selected in the list.
  136.  
  137.       if(aviidx !=-1)
  138.       {
  139.          
  140.          Target = llList2Key(avibtns,aviidx+1);
  141.          
  142.       }
  143.  
  144.  
  145.     llOwnerSay("Target locked on " + llKey2Name(Target) + ".");
  146.     }
  147.    
  148.    
  149.     llListenRemove(lhandle);
  150.  
  151.  
  152.     }
  153.  
  154.  
  155.  
  156. }
  157.  
  158. timer()
  159. {
  160.  
  161.  llSetTimerEvent(0.0);
  162.  llListenRemove(lhandle);
  163.  
  164.    
  165. }
  166.  
  167. }
Add Comment
Please, Sign In to add comment