07-26-2003 08:32
CODE

// Take Controls example
//
// Wednesday Grimm, July 26, 2003
//
// A script with the right permissions can capture user input
// that would normally go to the avatar (and maybe pass that
// input on to the avatar as well). This script is a simple
// demonstration of how to take controls and use them
//


// doTakeControls - actually take inputs from the avatar, we assume
// that we already have PERMISSION_TAKE_CONTROLS
doTakeControls()
{
llTakeControls(
CONTROL_FWD | CONTROL_ROT_LEFT, // These are the controls we are taking,
// if the user presses or releases any
// of these keys (or buttons) then
// the control() event will be triggered

TRUE, // accept, TRUE if we want to receive these keys,
// FALSE to release these controls (you can set this to
// FALSE to release some controls without releasing all
// controls (you would use llReleaseControls() to do that))


TRUE // pass_on, if TRUE, the avatar also receives this input
// and therefore moves. For vehicle-like scripts, set this
// to FALSE
);
}

// startup - check to see if we have PERMISSION_TAKE_CONTROLS, if we
// do, take the controls, if not, request the permission
startup()
{
integer nMyPerms;
nMyPerms = llGetPermissions();
if (nMyPerms & PERMISSION_TAKE_CONTROLS)
{
doTakeControls();
}
else
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
}

default
{
state_entry()
{
startup();
}

on_rez(integer nRezParam)
{
startup();
}

// this scripts run time permissions have changed. See if the
// user granted us PERMISSION_TAKE_CONTROLS and if so, take 'em
run_time_permissions(integer nMyPerms)
{
if (nMyPerms & PERMISSION_TAKE_CONTROLS)
{
doTakeControls();
}
}

control(key id, integer level, integer edge)
{
// something has happened to one of the
// keys we're watching. One or more of them was
// pressed, released or held down
//
// id is the avatar that generated the event, we are only
// capturing controls from 1 avatar, so we don't care
// about this
//
// level is the state of the key, 1 for down, 0 for up
//
// edge shows if the state of the key has changed, 1
// for changed, 0 for the same

if (level & CONTROL_FWD )
{
// The forward key is down, see if it was just pressed or if it is
// held down
if (edge & CONTROL_FWD)
{
llWhisper(0, "Forward key pressed");
}
else
{
llWhisper(0, "Forward key held down");
}
}
else
{
// the forward key is up, see if it was just released
if (edge & CONTROL_FWD)
{
llWhisper(0, "Forward key released");
}
else
{
// we only get here if something happens to the other key we're
// watching.
llWhisper(0, "Forward key up");
}
}
}
}

_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!