Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need Help with a Swing Script

Sohniii Misfit
Registered User
Join date: 9 Jun 2006
Posts: 1
08-14-2006 06:16
I have a really smooth swing script, but the problem is its swings continusly. Does anyone know how to modify it so that it will swing when its touch .. or even on command.. ie /1 swing .. or something. Please help..

Hmm not sure how to post a script.. just going to copy paste it below.

Thanks.


rotation Inverse(rotation r)
{
r.x = -r.x;
r.y = -r.y;
r.z = -r.z;
return r;
}
rotation GetParentRot()
{
return Inverse(llGetLocalRot())*llGetRot();
}
SetLocalRot(rotation x)
{
llSetRot(x*Inverse(GetParentRot()));
}

vector normal = <1.57, 0, -2.5>;

default
{
state_entry()
{
@a;
llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .1>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .2>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .3>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .4>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .5>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .4>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .3>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .2>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + .1>;));

llSleep(-1.9);
SetLocalRot(llEuler2Rot(normal));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .1>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .2>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .3>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .4>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .5>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .4>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .3>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .2>;));

llSleep (-1.9);
SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - .1>;));

llSleep(-1.9);
SetLocalRot(llEuler2Rot(normal));

//llOwnerSay(".";);
jump a;
}
}
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
08-14-2006 12:45
From: Sohniii Misfit
I have a really smooth swing script, but the problem is its swings continusly. Does anyone know how to modify it so that it will swing when its touch .. or even on command.. ie /1 swing .. or something. Please help..



I can point you in the right direction, or thereabouts.

Create a new

state swinging {

}

and put the swing code in there.

In the default state you can do detect the touch. When touched, change to the swinging state.

Once in swinging, either a) set a timer for 30 seconds or 1 minute or whatever, and then change back to default, or b) llListen for the command, parse it, and then switch back to default.

I am just a novice LSL scripter. if you IM me in-world, I'd be glad to work on this for my own self-education.

Lee Ponzu
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
This time with real, working LSL.
08-14-2006 14:40
The basic idea is that in the default state, you listen for a "/2 swing" command, or detect a touch. Then jump into the swinging state.

In swinging, you set a timer to go off periodically (update). Each time it goes off, you adjust the swing a little bit. This is what you did with llSleep(). meanwhile, Yyou also detect a touch and listen for the "/2 noswing" command.

I am not an expert. But I did sleep in a Holiday Inn lat night. (Strange American reference. Sorry, world.)

CODE

integer ch = 2; // Use /2 <cmd>
float update = .25; //How often to update the swing

default
{
state_entry()
{
llOwnerSay("The swing is still.");
llListen(ch, "", llGetOwner(), "swing" );
}

listen(integer c, string n, key o, string m ) {
llOwnerSay( m );
state swinging;
}

on_rez(integer n) {
state default;
}

touch(integer total_number)
{
llOwnerSay( "Touched");
state swinging;
}
}

state swinging {
state_entry() {
llOwnerSay("Start swinging...");
llSetTimerEvent( update );
llListen(ch, "", llGetOwner(), "noswing" );
}

timer() {
llOwnerSay("...swing...");
// adjust swing here...
}

touch(integer n) {
state default;
}

listen(integer c, string n, key o, string m ) {
llOwnerSay( m );
state default;
}
}
input Trilam
Registered User
Join date: 10 Apr 2006
Posts: 9
08-20-2006 01:32
Not meaning to be rude or anything but its a Holiday Inn Express, if you wanted the reference correct :), I like this script, I think it might come in handy, thanx.