A script to control your avatar's camera.
Relatively easy to follow. You could add your own camera presets to the menu.
<CODE>
integer CHANNEL; // dialog channel
list MENU_MAIN = ["Butt Cam", "God Cam", "Back Cam", "Trip Cam", "Ghost Cam", "Worm Cam", "Me Cam", "Fly Cam", "More...", "Cam ON", "Cam OFF"]; // the main menu
list MENU_2 = ["More...", "...Back"]; // menu 2
integer on = FALSE;
integer flying;
integer falling;
integer spaz = 0;
integer trap = 0;
take_camera_control(key agent)
{
llOwnerSay("take_camera_control"); // say function name for debugging
llOwnerSay( (string)agent);
llRequestPermissions(agent, PERMISSION_CONTROL_CAMERA);
llSetCameraParams([CAMERA_ACTIVE, 1]); // 1 is active, 0 is inactive
on = TRUE;
}
release_camera_control(key agent)
{
llOwnerSay("release_camera_control"); // say function name for debugging
llSetCameraParams([CAMERA_ACTIVE, 0]); // 1 is active, 0 is inactive
llReleaseCamera(agent);
on = FALSE;
}
focus_on_me()
{
llOwnerSay("focus_on_me"); // say function name for debugging
// llClearCameraParams(); // reset camera to default
vector here = llGetPos();
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 0.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.0, // (0 to 3) seconds
CAMERA_DISTANCE, 0.0, // ( 0.5 to 10) meters
CAMERA_FOCUS, here, // region relative position
CAMERA_FOCUS_LAG, 0.0 , // (0 to 3) seconds
CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
// CAMERA_PITCH, 80.0, // (-45 to 80) degrees
CAMERA_POSITION, here + <4,4,4>, // region relative position
CAMERA_POSITION_LAG, 0.0, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_FOCUS_OFFSET, ZERO_VECTOR // <-10,-10,-10> to <10,10,10> meters
]);
}
butt_cam()
{
// llOwnerSay("butt_cam"); // say function name for debugging
llClearCameraParams(); // reset camera to default
llSetCameraParams([CAMERA_ACTIVE, 1]);
}
fly_cam()
{
llOwnerSay("fly_cam"); // say function name for debugging
butt_cam();
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 45.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.5, // (0 to 3) seconds
CAMERA_DISTANCE, 8.0, // ( 0.5 to 10) meters
//CAMERA_FOCUS, <0,0,5>, // region relative position
CAMERA_FOCUS_LAG, 0.05 , // (0 to 3) seconds
CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_PITCH, 30.0, // (-45 to 80) degrees
//CAMERA_POSITION, <0,0,0>, // region relative position
CAMERA_POSITION_LAG, 0.1, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_FOCUS_OFFSET, <0,0,0> // <-10,-10,-10> to <10,10,10> meters
]);
}
me_cam()
{
llOwnerSay("me_cam"); // say function name for debugging
llClearCameraParams(); // reset camera to default
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.2, // (0 to 3) seconds
CAMERA_DISTANCE, 3.0, // ( 0.5 to 10) meters
//CAMERA_FOCUS, <0,0,5>, // region relative position
CAMERA_FOCUS_LAG, 0.02 , // (0 to 3) seconds
CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_PITCH, 10.0, // (-45 to 80) degrees
//CAMERA_POSITION, <0,0,0>, // region relative position
CAMERA_POSITION_LAG, 0.15, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_FOCUS_OFFSET, <0,0,0> // <-10,-10,-10> to <10,10,10> meters
]);
}
trip_cam()
{
llOwnerSay("trip_cam"); // say function name for debugging
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.0, // (0 to 3) seconds
// CAMERA_DISTANCE, 10.0, // ( 0.5 to 10) meters
//CAMERA_FOCUS, <0,0,5>, // region relative position
CAMERA_FOCUS_LAG, 3.0 , // (0 to 3) seconds
// CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
// CAMERA_PITCH, 80.0, // (-45 to 80) degrees
//CAMERA_POSITION, <0,0,0>, // region relative position
// CAMERA_POSITION_LAG, 0.0, // (0 to 3) seconds
// CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_FOCUS_OFFSET, <5,2,-2> // <-10,-10,-10> to <10,10,10> meters
]);
}
god_cam()
{
llOwnerSay("god_cam"); // say function name for debugging
butt_cam();
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.5, // (0 to 3) seconds
CAMERA_DISTANCE, 10.0, // ( 0.5 to 10) meters
//CAMERA_FOCUS, <0,0,5>, // region relative position
CAMERA_FOCUS_LAG, 0.05 , // (0 to 3) seconds
CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_PITCH, 80.0, // (-45 to 80) degrees
//CAMERA_POSITION, <0,0,0>, // region relative position
CAMERA_POSITION_LAG, 0.0, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_FOCUS_OFFSET, <0,0,0> // <-10,-10,-10> to <10,10,10> meters
]);
}
ghost_cam()
{
llOwnerSay("ghost_cam"); // say function name for debugging
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 0.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.5, // (0 to 3) seconds
CAMERA_DISTANCE, 3.0, // ( 0.5 to 10) meters
//CAMERA_FOCUS, <0,0,5>, // region relative position
CAMERA_FOCUS_LAG, 2.0, // (0 to 3) seconds
CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_PITCH, 0.0, // (-45 to 80) degrees
//CAMERA_POSITION, <0,0,0>, // region relative position
CAMERA_POSITION_LAG, 0.05, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
CAMERA_FOCUS_OFFSET, <0,0,0> // <-10,-10,-10> to <10,10,10> meters
]);
llSleep(5);
butt_cam();
}
worm_cam()
{
llOwnerSay("worm_cam"); // say function name for debugging
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.0, // (0 to 3) seconds
CAMERA_DISTANCE, 8.0, // ( 0.5 to 10) meters
//CAMERA_FOCUS, <0,0,5>, // region relative position
CAMERA_FOCUS_LAG, 0.0 , // (0 to 3) seconds
CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 4.0, // (0 to 4) meters
CAMERA_PITCH, -45.0, // (-45 to 80) degrees
//CAMERA_POSITION, <0,0,0>, // region relative position
CAMERA_POSITION_LAG, 1.0, // (0 to 3) seconds
CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 1.0, // (0 to 4) meters
CAMERA_FOCUS_OFFSET, <0,0,0> // <-10,-10,-10> to <10,10,10> meters
]);
}
spaz_cam()
{
llOwnerSay("spaz_cam for 5 seconds"); // say function name for debugging
float i;
for (i=0; i< 50; i+=1)
{
vector xyz = llGetPos() + <llFrand(80) - 40, llFrand(80) - 40, llFrand(10)>;
// llOwnerSay((string)xyz);
vector xyz2 = llGetPos() + <llFrand(80) - 40, llFrand(80) - 40, llFrand(10)>;
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_BEHINDNESS_ANGLE, 180.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, llFrand(3), // (0 to 3) seconds
CAMERA_DISTANCE, llFrand(10), // ( 0.5 to 10) meters
//CAMERA_FOCUS, xyz, // region relative position
CAMERA_FOCUS_LAG, llFrand(3), // (0 to 3) seconds
CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, llFrand(4), // (0 to 4) meters
CAMERA_PITCH, llFrand(125) - 45, // (-45 to 80) degrees
CAMERA_POSITION, xyz2, // region relative position
CAMERA_POSITION_LAG, llFrand(3), // (0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE, // (TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, llFrand(4), // (0 to 4) meters
CAMERA_FOCUS_OFFSET, <llFrand(20) - 10, llFrand(20) - 10, llFrand(20) - 10> // <-10,-10,-10> to <10,10,10> meters
]);
llSleep(0.1);
}
butt_cam();
}
back_cam()
{
llSetCameraParams([
CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
CAMERA_DISTANCE, 5.0, // ( 0.5 to 10) meters
CAMERA_PITCH, 10.0, // (-45 to 80) degrees
CAMERA_BEHINDNESS_ANGLE, 0.0, // (0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.1, // (0 to 3) seconds
CAMERA_FOCUS_OFFSET, <0.0,0.0,1.5>, // <-10,-10,-10> to <10,10,10> meters
CAMERA_FOCUS, llGetPos(), // region-relative position
CAMERA_FOCUS_LAG, 0.1, // (0 to 3) seconds
CAMERA_FOCUS_THRESHOLD, 0.1, // (0 to 4) meters
CAMERA_FOCUS_LOCKED, FALSE, // (TRUE or FALSE)
CAMERA_POSITION, llGetPos(), // region-relative position
CAMERA_POSITION_LAG, 0.5, // (0 to 3) seconds
CAMERA_POSITION_THRESHOLD, 0.5, // (0 to 4) meters
CAMERA_POSITION_LOCKED, FALSE // (TRUE or FALSE)
]);
}
setup_listen()
{
llListenRemove(1);
CHANNEL = llRound(llFrand(1) * 100000);
integer x = llListen(CHANNEL, "", "", ""); // listen for dialog answers
}
default
{
state_entry()
{
setup_listen();
llSetTimerEvent(2);
}
touch_start(integer total_number)
{
integer perm = llGetPermissions();
if (perm & PERMISSION_DEBIT)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_DEBIT perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_TAKE_CONTROLS)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_TAKE_CONTROLS perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_TRIGGER_ANIMATION)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_TRIGGER_ANIMATION perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_ATTACH)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_ATTACH perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_CHANGE_LINKS)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_CHANGE_LINKS perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_TRACK_CAMERA)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_TRACK_CAMERA perms for "+(string)llGetPermissionsKey()); }
if (perm & PERMISSION_CONTROL_CAMERA)
{ llOwnerSay(llGetScriptName() + " has PERMISSION_CONTROL_CAMERA perms for "+(string)llGetPermissionsKey()); }
if (perm == 0)
{ llOwnerSay(llGetScriptName() + " has NO perms for "+(string)llGetPermissionsKey()); }
llDialog(llDetectedKey(0), "What do you want to do?", MENU_MAIN, CHANNEL); // present dialog on click
}
listen(integer channel, string name, key id, string message)
{
if (llListFindList(MENU_MAIN + MENU_2, [message]) != -1) // verify dialog choice
// if (llListFindList(MENU_MAIN, [message]) != -1) // verify dialog choice
{
// llOwnerSay(name + " picked the option '" + message + "'."); // output the answer
if (message == "More...")
llDialog(id, "Pick an option!", MENU_2, CHANNEL); // present submenu on request
else if (message == "...Back")
llDialog(id, "What do you want to do?", MENU_MAIN, CHANNEL); // present main menu on request to go back
else if (message == "Cam ON")
{
take_camera_control(id);
}
else if (message == "Cam OFF")
{
release_camera_control(id);
}
else if (message == "Butt Cam")
{
butt_cam();
}
else if (message == "Fly Cam")
{
fly_cam();
}
else if (message == "Worm Cam")
{
worm_cam();
}
else if (message == "God Cam")
{
god_cam();
}
else if (message == "Trip Cam")
{
trip_cam();
}
else if (message == "Me Cam")
{
me_cam();
}
else if (message == "Ghost Cam")
{
ghost_cam();
}
else if (message == "Trap Toggle")
{
trap = !trap;
if (trap == 1) {
llOwnerSay("trap is on");
}
else {
llOwnerSay("trap is off");
}
}
else if (message == "Back Cam")
{
back_cam();
}
} else
llOwnerSay(name + " picked invalid option '" + llToLower(message) + "'."); // not a valid dialog choice
}
run_time_permissions(integer perm) {
if ((perm & PERMISSION_CONTROL_CAMERA) == PERMISSION_CONTROL_CAMERA) {
llSetCameraParams([CAMERA_ACTIVE, 1]); // 1 is active, 0 is inactive
llOwnerSay("Camera permissions have been taken");
}
}
changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
setup_listen();
llRequestPermissions(agent, PERMISSION_CONTROL_CAMERA);
}
}
}
attach(key agent)
{
if (agent != NULL_KEY)
{
setup_listen();
llRequestPermissions(agent, PERMISSION_CONTROL_CAMERA);
}
}
timer()
{
if (trap == 1)
{
focus_on_me();
}
}
}
</CODE>

No comments:
Post a Comment
Note: only a member of this blog may post a comment.