throw.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////
 
key agent = NULL_KEY;
 
default {
    attach(key id) {
        if(id == NULL_KEY) return;
        agent = id;
        llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION);
    }
    run_time_permissions(integer perm) {
        if((perm & PERMISSION_TAKE_CONTROLS == 0) || (perm & PERMISSION_TRIGGER_ANIMATION) == 0) return;
        llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
    }
    control(key id, integer level, integer edge) {
        if((level & CONTROL_ML_LBUTTON) && (edge & CONTROL_ML_LBUTTON)) {
            llGetAndResetTime();
            return;
        }
        if(level & CONTROL_ML_LBUTTON || !(edge & CONTROL_ML_LBUTTON)) return;
        vector op = llList2Vector(llGetObjectDetails(agent, [OBJECT_POS]), 0);
        vector as = llGetAgentSize(agent);
        float f = llGetAndResetTime()*96;
        if(f > 50) f = 50;
        llStartAnimation("throw");
        llRezObject(llGetInventoryName(INVENTORY_OBJECT, 0), <1.108685, 0, as.z> + op, llRot2Fwd(llGetRootRotation()) * f, llGetRot(), 0); 
    }
}