"Targeting" an avatar - sort of
|
|
Clinton Bulan
Registered User
Join date: 9 Oct 2006
Posts: 22
|
04-22-2007 14:32
So I'm making a HUD and part of the functionality requires the owner to be able to "target" another avatar. The HUD would then use that "target" avatars first name in various emotes and gestures until the owner clears the target or choses a new one.
I've been playing around with sensors and whatnot but I'm getting in over my head...and I thought permissions were a headache!
Anyone have any input?
|
|
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
|
04-22-2007 15:06
Maybe you could shoot a transparent bullet, and have a script in the bullet to detect the collision, grab the id of who it collides with, and chat it back to your hud?
|
|
Clinton Bulan
Registered User
Join date: 9 Oct 2006
Posts: 22
|
04-22-2007 15:12
Ideally I'd like to have a sensor with a small cone radius that pulls the info from whomever it's being pointed at but thats a creative approach  I'll give that a shot, one listener should do the trick. I want to make it as simple a device as possible for the user but considering the limitations of sensors, the "bullet" idea seems like a decent approach.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
04-22-2007 15:37
A standard sensor will do what you need. In crowded area's you will have problems with the 16 item return limit but that is circumventable by using variable scan ranges and rotation angles. You could even go one step further and use multiple prims instead of rotationing the sensor.
|
|
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
|
04-22-2007 15:47
I've got a sensor that returns the 12 nearest avatar names, in menu dialog form. Press a button, and get the key of that user, with which to do whatever yo9u like. IT basically involves running a loop on the num_detected. so like... This isn't "properly tested" lsl.. I'm not in world, and it's just fragments anyways, so I can't check if it will compile.. but here's how I'd approach it. Note to better scripters: PLEASE correct my assumptions herein, and if you know something to save memory, or whatnot, feel free to post that, or punk up my snippets here.. or even slap them into something more closely resembling a script.We'll need a couple of lists list names; list keys;
let's also establish an integer, we'll be reusing it. integer temp;
Okay let's say that "on touch", the script will trigger a sensor. let's say it's set to do a full sperical sweep, at 100m, and it's looking for agents. That's going to return the 16 nearest agents. names = [ ]; // new sensor sweep, so let's blank the lists for new data! keys = [ ]; temp = num_detected if (temp > 12) temp = 12; // truncates the list so it will fit on a dialog. while (temp > -1) { names = names + [llDetectedName(temp)]; keys = keys + [llDetectedKey(temp)]; temp -= 1; }
Then it's just a matter of using the names list as a dialog. The dialog will pop up 12 buttons, and each button will have a name, clicking a name will return that name, as if you said it. SO we can use a simple llGetOwner Listen on whatever channel, to listen for the menu choice. Then in a listen, we do a test like this.. if (llListFindList(names, [message]) != -1) // if the name is found in the names list { temp = llListFindList(names, [message]); // get the position of the name, in the list targetkey = llList2Key(keys, temp); // look in the same position, in the keys list }
And now you've got the key of your target! Using an intuitive, easy to comprehend interface. Unfortunately one that takes a bit of backend planning to put together.. but once done, you can reuse that code over and over again.
_____________________
 ● Inworld Store: http://slurl.eclectic-randomness.com ● Website: http://www.eclectic-randomness.com ● Twitter: @WinterVentura
|
|
Clinton Bulan
Registered User
Join date: 9 Oct 2006
Posts: 22
|
04-22-2007 15:49
Thanks Newgate, I'll play around with it a bit. I don't need the sensor to pick up anyone outside of 5 meters or so, that should help the limitations.
Working on having the HUD prim display the detected names and distances in a hover text at the moment.
I've never done anything involving sensors before so it's a bit new.
|
|
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
|
04-22-2007 16:05
Okay here's my "Avatar Finder" script from in world. it's still a bit rudimentary, but it compiles, and actually DOES work... integer channel = -10; string menuText = "Select your target:"; list avatarsDetected = [ ]; list keysDetected = [ ];
useKey(key targetKey) { // This is where you "do something" with that key. I dunno whatYOU plan to do with it // in my demo in world, I passed it to a particle beam. There's some issues with that // since the particle target range seems to be the client's draw distance. // but if you wanted to rez a follower, or whatever, you'd do that here. }
default { state_entry() { llListen(channel, "", llGetOwner(), ""); }
listen(integer channel, string name, key id, string message) { integer listPos = llListFindList(avatarsDetected, (list)message); useKey(llList2Key(keysDetected, listPos)); }
touch_start(integer duration) { llSensor("", NULL_KEY, AGENT, 100, PI); } sensor(integer numDetected) { if (numDetected > 12) numDetected = 12; integer nextStep; string nextAvatarName; string nextAvatarKey; avatarsDetected = [ ]; keysDetected = [ ]; for (nextStep = 0; nextStep < numDetected; nextStep++) { nextAvatarName = llDetectedName(nextStep); nextAvatarKey = llDetectedKey(nextStep); if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23); avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName; keysDetected = (keysDetected=[]) + keysDetected + nextAvatarKey; } llDialog(llGetOwner(), menuText, avatarsDetected, channel); } }
_____________________
 ● Inworld Store: http://slurl.eclectic-randomness.com ● Website: http://www.eclectic-randomness.com ● Twitter: @WinterVentura
|
|
Clinton Bulan
Registered User
Join date: 9 Oct 2006
Posts: 22
|
04-22-2007 18:13
Wow, going way beyond what I need but thanks  All i need is the name I think, being as the HUD isn't actually interacting with the target at all, just pulling the name.
|
|
Usagi Musashi
UM ™®
Join date: 24 Oct 2004
Posts: 6,083
|
04-22-2007 18:34
Thank you two for sharing this. Its a great resource!!!!!!!!!! boy O` boy sometimes you find a mint in this forums! You people are wonderful! THANK YOU! 
|
|
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
|
04-22-2007 18:38
like I say, it's kind of a boilerplate script. So just pull out the parts that build the key list, and search/compare the lists. The listen will be hearing a "name" it's fairly short work to split the name at the " " between first and last...
But hopefully you can mod that into what you're needing?
_____________________
 ● Inworld Store: http://slurl.eclectic-randomness.com ● Website: http://www.eclectic-randomness.com ● Twitter: @WinterVentura
|
|
Clinton Bulan
Registered User
Join date: 9 Oct 2006
Posts: 22
|
04-22-2007 19:23
So Winter came online and we had a little one on one with her code. Got it running as I need it. It's the same as the script Winter posted, we just pulled anything relating to keys out of it and set the button clicks to return the first name of the chosen avatar. Thanks Winter!
integer channel = -10; string menuText = "Select your target:"; list avatarsDetected = [ ]; string firstname = ""; default { state_entry() { llListen(channel, "", llGetOwner(), ""); }
listen(integer channel, string name, key id, string message) { integer listPos = llListFindList(avatarsDetected, (list)message); firstname = llGetSubString(message, 0, llSubStringIndex(message, " ") - 1); }
touch_start(integer duration) { llSensor("", NULL_KEY, AGENT, 30, PI); } sensor(integer numDetected) { if (numDetected > 12) numDetected = 12; integer nextStep; string nextAvatarName; avatarsDetected = [ ]; for (nextStep = 0; nextStep < numDetected; nextStep++) { nextAvatarName = llDetectedName(nextStep); if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23); avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName; } llDialog(llGetOwner(), menuText, avatarsDetected, channel); } }
|
|
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
|
04-22-2007 21:33
ALMOST all of it... remove this line (first line of the listen event) integer listPos = llListFindList(avatarsDetected, (list)message); You no longer need to know the position of the chosen name in the names list.
_____________________
 ● Inworld Store: http://slurl.eclectic-randomness.com ● Website: http://www.eclectic-randomness.com ● Twitter: @WinterVentura
|