This script was created so I could use both a flight script and the anti-push script without blatently conflicting. The anti push portion with the flight is truly great. It won't stop people from knocking you out of a sim, but minor pushes and such won't bother you. What's more is if you're not doing anything and you happen to fall for some reason (you were standing high on a platform in cordova or something and someone deletes it), you won't fall very far before the script catches you. It's amazingly convenient. Also knowing just who's bullet smacked into you in your chatlog provides a lot of peace of mind. It could certainly use some improvements though. (as outlined in the known bugs)
Known Bugs:
Releasing controls at this time seems imperfect, I believe I forgot to set locked to false if you're locked and you release controls, thus you stay locked. (easy to fix, but I'm that lazy)
Leaving a sim or entering a sim during extreme time dilation or lag seems to lock you sometimes without taking controls. I have no idea what's going on here.
Flight controls seem to not allow you to descend to the ground at anything other than Walk!. What happens is you kind of bounce at a certain height depending on your speed. I don't have the best grasp of physics, but I imagine someone who does will immediately grasp what's going on here and can either fix it or comment on what's wrong.
The detection script works great except that your own avatar will cause it to set off when you collide with scripted objects on purpose. I have an elevator in particular that set this off constantly. A work around is to check for your own name in the list, but this still won't stop instances of you bumping into other people rather than vice versa. So I really have no idea how to check for that, if you can check for that.
CODE
// Anti-Grief Script, a combination of three other public domain scripts
// Enjoy
// (Anti Push/lock, Flight (with my own improvements), and attack detection.
// Freely donated to the public domain
integer speed=10000;
integer locked; // TRUE if avatar is damping to current position
float LOCKWAIT = 1.0; // if you don't move for this period of time, you lock into place
key owner;
key nameRequest;
key onlineRequest;
key objectowner;
string name;
string presentInSimTestName;
default
{
state_entry()
{
owner=llGetOwner();
llListen(0,"",owner,"");
}
collision_start(integer detected)
{
if (llDetectedType(0) & SCRIPTED)
{
objectowner = llDetectedOwner(0);
presentInSimTestName = llKey2Name(objectowner);
if (presentInSimTestName == "")
llWhisper(0,"owner is not in this sim");
nameRequest = llRequestAgentData(objectowner, DATA_NAME);
onlineRequest = llRequestAgentData(objectowner, DATA_ONLINE);
}
}
dataserver(key queryid, string data)
{
if (queryid == nameRequest)
{
llSay(0,"you were attacked by " + data);
name = data;
}
//sometimes the name isn't reruned in time for the onlineRequest test to use it.
//If not, wait 3 seconds and try again. Don't realy know if this will work or just hang up the script
if (queryid == onlineRequest && data == "0" && presentInSimTestName == "")
{
llWhisper(0,name + " is NOT online");
}
if (queryid == onlineRequest && data == "0" && name != "")
{
llWhisper(0,name + " is NOT online");
}
if (queryid == onlineRequest && data == "0" && name == "")
{
llSleep(3);
llWhisper(0,name + " is NOT online");
}
}
// request controls & prime locked condition
on_rez(integer start_param)
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
locked = FALSE;
}
// if user accepts, trap control events and also allow them to pass on to the avatar for movement:
//
// llTakeControls(integer controls, integer accept, integer pass_on);
//
// If (accept == (controls & input)), send input to object. If the boolean pass_on is TRUE, also send input to avatar.
run_time_permissions(integer perm)
{
if(perm & (PERMISSION_TAKE_CONTROLS))
{
llTakeControls(CONTROL_FWD|
CONTROL_BACK|
CONTROL_RIGHT|
CONTROL_LEFT|
CONTROL_ROT_RIGHT|
CONTROL_ROT_LEFT|
CONTROL_UP|
CONTROL_DOWN,
TRUE, TRUE);
// set timer to periodically check the time since the last control input
llSetTimerEvent(1);
}
}
// called any time a user moves. release the damping if the avatar is locked. reset the time since last movement.
control(key id, integer level, integer edge)
{
if (locked)
{
llMoveToTarget(llGetPos(), 0);
locked = FALSE;
llSetForce(<0,0,0>, FALSE);
//llWhisper(0, "unlocked");
}
//else if (!(level & CONTROL_FWD))
//{
// llSetForce(<0,0,0>, FALSE);
//}
else if(level & CONTROL_FWD)
{
vector fwd= llRot2Fwd(llGetRot());
fwd = llVecNorm(fwd);
fwd *= speed; // multiplies the fwd speed
llSetForce(fwd, FALSE); // applies force to accelerate
}
else if(level & CONTROL_UP)
{
vector up= llRot2Up(llGetRot());
up = llVecNorm(up);
up *= speed; // multiplies the fwd speed
llSetForce(up, FALSE); // applies force to accelerate
}
else if(level & CONTROL_DOWN)
{
rotation inverse = llGetRot();
inverse.s = -inverse.s;
vector down = llRot2Up(inverse);
down = llVecNorm(down);
down *= speed; // multiplies the fwd speed
llSetForce(down, FALSE); // applies force to accelerate
}
else if(level & CONTROL_BACK)
{
rotation inverse = llGetRot();
inverse.s = -inverse.s;
vector back= llRot2Fwd(inverse);
back = llVecNorm(back);
back *= speed; // multiplies the fwd speed
llSetForce(back, FALSE); // applies force to accelerate
}
else
{
llSetForce(<0,0,0>, FALSE);
}
llResetTime();
}
// if the avatar is not already locked and it has been longer than the wait time since the last movement then lock the avatar
timer()
{
if ((!locked) && (llGetTime() > LOCKWAIT))
{
llMoveToTarget(llGetPos(), 0.2);
locked = TRUE;
//llWhisper(0, "locked");
}
}
listen(integer channel, string name, key id, string message)
{
// if(id==owner)
// {
if(message=="Stop")
{
llReleaseControls();
llWhisper(0,"What, you don't like the SPEED?");
}
if(message=="Fly")
{
llWhisper(0,"WOOWHOOO!");
speed=10000;
if (owner)
{
llRequestPermissions(owner, PERMISSION_TAKE_CONTROLS);
}
}
if (message=="Walk!")
{
speed=1;
llWhisper(0, "A casual walk?");
}
if (message=="Trot!")
{
speed=100;
llWhisper(0, "Moving to a brisk pace??");
}
if (message=="Sprint!")
{
speed=10000;
llWhisper(0, "oooo, a run!");
}
if (message=="Plaid!")
{
speed=75000;
llWhisper(0, "Ludicris Speed.");
}
//}
}
}