pgs_prey_collider.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////
 
// Reference land types
list _landReference = [ "Green", 1, "Black", 2, "Brown", 3 ];
// Reference genomes
list _genotypeReference = [ "BB", 1, "Bb", 2, "bB", 3, "bb", 4 ];
 
string _landType = "";
string _genome = "";
integer _mouseID = 1;
 
// Owner key.
key _owner = NULL_KEY;
 
setparams(integer param) {
    list opt = llParseString2List(llGetSubString((string)param, 0, 4), [], [ "1", "2", "3", "4", "5", "6" ]);
    integer itra=llGetListLength(opt)-1;
    do {
        if(llList2Integer(opt, itra) == 5) {
            _genome = llList2String(_genotypeReference, llListFindList(_genotypeReference, (list)llList2Integer(opt, itra+1))-1);
            jump next_param;
        }
        if(llList2Integer(opt, itra) == 6) {
            _landType = llList2String(_landReference, llListFindList(_landReference, (list)llList2Integer(opt, itra+1))-1);
            jump next_param;
        }
@next_param;
    } while(--itra>=0);
    list id = llParseString2List(llGetSubString((string)param, 5, -1), [], ["1", "2", "3", "4", "5", "6", "7", "8", "9" ]);
    _mouseID = (integer)llDumpList2String(id, "");
}
 
default
{
    state_entry()
    {
        llSetTimerEvent(1);
    }
    changed(integer change) {
        if(change & CHANGED_OWNER) _owner = llGetOwner();
    }
    on_rez(integer num) {
        _owner = llGetOwner();
        setparams(num);
    }
    timer() {
        if(_landType != "" && _genome != "") {
            llSetTimerEvent(0);
            state life;
        }
    }
}
 
state life
{
    state_entry() {
        llPreloadSound("1f4d6484-5566-d004-e419-2711f0f151a2");
        llMinEventDelay(1);
        llVolumeDetect(TRUE);
        llCollisionFilter("[K] Robin", "", TRUE);
    }
    collision_end(integer num) {
        float rnd = llFrand(1);
        if((_landType == "Green" || _landType == "Brown") && rnd < 0.8) state death;
        if(_landType == "Black" && rnd < 0.2) state death;
    }
    changed(integer change) {
        if(change & CHANGED_OWNER) llResetScript();
    }
    on_rez(integer num) {
        llResetScript();
    }
}
 
state death
{
    state_entry() {
            integer comChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
            llRegionSay(comChannel+3, "BLK_DEATH:" + (string)_mouseID + ",GENOME:" + _genome);
            llParticleSystem([  // start of particle settings
           // Texture Parameters:
           PSYS_SRC_TEXTURE, llGetInventoryName(INVENTORY_TEXTURE, 0), 
           PSYS_PART_START_SCALE, <0.5, 1.0, FALSE>, PSYS_PART_END_SCALE, <1.0, 0.5, FALSE>, 
           PSYS_PART_START_COLOR, <0.4,0.4,0.4>,    PSYS_PART_END_COLOR, <0.5,0.5,0.5>, 
           PSYS_PART_START_ALPHA,  (float)0.5,            PSYS_PART_END_ALPHA, (float)0.1,   
 
           // Production Parameters:
           PSYS_SRC_BURST_PART_COUNT, (integer)2, 
           PSYS_SRC_BURST_RATE, (float) 0.06,  
           PSYS_PART_MAX_AGE, (float)1.0, 
           PSYS_SRC_MAX_AGE,(float) 0.0,  
 
           // Placement Parameters:
           PSYS_SRC_PATTERN, (integer)2, // 1=DROP, 2=EXPLODE, 4=ANGLE, 8=ANGLE_CONE,
 
           // Placement Parameters (for any non-DROP pattern):
           PSYS_SRC_BURST_SPEED_MIN, (float)1.0,   PSYS_SRC_BURST_SPEED_MAX, (float)3.0, 
        // PSYS_SRC_BURST_RADIUS, 0.0,
 
           // Placement Parameters (only for ANGLE & CONE patterns):
           PSYS_SRC_ANGLE_BEGIN, (float) 0.03*PI,    PSYS_SRC_ANGLE_END, (float)0*PI,  
        // PSYS_SRC_OMEGA, <0,0,0>, 
 
           // After-Effect & Influence Parameters:
           PSYS_SRC_ACCEL, <0.0,0.0, - 2.0 >,  
        // PSYS_SRC_TARGET_KEY,      llGetLinkKey(llGetLinkNumber() + 1),       
 
           PSYS_PART_FLAGS, (integer)( 0         // Texture Options:     
                                | PSYS_PART_INTERP_COLOR_MASK   
                                | PSYS_PART_INTERP_SCALE_MASK   
                            //  | PSYS_PART_EMISSIVE_MASK   
                                | PSYS_PART_FOLLOW_VELOCITY_MASK
                                                  // After-effect & Influence Options:
                                | PSYS_PART_WIND_MASK            
                                | PSYS_PART_BOUNCE_MASK          
                             // | PSYS_PART_FOLLOW_SRC_MASK     
                             // | PSYS_PART_TARGET_POS_MASK     
                             // | PSYS_PART_TARGET_LINEAR_MASK   
                            ) 
            //end of particle settings                     
        ]);
        llPlaySound("1f4d6484-5566-d004-e419-2711f0f151a2", 1.0);
        llSetTimerEvent(5);
 
    }
    timer() {
        llSetTimerEvent(0);
        llDie();
        return;
    }
    changed(integer change) {
        if(change & CHANGED_OWNER) llResetScript();
    }
    on_rez(integer num) {
        llResetScript();
    }
}