here is the script:
CODE
default
{
state_entry()
{
//Do some initialization here
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
on_rez(integer param)
{
llResetScript(); // reset the script as soon as it starts.
//llSetTimerEvent(5);
}
run_time_permissions(integer permissions)
{
if (permissions)
{
llSay(0, "Initialized Successfully...");
state transition;
}
}
attach(key who)
{
integer perm = llGetPermissions();
if (who == NULL_KEY) {
// detached
if (llGetPermissions() & PERMISSION_TAKE_CONTROLS) {
llReleaseControls();
}
} else {
llRequestPermissions(who, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
}
}
state transition
{
state_entry()
{
vector pos = llGetPos(); // Gets your current position
vector size = llGetAgentSize(llGetOwner()); // Get the dimensions of your agent
size.z = size.z / 2; // Halve the height element of your agent, get altitude from feet
pos.z = pos.z + size.z;
float abovewater = llWater(<0,0,0>) + pos.z; // difference between yourwater height
` if (pos.z < llWater(<0,0,0>)) // If underwater
{
state swimming;
} else {
state dry;
}
}
}
state swimming
{
state_entry(){
llSay(0, "Wet");
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
llGroundRepel(-0.5, 1, 1);
//llStopAnimation("falldown"); // automatically trigger animation.
//llStopAnimation("fly"); // automatically trigger animation.
//llStartAnimation("hover"); // automatically trigger animation.
//llSetTimerEvent(5);
llMinEventDelay(0.1);
}
attach(key who)
{
integer perm = llGetPermissions();
if (who == NULL_KEY) {
// detached
if (llGetPermissions() & PERMISSION_TAKE_CONTROLS) {
llReleaseControls();
}
} else {
llRequestPermissions(who, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
}
run_time_permissions(integer perms)
{
integer desired_controls =
CONTROL_FWD |
CONTROL_BACK |
CONTROL_LEFT |
CONTROL_RIGHT |
CONTROL_ROT_LEFT |
CONTROL_ROT_RIGHT //|
//CONTROL_UP |
//CONTROL_DOWN |
//CONTROL_LBUTTON |
//CONTROL_ML_LBUTTON
;
if (perms & PERMISSION_TAKE_CONTROLS) {
llTakeControls(1, 1, 0); // glitch the rotation
llTakeControls(desired_controls, 1, 0);
}
}
control(key id, integer down, integer new)
{
integer pressed = down & new;
integer held = down & ~new;
integer released = ~down & new;
if (pressed & CONTROL_FWD) {
llGroundRepel(-0.5, 1, 1);
string ani = llGetAnimation(llGetOwner());
if (ani != "Flying" ) {
llStopAnimation(ani);
llStartAnimation("fly");
}
}
if (held & CONTROL_FWD) {
vector pos = llGetPos(); // Gets your current position
vector size = llGetAgentSize(llGetOwner()); // Get the dimensions of your agent
size.z = size.z / 2; // Halve the height element of your agent, get altitude from feet
pos.z = pos.z + size.z;
float abovewater = llWater(<0,0,0>) + pos.z; // difference between your water height
` if (pos.z > llWater(<0,0,0>)) // If above water
{
llReleaseControls();
state dry;
}
vector newVel = <4,0,0>;
vector curVel = llGetVel();
rotation rot = llGetRot();
curVel /= rot; // Un-rotate curVel.
newVel -= curVel;
newVel *= llGetMass();
newVel.z = 0;
llApplyImpulse(newVel, TRUE);
string ani = llGetAnimation(llGetOwner());
if (ani != "Flying" ) {
llStopAnimation(ani);
llStartAnimation("fly");
}
}
if (released & CONTROL_FWD) {
llApplyImpulse(-llGetMass()*llGetVel(),FALSE);
string ani = llGetAnimation(llGetOwner());
if (ani != "Hovering" ) {
llStopAnimation(ani);
llStartAnimation("hover");
}
}
if (released & CONTROL_BACK) {
llApplyImpulse(-llGetMass()*llGetVel(),FALSE);
llStopAnimation("falldown"); // stop.
llStopAnimation("hover"); // stop.
llStartAnimation("fly"); // automatically trigger animation.
}
if (held & CONTROL_DOWN) {
llApplyImpulse(llGetMass()*<0,0,-20>,FALSE);
}
}
}
state dry
{
state_entry()
{
llReleaseControls();
state transition;
}
}
Seagel Neville