|
Deneb Rosewood
Registered User
Join date: 2 Feb 2006
Posts: 15
|
05-07-2006 10:09
I know this is possable because I'm constantly using my /1pounce attachment with partial names, but I can't figure out how to actually do it. I'm scripting a fireball that activates in the same way, you say the name of the target and it flies off to blow 'em up. Problem is, I've tried everything I can think of, studied the wiki closely, it just can't find my target (no_sensor() event runs). I don't know what I'm doing wrong. I've been using: if (llToLower(llGetSubString(msg, 0, 7)) == "fireball") { string target = llGetSubString(msg, 9, -1); llSensor(target,NULL_KEY,AGENT,30,PI); }
but it occers to me that Sensors (dispite simply not working for me like this) require -full- names. *shakes head* That would be troublesome. Does anybody have a code that can scan for partial names like my pounce thing does? (example "/1pounce camp" targets Campbell Harker)
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
05-07-2006 10:56
Sensors require the full name (with proper case, I believe) to match a target. If you want to use partial names, you have to do a full scan and then loop through each DetectedName and compare it to your partial with llSubStringIndex. It is advisable to make both the returned names and the compared name the same case as well.
|
|
Deneb Rosewood
Registered User
Join date: 2 Feb 2006
Posts: 15
|
05-09-2006 05:44
*facepalm* I was hoping I'm good enough at this to be able to figure out what you ment, but alas, I'm not. Here's what I got: string target; default { state_entry() { llListen(2, "", llGetOwner(), ""); } listen(integer channel, string name, key id, string msg) { target = msg; llSensor("","",AGENT,30,PI); } sensor(integer num_detected) { integer i = 0; for(i = 0; i<num_detected; i++) { string n = llDetectedKey(i); llSubStringIndex(target,llKey2Name(n)); // ... } } } As you can see, I'm completely clueless on how to use a 'for'. So if somebody could help me out a little more, uh, spicificly, perhaps with an example? I just don't understand... I'm gunna hurt myself if I keep trying like this.
|
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
05-09-2006 06:26
From: Deneb Rosewood string n = llDetectedKey(i); llSubStringIndex(target,llKey2Name(n));
Try: string name = llToLower( llDetectedName(i) ); if( llSubStringIndex( name, target ) != -1 ) {
// name matched, put the code here what to do with it }
since the name is getting converted to lowercase, same should probably be applied to your target string somewhere earlier in your script.
|