Script to randomly move 1 prim around 30m
|
|
Lance Talon
Registered User
Join date: 9 Nov 2006
Posts: 3
|
12-05-2006 20:39
Hi I am very new to scripting and have been trying to make a simple script that will randomly move one prime around a 30m area going in one direction for 3-5 sec before changing directions but will always stay within the 30m of its starting point and stay within a specific Z perameter say 10-20 m. any help is greatly appreciated
thx Ed44 but I think you may have over estimated my scripting ability =) still can't figure out how to input that into a working script
|
|
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
|
12-06-2006 04:31
|
|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
12-07-2006 01:17
All I can garauntee is that this will compile: vector startpos;//position to stay near. float time;//time interval in which this will move
vector getmovepos() { float posx=(llFrand(2) - 1)*30;//generates a random number between -30 and 30 float posy=(llFrand(2) - 1)*30; vector moveto=<posx,posy,0>;//Location we want to move to return moveto; }
default { on_rez(integer num) { llResetScript(); } state_entry() { llSetBuoyancy(1);//allows the object to hover llSetStatus(STATUS_PHYSICS,TRUE);//Turns on physics llSetStatus(STATUS_PHANTOM,TRUE);//Turns on phantom startpos=llGetPos();//Sets the locked position to where it is originally located. time=llFrand(3)+2;//generates a number between 3 and 5 seconds. llSetTimerEvent(time); } timer() { vector nextpos=getmovepos()+startpos;//picks a point within 30m (more or less) of the starting position to move to. nextpos.z=llGround(<0,0,0>)+5;//"clever" trick to keep it 5 meters above the ground llMoveToTarget(nextpos,time);// moves the object to our next position. time=llFrand(3)+2; llSetTimerEvent(time); llSetText("Moving to " + (string)nextpos + "\n in " + (string)time + " seconds.",<1,1,1>,1);//Debugging Shiz } }
_____________________
My SLExchange shopTypos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-07-2006 01:44
You beat me to it Senuka! Here is my version vector startpos;
float Rand(float num) { return (llFrand(2) - 1) * num; }
vector Move() { vector moveto = <Rand(30),Rand(30),Rand(10)> + startpos; float time = llFrand(2) + 3; llMoveToTarget(moveto,time); llSetTimerEvent(time); }
default { on_rez(integer num) { llResetScript(); } state_entry() { llSetBuoyancy(0); llSetStatus(STATUS_PHYSICS,FALSE);//Turns off physics llSetStatus(STATUS_PHANTOM,FALSE);//Turns off phantom startpos=llGetPos(); } touch_start(integer total_number) { if(llDetectedKey(0) == llGetOwner()) { state running; } } }
state running { on_rez(integer num) { llResetScript(); } state_entry() { llSetBuoyancy(1);//allows the object to hover llSetStatus(STATUS_PHYSICS,TRUE);//Turns on physics llSetStatus(STATUS_PHANTOM,TRUE);//Turns on phantom Move(); } touch_start(integer total_number) { if(llDetectedKey(0) == llGetOwner()) { llSetPos(startpos); llSetTimerEvent(0); state default; } } timer() { Move(); } }
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
12-07-2006 03:28
From: Newgate Ludd You beat me to it Senuka!
Here is my version
WOW a new compile error I haven't encountered before. Your script compiles fine in Scite but then in SL I get: "  13, 0) : ERROR : Not all codes paths return a value" OK found it. You can't declare Moveto() a vector: vector startpos;
float Rand(float num) { return (llFrand(2) - 1) * num; }
Move() { vector moveto = <Rand(30),Rand(30),Rand(10)> + startpos; float time = llFrand(2) + 3; llMoveToTarget(moveto,time); llSetTimerEvent(time);
}
default { on_rez(integer num) { llResetScript(); } state_entry() { llSetBuoyancy(0); llSetStatus(STATUS_PHYSICS,FALSE);//Turns off physics llSetStatus(STATUS_PHANTOM,FALSE);//Turns off phantom startpos=llGetPos(); } touch_start(integer total_number) { if(llDetectedKey(0) == llGetOwner()) { state running; } } }
state running { on_rez(integer num) { llResetScript(); } state_entry() { llSetBuoyancy(1);//allows the object to hover llSetStatus(STATUS_PHYSICS,TRUE);//Turns on physics llSetStatus(STATUS_PHANTOM,TRUE);//Turns on phantom Move(); } touch_start(integer total_number) { if(llDetectedKey(0) == llGetOwner()) { llSetPos(startpos); llSetTimerEvent(0); state default; } } timer() { Move(); } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Lhorentso Nurmi
Registered User
Join date: 24 Nov 2006
Posts: 246
|
12-07-2006 05:42
Hi,
Can such a script be triggered by a chat command, say /13primmove... and then take back to its original position using /13primreturn?
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-07-2006 06:16
From: Jesse Barnett WOW a new compile error I haven't encountered before. Your script compiles fine in Scite but then in SL I get: "  13, 0) : ERROR : Not all codes paths return a value" Well I like to entertain and educate you Jesse  Guess thats the penalty for not trying it in world first!!! The actual error is because I am not returning anything. I had started writing it to return a vector but then changed my mind.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-07-2006 06:23
From: Lhorentso Nurmi Hi,
Can such a script be triggered by a chat command, say /13primmove... and then take back to its original position using /13primreturn? Sure it can, Just add listen handlers for it i.e. vector startpos;//position to stay near.
float Rand(float num) { return (llFrand(2) - 1) * num; }
Move() { vector moveto = <Rand(30),Rand(30),Rand(10)> + startpos; float time = llFrand(2) + 3; llMoveToTarget(moveto,time);// moves the object to our next position. llSetTimerEvent(time); }
default { on_rez(integer num) { llResetScript(); } state_entry() { llSetBuoyancy(0); llSetStatus(STATUS_PHYSICS,FALSE);//Turns off physics llSetStatus(STATUS_PHANTOM,FALSE);//Turns off phantom startpos=llGetPos(); llListen(13,"",llGetOwner(),""); } listen(integer channel, string name, key id, string message) { string str = llToLower(message); if("primmove" == str) { llSetBuoyancy(1);//allows the object to hover llSetStatus(STATUS_PHYSICS,TRUE);//Turns on physics llSetStatus(STATUS_PHANTOM,TRUE);//Turns on phantom Move(); } else if("primreturn" == str) { llSetBuoyancy(0); llSetStatus(STATUS_PHYSICS,FALSE);//Turns off physics llSetStatus(STATUS_PHANTOM,FALSE);//Turns off phantom llSetPos(startpos); llSetTimerEvent(0); } } timer() { Move(); } }
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
12-07-2006 09:22
From: Lhorentso Nurmi Hi,
Can such a script be triggered by a chat command, say /13primmove... and then take back to its original position using /13primreturn? Yes. it just needs to listen for the commands, and then act upon them when they occur.
|
|
Lance Talon
Registered User
Join date: 9 Nov 2006
Posts: 3
|
Thanks All
12-07-2006 16:26
Thanks everyone those were all a big help
|