Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rez a prim and put this script in it contents. Take the prim and attach to HUD center.
- list avibtns;
- list Targets;
- integer lchan;
- integer lhandle;
- key Owner;
- key Target;
- integer Trigger;
- list order_buttons(list buttons)
- {
- return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) +
- llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
- }
- Timer()
- {
- llSetTimerEvent(0.0);
- llSetTimerEvent(120.0);
- }
- default
- {
- state_entry()
- {
- Owner = llGetOwner();
- lchan = -(integer) ( "0x" + (string) llGetKey() ) - 987653;
- }
- attach(key id)
- {
- if(id)
- {
- llRequestPermissions(id, PERMISSION_TRACK_CAMERA);
- llOwnerSay("Focus your camera on an avatar then touch the HUD to target them.");
- }
- else
- Trigger = FALSE;
- }
- run_time_permissions(integer perms)
- {
- if(perms & PERMISSION_TRACK_CAMERA )
- {
- Trigger = TRUE;
- }
- }
- touch_end(integer num)
- {
- if(llDetectedKey(0) == Owner && Trigger)
- {
- avibtns = [];
- Targets = llCastRay(llGetCameraPos(),llGetCameraPos() + (llRot2Fwd(llGetCameraRot())*15),[ RC_MAX_HITS,10, RC_REJECT_TYPES, RC_REJECT_PHYSICAL | RC_REJECT_NONPHYSICAL | RC_REJECT_LAND ]);
- /// 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.
- if(llList2String(Targets,0) != "0") // if there are targets nearby
- {
- integer llength= llGetListLength(Targets);
- integer i;
- for(i = 0; i < llength-2; i = i+2)
- {
- avibtns += [llKey2Name(llList2Key(Targets,i))] + [llList2Key(Targets,i)]; // Adds name of avatar + key to a list.
- }
- llListenRemove(lhandle);
- lhandle = llListen(lchan,"",Owner,"");
- Timer();
- 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);
- }
- else
- {
- llDialog(Owner,"\nThere are no targets nearby.", [],lchan);
- }
- }
- }
- listen(integer chan, string name, key id, string msg)
- {
- if(chan == lchan)
- {
- if(msg != "Cancel")
- {
- integer aviidx = llListFindList(avibtns,[msg]); // Finds the name selected in the list.
- if(aviidx !=-1)
- {
- Target = llList2Key(avibtns,aviidx+1);
- }
- llOwnerSay("Target locked on " + llKey2Name(Target) + ".");
- }
- llListenRemove(lhandle);
- }
- }
- timer()
- {
- llSetTimerEvent(0.0);
- llListenRemove(lhandle);
- }
- }
Add Comment
Please, Sign In to add comment