Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

turn off things when avatar stands up

Robin Peel
Registered User
Join date: 8 Feb 2005
Posts: 163
05-11-2008 09:30
hello, i've tried this a few ways and i'm missing something very easy. so i need advice from the experts that live in these forums.
what i want to do is to turn off various things that are running such as particles when the driver stands up. its the non physics movement that Jesrad Seraph posted in these forums. i placed a llMessageLinked(); in the stop(); section and another in the touch. it works great if its touched. but won't when the avatar just stands up even though there is a stop(); in run_time_permissions(integer p).
can somebody please look and let me know what i need to do or can point me in the right direction.
thank you very much.

CODE

// Main script: you may want to tweak a bit the initial speed and acceleration settings, and also the sit target and camera offsets.

// Non-Physical Flying Vehicle
// A.K.A: How to exploit tricks in LSL to get your way
//
// (your way being: up to 254 prims on a vehicle, in this case)
// Author: Jesrad Seraph
// Modify and redistribute freely, as long as your permit free modification and redistribution

// The variable "hidden_face" must be the same for all the scripts, it's the face number that will be used to transmit information from the main script to the parralelle movement scripts, so make sure the face is not visible (5 is the inside face of hollowed cubes, on spheres it's 1).

// These scripts are provided as-is. They work for me, and I can provide a ready-to-drop copy of those scripts inworld. You can use these scripts in a commercial build, but please keep them full perms if you do. This won't affect the permissions on your object in any way.

// Main script: you may want to tweak a bit the initial speed and acceleration settings, and also the sit target and camera offsets.

integer hidden_face = 1;

float max_fwd = 6.0; // max speed in m per quarter of a second - default 2
integer max_rot = 8; // max turning speed in degrees per quarter of a second
float hover_height = 0.01; // prefered minimum height above ground

integer down;
integer change;

float fwd_accel = 0.05; // forward/back acceleration - default 0.015625
float up_accel = 0.02; // vertical acceleration
float left_accel = 0.02; // strafing acceleration
float rot_accel = 0.03; // turning acceleration

float inertia = 0.75; // movement slowdown rate
float moment = 0.5; // turning slowdown rate


// internal stuff, don't modify
vector velocity;
float rotacity;
vector veloff = <0.5, 0.5, 0.5>;
integer timeout;

integer controls;
key pilot;

stop()
{
vector aim;
llReleaseControls();
llResetOtherScript("turn");
llResetOtherScript("turn1");
llResetOtherScript("turn2");
llResetOtherScript("turn3");
llResetOtherScript("rota");
llResetOtherScript("rota1");
llResetOtherScript("rota2");
llResetOtherScript("rota3");
llResetOtherScript("move");
llResetOtherScript("move1");
llResetOtherScript("move2");
llResetOtherScript("move3");
timeout = 0;
llSetTimerEvent(0.0);
pilot = NULL_KEY;
velocity = ZERO_VECTOR;
rotacity = 0.0;
llSetColor(velocity + veloff, hidden_face);
llSetAlpha(rotacity + 0.5, hidden_face);
aim = llRot2Euler(llGetRot());
aim.x = 0.0;
aim.y = 0.0;
llSetRot(llEuler2Rot(aim));
llMessageLinked(LINK_ALL_OTHERS, 987654321, "", NULL_KEY); // Switch off
llStopSound();
}

default
{
state_entry()
{
key id = llGetOwner();
llListen(4,"",id,"");
controls = CONTROL_FWD|CONTROL_BACK|CONTROL_UP|CONTROL_DOWN|CONTROL_LEFT|CONTROL_RIGHT|CONTROL_ROT_LEFT|CONTROL_ROT_RIGHT;
stop();
//llSitTarget(<0.25, 0.0, 0.4>, ZERO_ROTATION);
//llSetCameraAtOffset(<1.0, 0.0, 0.0>);
//llSetCameraEyeOffset(<-3.0, 0.0, 0.0>);
}

on_rez(integer param)
{
llResetScript();
}

listen(integer channel,string name,key id,string message)
{
message = llToLower(message);
if (message == "start")
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
llMessageLinked(LINK_ALL_OTHERS, 123456789, "", NULL_KEY);
}
if (message == "stop")
{
stop();
}
}

changed(integer change)
{
if (change & 128)
{
llResetScript();
}
}

touch_start(integer c)
{
if (llDetectedKey(0) != llGetOwner()) return;
if (pilot == llGetOwner())
{
stop();
} else
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
//llSleep (2);
//llLoopSound ("72499d8a-ef3f-d7f0-f80e-9ebc9a0f4cc8", 1);
llMessageLinked(LINK_ALL_OTHERS, 123456789, "", NULL_KEY); // Switch on
}
}

run_time_permissions(integer p)
{
if (p & PERMISSION_TAKE_CONTROLS)
{
llResetOtherScript("turn");
llResetOtherScript("turn1");
llResetOtherScript("turn2");
llResetOtherScript("turn3");
pilot = llGetPermissionsKey();
llTakeControls(controls, TRUE, FALSE);
velocity = ZERO_VECTOR;
rotacity = 0.0;
llSetColor(velocity + veloff, hidden_face);
llSetAlpha(rotacity + 0.5, hidden_face);
llMessageLinked(LINK_THIS, 0, "piloted", pilot);
} else if (llGetPermissions() & PERMISSION_TAKE_CONTROLS == FALSE)
{
stop();
}
}

control(key id, integer level, integer edge)
{
down = level;
change = edge;

if (down & controls)
{
if (timeout == 0)
{
llMessageLinked(LINK_THIS, max_rot, "nonphy", (key)((string)max_fwd));
llSetTimerEvent(0.05);
}
timeout = 12;
}
}

timer()
{
if (--timeout == 0)
{
llResetOtherScript("move");
llResetOtherScript("move1");
llResetOtherScript("move2");
llResetOtherScript("move3");
llResetOtherScript("rota");
llResetOtherScript("rota1");
llResetOtherScript("rota2");
llResetOtherScript("rota3");
llSetTimerEvent(0.0);
return;
}

if (down & CONTROL_FWD)
{
if (velocity.x < 0.0) velocity.x = 0.0;
velocity.x += fwd_accel;
if (velocity.x > 0.5 ) velocity.x = 0.5;
} else if (down & CONTROL_BACK)
{
if (velocity.x > 0.0) velocity.x = 0.0;
velocity.x -= fwd_accel;
if (velocity.x < -0.5 ) velocity.x = -0.5;
} else {
velocity.x *= inertia;
}

if (down & CONTROL_UP)
{
if (velocity.z < 0.0) velocity.z = 0.0;
velocity.z += up_accel;
if (velocity.z > 0.5 ) velocity.z = 0.5;
} else if (down & CONTROL_DOWN)
{
if (velocity.z > 0.0) velocity.z = 0.0;
velocity.z -= up_accel;
if (velocity.z < -0.5 ) velocity.z = -0.5;
if (llGetPos() * <0,0,1> < llGround(ZERO_VECTOR) + max_fwd * velocity.z + hover_height)
velocity.z = 0.0;
} else {
velocity.z *= inertia;
if (llGetPos() * <0,0,1> < llGround(ZERO_VECTOR) + max_fwd * velocity.z + hover_height)
velocity.z = 0.0;
}

if (down & CONTROL_LEFT)
{
if (velocity.y < 0.0) velocity.y = 0.0;
velocity.y += left_accel;
if (velocity.y > 0.5 ) velocity.y = 0.5;
} else if (down & CONTROL_RIGHT)
{
if (velocity.y > 0.0) velocity.y = 0.0;
velocity.y -= left_accel;
if (velocity.y < -0.5 ) velocity.y = -0.5;
} else {
velocity.y *= inertia;
}

if (down & CONTROL_ROT_LEFT)
{
if (rotacity < 0.0) rotacity = 0.0;
rotacity += rot_accel;
if (rotacity > 0.5 ) rotacity = 0.5;
} else if (down & CONTROL_ROT_RIGHT)
{
if (rotacity > 0.0) rotacity = 0.0;
rotacity -= rot_accel;
if (rotacity < -0.5 ) rotacity = -0.5;
} else {
rotacity *= moment;
}

llSetColor(velocity * llGetRot() + veloff, hidden_face);
llSetAlpha(rotacity + 0.5, hidden_face);
}
}
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
05-11-2008 09:54
CODE
changed(integer change)
{
if (change & 128)
{
llResetScript();
}
}



This is where sit detection ususally is.. in changed. You're using a hardcoded integer, rather than a bitwise constant. I don't know what "128" translates to.. but here's my take on the changed event.

When an avatar sits, their "AGENT" (the invisible prim that is our actual pghysical BODY inworld) is added to the linkset of whatever we sit upon. This simple fact explains so much about why we become immune to a lot of attacks while seated. out AGENTS become a PART of the chair!. When we get up, the agent is UNLINKED from the linkset. Therefore, the changed event is the way to detect joining and parting.. and we use "CHANGED_LINK" because the number of prims actually changes (as far as LSL is concerned).

CODE
changed(integer change)
{
if (change & CHANGED LINK) // linkset changed
{
key sitter = llAvatarOnSitTarget();

if (sitter != NULL_KEY) // someone is sitting on the sit target
{
// start stuff
}
else // they got up
{
//stop stuff
}
}
}


You may find that what you want to do, is to store the sitter's key on "sit", and then scan the linkset for the presence of that key. We've noticed in some tests that the above MAY be able to be fooled. We had a vehicle, and a "second sitter" who sat on a non-sit-target, was tricking the script into thinking that the pilot got up.

Here's an example of one idea I had to workaround that issue.


CODE
key lastsitter; // way up at top

integer checksitter()
{
integer i;
for (i = llGetNumberOfPrims(); i > -1; i --)
{
if (llGetLinkKey(i) == lastsitter) return TRUE;
}
return FALSE;
}


// then in the default state...


changed(integer change)
{
if (change & CHANGED LINK) // linkset changed
{
key sitter = llAvatarOnSitTarget();

if (sitter != NULL_KEY) // someone is sitting on the sit target
{
lastsitter = sitter;
// start stuff
}
else // they got up
{
if (!checksitter()) // if lastsitter is NOT found
{
lastsitter = NULL_KEY;
// stop stuff
}
}
}
}
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Robin Peel
Registered User
Join date: 8 Feb 2005
Posts: 163
05-12-2008 00:55
Thank you. I'll give this a try when I get on tonight.