Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: ChangeableSitPosScript

Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
05-17-2007 09:48
Hello there,

Strife released an awesome function the other day. I made a user-friendly script by using that.

Put this script into your chair.
Sit and touch it.
Arrows and PageUp/Down can change your avatar's sitting position.
Shift + Left/Right arrows can rotate it.
Touch again and fixed it.

CODE
//This script was mainly made of Strife&Escort's UpdateSitTarget function.
//And I learned the way of detecting the avatar positon from Qui Niangao's mass.
//Tonkotsu Nico & Shizuna Jeffries helped to create.
//Thanks all guys.

key av;
vector currentPos;
rotation currentRot;
integer touchFlag;

//Sets / Updates the sit target moving the avatar on it if necessary.
UpdateSitTarget(vector pos, rotation rot)
{
llSitTarget(pos, rot);//Set the sit target
key user = llAvatarOnSitTarget();
if(user)//true if there is a user seated on the sittarget, if so update their position
{
vector size = llGetAgentSize(user);
if(size)//This tests to make sure the user really exists.
{
//We need to make the position and rotation local to the current prim
rotation localrot = ZERO_ROTATION;
vector localpos = ZERO_VECTOR;
if(llGetLinkNumber() > 1)//only need the local rot if it's not the root.
{
localrot = llGetLocalRot();
localpos = llGetLocalPos();
}
pos.z += 0.4;
integer linkNum = llGetNumberOfPrims();
do{
if(user == llGetLinkKey( linkNum ))//just checking to make sure the index is valid.
{
llSetLinkPrimitiveParams(linkNum,
[PRIM_POSITION, ((pos - (llRot2Up(rot) * size.z * 0.02638)) * localrot) + localpos,
PRIM_ROTATION, rot * localrot / llGetRootRotation()]);
jump end;//cheaper but a tad slower then return
}
}while( --linkNum );
}
else
{//It is rare that the sit target will bork but it does happen, this can help to fix it.
llUnSit(user);
}
}
@end;
}//Written by Strife Onizuka, size adjustment provided by Escort DeFarge


default
{
state_entry()
{
llSitTarget(<0, 0, 0.25>, ZERO_ROTATION);
}
changed(integer change)
{
av = llAvatarOnSitTarget();
if(av == NULL_KEY)
{
if(llGetPermissions() & PERMISSION_TAKE_CONTROLS)
{
llReleaseControls();
}
}
}
touch_start(integer num_detected)
{
if(av == llDetectedKey(0))
{
if(!touchFlag)
{
vector avPos = llDetectedPos(0);
rotation avRot = llDetectedRot(0);
vector avSize = llGetAgentSize(llDetectedKey(0));
vector heightGlitch = <0, 0, (avSize.z/37.9)>;
vector primPos = llGetPos();
rotation primRot = llGetRot();
currentPos = (avPos + heightGlitch*avRot - primPos) / primRot - < 0, 0, 0.4>;
currentRot = avRot / primRot;
llRequestPermissions(av, PERMISSION_TAKE_CONTROLS);
}
else
{
if(llGetPermissions() & PERMISSION_TAKE_CONTROLS)
{
llReleaseControls();
llWhisper(0, "UpdateSitTargget has been deactivated.");
}
}
touchFlag = !touchFlag;
}
}
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;
if(perms & PERMISSION_TAKE_CONTROLS)
{
llWhisper(0, "UpdateSitTargget has been activated.");
llTakeControls(desired_controls, TRUE, FALSE);
}
}
control(key id, integer level, integer edge)
{
if(level & CONTROL_FWD)
{
currentPos = currentPos + (llRot2Fwd(llGetRot())/10);
}
else if(level & CONTROL_BACK)
{
currentPos = currentPos - (llRot2Fwd(llGetRot())/10);
}
else if(level & CONTROL_LEFT)
{
currentRot = llGetRot() + (currentRot * llEuler2Rot(<0, 0, -10> * DEG_TO_RAD));
}
else if(level & CONTROL_RIGHT)
{
currentRot = llGetRot() + (currentRot * llEuler2Rot(<0, 0, 10> * DEG_TO_RAD));
}
else if(level & CONTROL_ROT_LEFT)
{
currentPos = currentPos + (llRot2Left(llGetRot())/10);
}
else if(level & CONTROL_ROT_RIGHT)
{
currentPos = currentPos - (llRot2Left(llGetRot())/10);
}
else if(level & CONTROL_UP)
{
currentPos = currentPos + llRot2Up(llGetRot())/10;
}
else if(level & CONTROL_DOWN)
{
currentPos = currentPos - (llRot2Up(llGetRot())/10);
}
UpdateSitTarget(currentPos, currentRot);
llSleep(0.1);
}
}
_____________________
:) Seagel Neville :)
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
05-18-2007 06:54
/15/97/184550/1.html
_____________________
i've got nothing. ;)