|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
04-06-2006 16:54
So, I'm writing yet another script I need help with  I'm writing a follow script that follows anyone in which I write a command. Lets say I say "/2 follow exil" it will find someone with the beginning 4 letters "exil" and follow them. I can't get the script working though, and it won't even find the avatar. Here's the script: integer targetID; vector destination; float range = 0.5; string temp; integer i; default { state_entry() { llListen(2,"",llGetOwner(),""); }
listen(integer channel, string name,key id,string message) { temp=llGetSubString(message,0,6); if(temp=="follow ") { temp=llGetSubString(message,7,-1); llSensor("",NULL_KEY,AGENT,96,PI*2); } if (message == "reset") { llResetScript(); } } on_rez(integer n) { llResetScript(); } sensor(integer n) { destination = llDetectedPos(i); targetID = llTarget(destination, range); float dif = 5; float vecdist = llVecDist(llGetPos(),llDetectedPos(i)); for(i=0;i<n;i++) { vector detpos = llDetectedPos(i); if(llSubStringIndex(llToLower(llDetectedName(i)),llToLower(temp))!=-1) { llMoveToTarget(<detpos.x -= 1,detpos.y,detpos.z>, 0.1); llOwnerSay("Moving to follow target, " + llDetectedName(i)); } } } listen(integer channel, string name,key id,string message) { if(message == "stop follow") llTargetRemove(targetID); llStopMoveToTarget(); } }
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
04-06-2006 17:13
Well, I see one problem. You have two listen() handlers. The compiler doesn't warn you about that, but I think it only uses the 2nd one. Or the first one. Or something. In any case, you want only one handler per event. So combine... listen(integer channel, string name,key id,string message) { temp=llGetSubString(message,0,6); if(temp=="follow ") { temp=llGetSubString(message,7,-1); llSensor("",NULL_KEY,AGENT,96,PI*2); } if (message == "reset") { llResetScript(); } }
...
listen(integer channel, string name,key id,string message) { if(message == "stop follow") { llTargetRemove(targetID); llStopMoveToTarget(); } }
Into... listen(integer channel, string name,key id,string message) { temp=llGetSubString(message,0,6); if(temp=="follow ") { temp=llGetSubString(message,7,-1); llSensor("",NULL_KEY,AGENT,96,PI*2); } else if (message == "reset") { llResetScript(); } else if(message == "stop follow") { llTargetRemove(targetID); llStopMoveToTarget(); } }
Or something like that... I haven't tested it so there's probably bugs in there, but hopefully that'll get you started in (again, hopefully  ) the right direction. There's some unnecessary code in there, I think (like setting/removing targets), but that probably shouldn't prevent yoru script from working, so I removed my changes related to that.
|
|
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
|
04-06-2006 17:38
Lol I totally overlooked that. And I know that 2 listens don't work in one state, I'm just stupid  Thanks a lot, I'll check it when I get home from work.
|
|
Geoff Gavaskar
who, me?
Join date: 29 Dec 2005
Posts: 21
|
04-07-2006 12:08
hehehhe....a targeted banana phone!
|
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
04-07-2006 12:17
From: Geoff Gavaskar hehehhe....a targeted banana phone! hehehe....report abuse!
|