// © 2008 by Karzita Zabaleta
// Author of Scripting Your World, Wiley, October 2008.
list gMaterialTypes = [
"STONE",
"METAL",
"GLASS",
"WOOD",
"FLESH",
"PLASTIC",
"RUBBER"
];
vector gHomePosition;
rotation gHomeRotation;
integer gWaitCount = 0;
float gMaxVelMag;
integer gPrimMaterial;
moveTo(vector origin, vector destination) {
float dist = llVecDist(origin, destination);
integer passes = llCeil( llLog(dist/10.0) / llLog(2.0) );
integer i;
list params = [PRIM_POSITION, destination];
for (i=0; i<passes; i++) {
params = (params=[]) + params + params;
}
// actually move the prim, now
llSetPrimitiveParams(params);
}
returnHome()
{
llSetStatus(STATUS_PHYSICS, FALSE);
moveTo(llGetPos(),gHomePosition);
llSetTimerEvent(0);
llSetRot(gHomeRotation);
}
calculate_velocity()
{
float velMag = llVecMag(llGetVel());
if (velMag > gMaxVelMag) {
gMaxVelMag = velMag;
}
}
default
{
state_entry() {
gHomePosition = llGetPos();
gHomeRotation = llGetRot();
}
on_rez(integer _n) {
llResetScript();
}
touch_start(integer n) {
gMaxVelMag = 0;
llSetPrimitiveParams([PRIM_MATERIAL, gPrimMaterial]);
llSetStatus(STATUS_PHYSICS,TRUE);
llSetTimerEvent(0.1);
llResetTime();
gWaitCount=0;
gPrimMaterial++;
if (gPrimMaterial == 7 ) gPrimMaterial = 0;
}
timer() {
calculate_velocity();
gWaitCount++;
if (gWaitCount > 100) { // 10 seconds
string type = llList2String( gMaterialTypes, gPrimMaterial-1 );
llOwnerSay(type+" reached maximum velocity of "+(string)gMaxVelMag+
" and traveled "+(string)llVecDist(llGetPos(), gHomePosition)+" meters.");
returnHome();
}
}
}