User:Allen Kerensky/Myriad Lite/Myriad Compatible Trap-Preview6.lsl

From OpenSimulator

Jump to: navigation, search

Myriad_Compatible_Trap-Preview6.lsl

// Myriad_Compatible_Trap-Preview6.lsl
// Copyright (c) 2012 LANI GLOBAL SYSTEMS and Allen Kerensky (OSG/SL) All Rights Reserved.
// This work is dual-licensed under
// Creative Commons Attribution (CC BY) 3.0 Unported
// http://creativecommons.org/licenses/by/3.0/
// - or -
// Modified BSD License (3-clause)
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, 
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
// * Neither the name of Myriad Lite nor the names of its contributors may be
//   used to endorse or promote products derived from this software without
//   specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
// NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The Myriad RPG System was designed, written, and illustrated by Ashok Desai
// Myriad RPG System licensed under:
// Creative Commons Attribution (CC BY) 2.0 UK: England and Wales
// http://creativecommons.org/licenses/by/2.0/uk/
 
string  VERSION = "0.5.4"; // version number
string  VERDATE = "20120202"; // version date
 
// This trap causes Myriad damage if avatar touches or collides with it.
// Myriad config below this line
//==========================
integer MINDAMAGE = 1; // minimum allowed trap damage
integer MAXDAMAGE = 5; // maximum allowed trap damage
integer DAMAGE = 2; // default how much damage do you want this weapon to cause? can be overriden on rez!
string  CHAN_PREFIX = "0x"; // used to convert key to hexadecimal channel number
string  DIV = "|"; // divider between parts of Myriad API messages
integer CHANMYRIAD = -999; // channel to send Myriad RP events to
string  MYRIADTRAPNAME = "TRAP1"; //name of the trap
string  TOUCHMESSAGE = "do not touch this!"; // touch damage message sent to avi via IM direct
string  COLLISIONMESSAGE = "tried to trap you!"; //collision damage message sent to avi via IM direct
string  MYRIADMESSAGE = "tried to trap"; //RP attempted damage message sent via Myriad hud
string  SOUNDNAME = "zap"; // name of the sound to play when trap springs
string  HOVERTEXT = "TRAP"; //floating text
vector  HTEXTCOLOR = <1,0.0,0>; // <R,G,B> color of the hovertext
float   HTEXTALPHA = 0.5; //alpha level of the hovertext 
vector  PUSHPOWER = <200,200,200>; // vector to push the damaged avi away  
 
ATTACK(key victim,string victimname,string attackmessage) {
    llPlaySound(SOUNDNAME, 1.0); // play sound if touched
    llPushObject(victim,PUSHPOWER, ZERO_VECTOR, FALSE); // push avatar away if touch
    llInstantMessage(victim," sorry "+llDetectedName(0)+ ", "+attackmessage); //tell avi something  
    // calculate the dynamic channel of who/what we hit 
    integer dynchan = (integer)(CHAN_PREFIX+llGetSubString((string)llGetOwner(),0,6)); // owner of trap becomes attacker
    llRegionSay(dynchan,"CLOSECOMBAT"+DIV+(string)DAMAGE+DIV+(string)victim+DIV+(string)llGetOwner()+DIV+llGetObjectName()); //myriad damage regionsay
    llRegionSay(CHANMYRIAD,"RPEVENT"+DIV+MYRIADTRAPNAME+" "+MYRIADMESSAGE+" "+victimname+"!"); //myriad rp event regionsay
}
 
default {
    on_rez(integer rez_damage) { 
        if ( rez_damage >= MINDAMAGE && rez_damage <= MAXDAMAGE ) {
            DAMAGE = rez_damage; // allow rez param to override scripted in damage
        }
        llSetStatus(STATUS_PHANTOM, TRUE); // toggle phantom status
        llSleep(0.2); // sleep for a moment to give toggle a chance to settle
        llSetStatus(STATUS_PHANTOM, FALSE); // make sure trap is not phantom
    }
 
    state_entry() {
        llSetText(HOVERTEXT,HTEXTCOLOR,HTEXTALPHA); // set the hovertext
        llSetSitText("--"); // set the sit text
        llSetTouchText("BAD"); // set the touch text
    }
 
    touch_start(integer total_number) {
        while (total_number--) { // loop through all people who touched, not just first this frame
            ATTACK(llDetectedKey(total_number),llDetectedName(total_number),TOUCHMESSAGE);
        }
    }
 
     collision_start(integer total_number) {
        while (total_number--) { // loop through all people who touched, not just first this frame
            ATTACK(llDetectedKey(total_number),llDetectedName(total_number),COLLISIONMESSAGE);
        }
    }
}
Personal tools
General
About This Wiki