Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

"Flight-Responsive" attachment scripts

Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
10-31-2004 14:47
The following simple scripts allow the construction of attachments that will respond to the flying status of the owner, causing some parts to become invisible, and others to become visible. This is most commonly used, as an example, for wing attachments, to cause the wings to 'open' when the avatar is flying, and to 'close' when the avatar returns to earth.

The first script is the main controlling script. Only one copy of this is required per attachment. It detects whether or not the avatar's flying status has changed, then link_messages the rest of the prims as required.

CODE


// Agent Flying Detection
//
// This is the main script. Place one copy of it in the attachment in question,
// usually the root prim.
//
// Cross Lament's messy code follows.


integer isFlying = FALSE ;

default
{
state_entry()
{
llSetTimerEvent( 2 ) ; // Polling rate, check every couple of seconds
}

timer()
{
integer flystatus = llGetAgentInfo( llGetOwner() ) ;

// if the agent is flying, and the status holder says they're not...
if( ( flystatus & AGENT_FLYING ) && !isFlying )
{
isFlying = TRUE ;
llMessageLinked( LINK_ALL_OTHERS, 1, "", NULL_KEY ) ; // Hell yeah, tell everyone!
}

// if the agent is NOT flying, and the status holder says they are...
else if( !( flystatus & AGENT_FLYING ) && isFlying )
{
isFlying = FALSE ;
llMessageLinked( LINK_ALL_OTHERS, 0, "", NULL_KEY ) ; // Nope, I'm not.
}
}
}


The next two scripts are to be placed in the rest of the prims making up the attachment, one script per prim, depending on how you want each prim to behave.

The following script will cause any prim containing it to become invisible when the avatar is flying, and become visible once they stop flying.

CODE

// Invisible when flying
//
// Place this script on every prim in the link-set that should be INVISIBLE when flying
//
// Cross Lament's messy code follows.

default
{
state_entry()
{

}

link_message( integer sender, integer num, string message, key id )
{
if( num == 0 )
{
llSetAlpha( 1.0, ALL_SIDES ) ;
}

else
{
llSetAlpha( 0.0, ALL_SIDES ) ;
}
}
}


The last script that follows is the same as the previous, only it will make any prim containing it visible when flying, and invisible when not flying.

CODE

// Visible when flying
//
// Place this script on every prim in the link-set that should be VISIBLE when flying
//
// Cross Lament's messy code follows.

default
{
state_entry()
{

}

link_message( integer sender, integer num, string message, key id )
{
if( num == 0 )
{
llSetAlpha( 0.0, ALL_SIDES ) ;
}

else
{
llSetAlpha( 1.0, ALL_SIDES ) ;
}
}
}


A basic example of how to use this would be a wing attachment. You would build both the open and closed versions of the wing and put them together as the same attachment. Put a single copy of the 'Agent Flying Detection' script in the resulting object, likely in the root prim. Then in every other prim, put one of the other two scripts (and only one!), depending on whether that prim should be visible or not visible when flying (ie. the prims making up the 'open wing' would be visible when flying, and the prims making up the 'closed wing' would be invisible when flying).

It's a totally trivial set of scripts, and I can't explain to save my life, but I hope this made some kinda sense. :D
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Zuzi Martinez
goth dachshund
Join date: 4 Sep 2004
Posts: 1,860
10-31-2004 18:05
cool idea thanks. one thing, will that llSetAlpha make it all the way invisible or just 95% or so like the building tool? can you go all the way invisible with a script?
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
11-01-2004 17:26
From: Zuzi Martinez
cool idea thanks. one thing, will that llSetAlpha make it all the way invisible or just 95% or so like the building tool? can you go all the way invisible with a script?


llSetAlpha will go all the way.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
11-01-2004 18:06
llSetAlpha() has recently been changed to allow 100% transparency, so yes, it'll make the prims completely invisible. :)
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Hiro Pendragon
bye bye f0rums!
Join date: 22 Jan 2004
Posts: 5,905
11-02-2004 02:46
From: Zuzi Martinez
can you go all the way invisible with a script?

Yes. Alpha != transparency setting.
_____________________
Hiro Pendragon
------------------
http://www.involve3d.com - Involve - Metaverse / Emerging Media Studio

Visit my SL blog: http://secondtense.blogspot.com
Psyra Extraordinaire
Corra Nacunda Chieftain
Join date: 24 Jul 2004
Posts: 1,533
11-02-2004 10:22
I'd love to see an offshoot of this, namely 'trigger looping animation on flight, stop upon landing'. I've never had any luck trying to figure out the whole llRequestPermissions stuff. Why does LL need to make that so darn hard?!? I'm tired of opening an animation box to make my wings flap when I want to fly. :)
_____________________
E-Mail Psyra at psyralbakor_at_yahoo_dot_com, Visit my Webpage at www.psyra.ca :)

Visit me in-world at the Avaria sims, in Grendel's Children! ^^
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
11-05-2004 11:23
From: Psyra Extraordinaire
I'd love to see an offshoot of this, namely 'trigger looping animation on flight, stop upon landing'. I've never had any luck trying to figure out the whole llRequestPermissions stuff. Why does LL need to make that so darn hard?!? I'm tired of opening an animation box to make my wings flap when I want to fly. :)


Hmm... something like this, Psyra? I dunno if this script actually works correctly, as I'm writing it here at work.

Hopefully someone will point out all the horrible, glaring mistakes I've made in my permissions code. ;)

EDIT: I think I've got it fixed. :D

CODE

// Cross Lament's Silly Animate-On-Flying Kludge

integer isFlying = FALSE ;

integer hasperms = FALSE ;

key lastuser ;

default
{
state_entry()
{
llSetTimerEvent( 2 ) ; // Polling rate, check every couple of seconds
}

timer()
{
integer flystatus = llGetAgentInfo( llGetOwner() ) ;

// if the agent is flying, and the status holder says they're not...
if( ( flystatus & AGENT_FLYING ) && !isFlying && hasperms )
{
isFlying = TRUE ;
llStartAnimation( "your-flying-animation" ) ;
}

// if the agent is NOT flying, and the status holder says they are...
else if( !( flystatus & AGENT_FLYING ) && isFlying && hasperms )
{
isFlying = FALSE ;
llStopAnimation( "your-flying-animation" ) ;
}
}

attach( key id )
{
if( ( id != NULL_KEY ) && !hasperms )
{
lastuser = id ;
llRequestPermissions( id, PERMISSION_TRIGGER_ANIMATION ) ;
}

else if( id = NULL_KEY )
{
hasperms = FALSE ;

integer i ;
list animlist = llGetAnimationList( lastuser ) ;

for( i = 0; i < llGetListLength( animlist ); i++ )
{
llStopAnimation( llList2String( animlist, i ) ) ;
}
}
}

run_time_permissions( integer perms )
{
if( perms & PERMISSION_TRIGGER_ANIMATION )
{
hasperms = TRUE ;
}

else
{
llWhisper( 0, "Warning: Animation permission not set!" ) ;
}
}
}
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Psyra Extraordinaire
Corra Nacunda Chieftain
Join date: 24 Jul 2004
Posts: 1,533
11-08-2004 16:56
Got a Syntax Error in line 48. ^_^
_____________________
E-Mail Psyra at psyralbakor_at_yahoo_dot_com, Visit my Webpage at www.psyra.ca :)

Visit me in-world at the Avaria sims, in Grendel's Children! ^^
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
11-09-2004 00:07
Hehe, I knew that was gonna happen. I fixed it, I think. :)
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Hawk Statosky
Camouflage tourist
Join date: 11 Nov 2003
Posts: 175
11-09-2004 02:21
You're missing a close-brace below the warning whisper, on inspection.
_____________________
This .sig has been cancelled due to lack of interest.
Satu Moreau
Seldom seen ***** phantom
Join date: 22 Nov 2004
Posts: 65
02-06-2005 00:26
Is there a version of this that can be used on non attached items to make them look animated? Like a pump I have for instance, that I want to trade visibility between parts back and forth to make it look like it's pumping?
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
03-02-2005 20:23
From: Satu Moreau
Is there a version of this that can be used on non attached items to make them look animated? Like a pump I have for instance, that I want to trade visibility between parts back and forth to make it look like it's pumping?


use link messages, and trigger off of them, rahter than checkign flying state, OR

depend on both scripts starting at same time, and do an on_timer(x) and flip alpha on/off on pieces as needed
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
03-06-2005 22:27
From: Satu Moreau
Is there a version of this that can be used on non attached items to make them look animated? Like a pump I have for instance, that I want to trade visibility between parts back and forth to make it look like it's pumping?


Something like these, then. :)

Controller script:
CODE
// Alpha-animation Controller Script
//
// User speficies the total number of frames in the animation and
// the frame rate in frames per second. Try to keep this reasonably low...


integer NUMBER_OF_FRAMES = 4 ; // Total number of frames in this animation

float FRAMES_PER_SECOND = 5 ; // I doubt it could handle 10fps :)

integer running = TRUE ;

animcycle()
{
integer i ;

for( i = 0; i < NUMBER_OF_FRAMES; i++ )
{
llMessageLinked( LINK_SET, (integer)llPow( 2.0, (float)i ), "", "" ) ;
llSleep( 1.0 / FRAMES_PER_SECOND ) ;
}
}


default
{
state_entry()
{
llSetTimerEvent( (float)NUMBER_OF_FRAMES / FRAMES_PER_SECOND ) ;
}

timer()
{
animcycle() ;
}

touch_start( integer num )
{
running = !running ;

if( running ) llSetTimerEvent( (float)NUMBER_OF_FRAMES / FRAMES_PER_SECOND ) ;

else llSetTimerEvent( 0 ) ;
}
}


Frame script (one of these goes into each prim that needs to 'change' between frames):

CODE
// Framescript
//
// Place this script in every prim that should be changing between frames
//
// For the FRAME_NUMBERS integer, OR together ( | ) the FRAMEs on which this prim should be visible
// Ie. if it should be visible on the 0th and 3rd frames, FRAME_NUMBERS = FRAME0 | FRAME3 ;
//
// Frames are numbered starting at zero!

integer FRAME0 = 1 ;
integer FRAME1 = 2 ;
integer FRAME2 = 4 ;
integer FRAME3 = 8 ;
integer FRAME4 = 16 ;
integer FRAME5 = 32 ;
integer FRAME6 = 64 ;
integer FRAME7 = 128 ;
integer FRAME8 = 256 ;
integer FRAME9 = 512 ;
integer FRAME10 = 1024 ;

integer FRAME_NUMBERS ;

integer is_visible = FALSE ;

default
{
state_entry()
{
FRAME_NUMBERS = FRAME0 ; // OR together all the frames this prim should be -visible- on
}

link_message( integer sender, integer num, string message, key id )
{
if( FRAME_NUMBERS & num )
{
if( !is_visible )
{
is_visible = TRUE ;
llSetAlpha( 1.0, ALL_SIDES ) ;
}
}

else
{
is_visible = FALSE ;
llSetAlpha( 0.0, ALL_SIDES ) ;
}
}
}
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Quick Stirling
Driveling Idiot
Join date: 3 Aug 2004
Posts: 33
03-10-2005 13:42
From: Shack Dougall
llSetAlpha will go all the way.


cool...do you have a phone number for llSetAlpha? :p
Logan Bauer
Inept Adept
Join date: 13 Jun 2004
Posts: 2,237
05-05-2005 18:29
That's hot. :D
Kazuma Onizuka
Registered User
Join date: 23 Apr 2004
Posts: 13
Hovering Flight / Forward Flight
06-15-2005 05:07
Hi, I'm so EXCITED I've found your scripts! I'm going to start working on making my own wings that will be closed when I'm not in flight and open & animated during flight. I think I have a rough understanding on how to combine these scripts to do this. I don't know how to script, but I'm pretty good at putting things together so they work really well :)

First I'm going to create wings that use the "Alpha-animation Controller Script" along with the "'Trigger Looping Animation Script" to basically turn them on during flight.

I'll then use the "Flight Responsive Visible/Invisible" script to make my wings appear to be closed when I'm not in flight. So I'll put the "Invisible" script on the starting wing prim of the Animated wings to make the "flight" wings invisible when not in flight. Then put the "Invisible" script on the closed wings during flight and "Visible" script on them when I'm not in flight.

That much I think I've gotten figured out, please tell me if I'm wrong or you have a better way of doing this.

My REAL question is: Do you have a script or know of one, (or could make one), that could make it so I could have TWO sets of wing animations and switch between my "Hovering" animated script and "Forward Flight" animated script? Basically what I want to do is, when I'm in flight and stationary or moving up/down the "Hovering" animated script would be on. And when I'm moving in any horizontal direction, it would switch to the "Forward Flight" animated script.

I know it might be more difficult, but to make it use the "Hovering" animated script when moving backwards would just make it perfect!

If you could look over my idea for how I want to put your scripts together for my wings, I'd appreciate it....just to make sure it will work hehe. And if you have any idea on how to make a script or know of one already made for my idea on "Hovering/Forward Flight animated script switching", I'd be SUPER HAPPY!!!!

- Kazuma Onizuka