Making a string that connects to a said avatar name.
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-22-2006 13:09
I need help on creating a script that would do something to the avatar that I name. For example, if you say "  whatever I want to do) + (The avatars name that I want to do it to)" <------Get rid of the parenthesis. I would be overly grateful for anyone who would be kind enough to write this short but simple script template that I could fill in the blanks for.
|
|
Gigs Taggart
The Invisible Hand
Join date: 12 Feb 2006
Posts: 406
|
Here
02-22-2006 15:51
default { state_entry() { llListen( 0, "", llGetOwner(), "" ); }
listen(integer channel, string name, key id, string message) { llSay(0, "/me " + message); } }
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-22-2006 19:29
I don't think this is what I meant. I meant; lets just say I wanted to TRAP someone, I want to be able to say "trap (avatar name)" and it will trap whomever I said's name. Does this do that; because it doesn't look like it does.
|
|
Gigs Taggart
The Invisible Hand
Join date: 12 Feb 2006
Posts: 406
|
hmm
02-22-2006 20:13
What you want would require some serious scripting. I think you may be underestimating the difficulty of the project.
|
|
Lindsey Dassin
Fallen Angel
Join date: 14 Sep 2005
Posts: 33
|
02-22-2006 21:19
I'd guess you're looking for something like this? If i do a "/20 hug Padraig Stygian", it says: Object: You told me to hug Padraig Stygian (key)6d7184cf-7b0a-4e65-b6b1-7826e87e6d1e Object: at position <216.39374, 241.08478, 551.25360> It's a "fill-in-the-blanks" sort of template... it's up to you to actually fill them in! integer LISTEN_CHANNEL = 20; float SENSOR_RANGE = 20.0;
string gRecipient; string gAction;
performAction() { key recipientKey = llDetectedKey( 0 ); string recipientName = llDetectedName( 0 ); vector recipientPos = llDetectedPos( 0 );
if( gAction == "hug" ) { // Perform all actions needed to hug here llOwnerSay( "You told me to hug " + recipientName + " (key)" + (string) recipientKey ); llOwnerSay( "at position " + (string)recipientPos );
} else if( gAction == "headjump" ) { // Do what is required to "headjump"
} else if( gAction == "trap" ) { // Do what is required to "trap"
} }
default { state_entry() { llListen( LISTEN_CHANNEL, "", llGetOwner(), "" ); }
listen( integer channel, string name, key id, string message ) { integer i = llSubStringIndex( message, " " ); if( i != -1 ) { gAction = llGetSubString( message, 0, i - 1 ); gRecipient = llGetSubString( message, i + 1, -1 );
if( gRecipient != "" ) { llSensor( gRecipient, "", AGENT, SENSOR_RANGE, PI ); } } }
no_sensor() { llOwnerSay( "Couldn't find " + gRecipient ); }
sensor( integer total_num ) { performAction(); } }
_____________________
:wq
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-23-2006 06:32
Does this actually do what I set to it? Will it say "Object: You told me to hug Exile Loudon key (Whatever my key is  ) Object: At position (X,Y,X)" Will it then hug the avatar; or does it only tell me that I told the object that I want it to start the hug animation? EDIT: NVM I see you did do it after I read through the comments  They do take the actions! Thank you so much lindsey! You're a Life saver!
|
|
Lindsey Dassin
Fallen Angel
Join date: 14 Sep 2005
Posts: 33
|
02-23-2006 09:12
*smiles* I'm glad i could help!
Just look out, though: These string parsing routines aren't very clever. They just look for the first space in whatever you type, and everything before that space is the "action"; everything after is the "recipient".
_____________________
:wq
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-23-2006 09:59
LOL i noticed. Now that I changed the script around to work like this. integer LISTEN_CHANNEL = 2; float SENSOR_RANGE = 20.0;
string gRecipient; string gAction;
performAction() { key recipientKey = llDetectedKey( 0 ); string recipientName = llDetectedName( 0 ); vector recipientPos = llDetectedPos( 0 );
if( gAction == "trap" ) { llRezObject("Aniam Trap",llDetectedPos(0),ZERO_VECTOR,ZERO_ROTATION,42); } }
default { state_entry() { llListen( LISTEN_CHANNEL, "", llGetOwner(), "" ); }
listen( integer channel, string name, key id, string message ) { integer i = llSubStringIndex( message, " " ); if( i != -1 ) { gAction = llGetSubString( message, 0, i - 1 ); gRecipient = llGetSubString( message, i + 1, -1 );
if( gRecipient != "" ) { llSensor( gRecipient, "", AGENT, SENSOR_RANGE, PI ); } } } no_sensor() {
sensor( integer total_num ) { performAction(); } } This code works; and I tested it out and it compiled fine. It rezzes a trap around anyone I say (Unluckily, I have to say their full name; Case Sensitive) and they have to be 10 m away or less. Would it be possible to figure out a way to set it up so the script can rez a trap more then 10 m away and have it so I don't have to have their full name typed; rather just the first 3 letters?
|
|
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
|
02-23-2006 10:09
This can be made more flexible, too. You can use the following in your sensor event: key recipientKey; string recipientName; vector recipientPos; integer t; integer hit = FALSE;
string ugrecipient = llToLower(gRecipient);
for (t=0; t<total_detected; t++) { if (llSubStringIndex(llToLower(llDetectedName(t)), ugrecipient) != -1) { if (hit) { llOwnerSay("Name '" + gRecipient + "' was ambiguous."); return; } recipientKey = llDetectedKey(t); recipientName = llDetectedName(t); recipientPos = llDetectedPos(t); hit = TRUE; } }
... call something to perform the action ...
This will let you use parts of names instead of whole names, and also ignore case: so you can "shoot yumi" instead of having to "shoot Yumi Murakami". You can speed it up by using a while loop if you don't mind ambiguity being resolved automatically.
|
|
Lindsey Dassin
Fallen Angel
Join date: 14 Sep 2005
Posts: 33
|
02-23-2006 10:23
From: Exile Loudon This code works; and I tested it out and it compiled fine. It rezzes a trap around anyone I say (Unluckily, I have to say their full name; Case Sensitive) and they have to be 10 m away or less. Would it be possible to figure out a way to set it up so the script can rez a trap more then 10 m away and have it so I don't have to have their full name typed; rather just the first 3 letters?
Both of these are possible, just that it's not such a simple, straightforward solution for either of them. Instead of passing the avatar name to llSensor()... if you passed it an empty string and a NULL_KEY it will return everything -- no filtering. Then in the sensor() event you would have to check the llDetectedName()s against gRecipient to see if they match. Ten meters is a limitation of llRezObject(), and you're already very aware of that. To get around that you'd have to make it trap gun script. Yes, i know how it could be done; no, i'm not going to help anyone build something like that. I don't do weapons -- i'm sorry.
_____________________
:wq
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-23-2006 12:36
Lol thanks; I just wanted to know actually just for information; and yes I am aware of the 10m rez object limit.
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-24-2006 06:00
From: Yumi Murakami This can be made more flexible, too. You can use the following in your sensor event: key recipientKey; string recipientName; vector recipientPos; integer t; integer hit = FALSE;
string ugrecipient = llToLower(gRecipient);
for (t=0; t<total_detected; t++) { if (llSubStringIndex(llToLower(llDetectedName(t)), ugrecipient) != -1) { if (hit) { llOwnerSay("Name '" + gRecipient + "' was ambiguous."); return; } recipientKey = llDetectedKey(t); recipientName = llDetectedName(t); recipientPos = llDetectedPos(t); hit = TRUE; } }
... call something to perform the action ...
This will let you use parts of names instead of whole names, and also ignore case: so you can "shoot yumi" instead of having to "shoot Yumi Murakami". You can speed it up by using a while loop if you don't mind ambiguity being resolved automatically. Sorry for the Double post; but how exactly would I impliment this into the code? (Where would I put this section exactly; and is there anything I need to change?)
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-26-2006 18:13
*b.u.m.p!!*
|
|
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
|
02-27-2006 04:11
From: Exile Loudon Sorry for the Double post; but how exactly would I impliment this into the code? (Where would I put this section exactly; and is there anything I need to change?) Here's an integrated version: integer LISTEN_CHANNEL = 2; float SENSOR_RANGE = 20.0;
string gRecipient; string gAction;
performAction(action, recipientKey, recipientName, recipientPos) { if( action == "trap" ) { llRezObject("Aniam Trap",recipientPos,ZERO_VECTOR,ZERO_ROTATION,42); } }
default { state_entry() { llListen( LISTEN_CHANNEL, "", llGetOwner(), "" ); }
listen( integer channel, string name, key id, string message ) { integer i = llSubStringIndex( message, " " ); if( i != -1 ) { gAction = llGetSubString( message, 0, i - 1 ); gRecipient = llGetSubString( message, i + 1, -1 ); if( gRecipient != "" ) { llSensor( "", "", AGENT, SENSOR_RANGE, PI ); } } }
no_sensor() { }
sensor( integer total_num ) { integer t; integer hit = FALSE; string ugrecipient = llToLower(gRecipient); for (t=0; t<total_num; t++) { if (llSubStringIndex(llToLower(llDetectedName(t)), ugrecipient) != -1) { if (hit) { llOwnerSay("Name '" + gRecipient + "' was ambiguous."); return; } recipientKey = llDetectedKey(t); recipientName = llDetectedName(t); recipientPos = llDetectedPos(t); hit = TRUE; } } if (hit) performAction(gAction, recipientKey, recipientName, recipientPos); } }
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-27-2006 04:27
That was a little off, so I changed the scirpt just a bit because the one you posted wasn't compiling. So here's the finished version, and thanks so much guys!! ( I mean girls!) integer LISTEN_CHANNEL = 2; float SENSOR_RANGE = 20.0;
string gRecipient; string gAction;
performAction() { key recipientKey = llDetectedKey( 0 ); string recipientName = llDetectedName( 0 ); vector recipientPos = llDetectedPos( 0 ); if( gAction == "trap" ) { llRezObject("Aniam Trap",recipientPos,ZERO_VECTOR,ZERO_ROTATION,42); } }
default { state_entry() { llListen( LISTEN_CHANNEL, "", llGetOwner(), "" ); }
listen( integer channel, string name, key id, string message ) { integer i = llSubStringIndex( message, " " ); if( i != -1 ) { gAction = llGetSubString( message, 0, i - 1 ); gRecipient = llGetSubString( message, i + 1, -1 ); if( gRecipient != "" ) { llSensor( "", "", AGENT, SENSOR_RANGE, PI ); } } }
no_sensor() { }
sensor( integer total_num ) { integer t; integer hit = FALSE; string ugrecipient = llToLower(gRecipient); for (t=0; t<total_num; t++) { if (llSubStringIndex(llToLower(llDetectedName(t)), ugrecipient) != -1) { if (hit) { llOwnerSay("Name '" + gRecipient + "' was ambiguous."); return; } key recipientKey = llDetectedKey(t); string recipientName = llDetectedName(t); vector recipientPos = llDetectedPos(t); hit = TRUE; } } if (hit) performAction(); key recipientKey = llDetectedKey( 0 ); string recipientName = llDetectedName( 0 ); vector recipientPos = llDetectedPos( 0 ); } }
|
|
Nick Fortune
National Alchemist
Join date: 30 May 2003
Posts: 74
|
02-27-2006 04:59
From: Exile Loudon This code works; and I tested it out and it compiled fine. It rezzes a trap around anyone I say (Unluckily, I have to say their full name; Case Sensitive) and they have to be 10 m away or less. Would it be possible to figure out a way to set it up so the script can rez a trap more then 10 m away and have it so I don't have to have their full name typed; rather just the first 3 letters?
Have the parent rez a object that moves to the target then rezzes the cage if its > 10m away. You can pass the target data via on_rez.
|
|
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
|
02-27-2006 06:04
From: Exile Loudon That was a little off, so I changed the scirpt just a bit because the one you posted wasn't compiling. So here's the finished version, and thanks so much guys!! ( I mean girls!) What was the compile error you were getting? The chances you've made will stop it working properly; you can't assume that the target is llDetectedKey(0) any more. As written it'll always target the nearest person even if that wasn't the person whose name you typed.
|
|
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
|
02-27-2006 06:06
Well d'oh, I can see at least a couple of errors right now. Don't write code without a compiler on hand while tired.  integer LISTEN_CHANNEL = 2; float SENSOR_RANGE = 20.0;
string gRecipient; string gAction;
performAction(string action, key recipientKey, string recipientName, vector recipientPos) { if( action == "trap" ) { llRezObject("Aniam Trap",recipientPos,ZERO_VECTOR,ZERO_ROTATION,42); } }
default { state_entry() { llListen( LISTEN_CHANNEL, "", llGetOwner(), "" ); }
listen( integer channel, string name, key id, string message ) { integer i = llSubStringIndex( message, " " ); if( i != -1 ) { gAction = llGetSubString( message, 0, i - 1 ); gRecipient = llGetSubString( message, i + 1, -1 ); if( gRecipient != "" ) { llSensor( "", "", AGENT, SENSOR_RANGE, PI ); } } }
no_sensor() { }
sensor( integer total_num ) { integer t; integer hit = FALSE; string ugrecipient = llToLower(gRecipient); for (t=0; t<total_num; t++) { if (llSubStringIndex(llToLower(llDetectedName(t)), ugrecipient) != -1) { if (hit) { llOwnerSay("Name '" + gRecipient + "' was ambiguous."); return; } recipientKey = llDetectedKey(t); recipientName = llDetectedName(t); recipientPos = llDetectedPos(t); hit = TRUE; } } if (hit) performAction(gAction, recipientKey, recipientName, recipientPos); } }
[/QUOTE]
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
02-27-2006 13:09
... Damnit; there's still compiling errors!!! sensor( integer total_num ) { integer t; integer hit = FALSE; string ugrecipient = llToLower(gRecipient); for (t=0; t<total_num; t++) { if (llSubStringIndex(llToLower(llDetectedName(t)), ugrecipient) != -1) { if (hit) { llOwnerSay("Name '" + gRecipient + "' was ambiguous."); return; } recipientKey = llDetectedKey(t);//right here is where the problem occurs //where the space is right after recipientKey is. recipientName = llDetectedName(t); recipientPos = llDetectedPos(t); hit = TRUE; } } if (hit) performAction(gAction, recipientKey, recipientName, recipientPos); } } It's a "Name not defined within scope" error; and I think that just meanst that "recipientKey" isn't defined as a Key in that state; right?
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
03-01-2006 02:31
Bump
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
03-01-2006 05:45
From: Exile Loudon It's a "Name not defined within scope" error; and I think that just meanst that "recipientKey" isn't defined as a Key in that state; right? If you know the answer, why are you asking? 
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
03-01-2006 12:59
From: Argent Stonecutter If you know the answer, why are you asking?  Because I don't know how to implement it right. I don't know how to fix it; I just know that that is probalby the problem.
|
|
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
|
03-02-2006 06:36
From: Exile Loudon ... Damnit; there's still compiling errors!!! Sorry *blush*. Please, remind me not to do this without SL, or at least LSLnt, on hand next time  sensor( integer total_num ) { integer t; integer hit = FALSE; string ugrecipient = llToLower(gRecipient); key recipientKey; string recipientName; vector recipientPos; for (t=0; t<total_num; t++) { if (llSubStringIndex(llToLower(llDetectedName(t)), ugrecipient) != -1) { if (hit) { llOwnerSay("Name '" + gRecipient + "' was ambiguous."); return; } recipientKey = llDetectedKey(t); recipientName = llDetectedName(t); recipientPos = llDetectedPos(t); hit = TRUE; } } if (hit) performAction(gAction, recipientKey, recipientName, recipientPos); } }
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
03-02-2006 13:15
...I hate to say this, but it compiled fine, but now it just doens't work. It won't rez the trap... weird.
|
|
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
|
03-03-2006 05:54
From: Exile Loudon ...I hate to say this, but it compiled fine, but now it just doens't work. It won't rez the trap... weird. I've tested the above and it works, so it must be a different problem. How are you testing it?
|