Talk:Quick Collar

From Second Life Wiki
Jump to navigation Jump to search
//////////////////////////////////////////////////////////
// [K] Kira Komarov - 2011, License: GPLv3              //
// Please see: http://www.gnu.org/licenses/gpl.html     //
// for legal details, rights of fair usage and          //
// the disclaimer and warranty conditions.              //
// Edited by: Allison Lynagh                            //
//////////////////////////////////////////////////////////
 
list _menuItems = [];
list _objectKeys = [];
list _mList = [];
key _aMaster = NULL_KEY;
integer _aMoveTarget = 0;
string _scanType = "";
string _FFA = "FFA: [✖]";
string _LOCK = "LOCK: [✔]";
key _leashedKey = NULL_KEY;
integer _mItra = 0;
integer _comChannel = 0;
integer _comHandle = 0;
list _cmList = [];
 
list mFwd() {
    if(_mItra+1>llGetListLength(_menuItems) || llGetListLength(_menuItems)==10) return _cmList;
    _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, ++_mItra, (_mItra+=9)), 
      ["<= Back"], 0), ["Next =>"], 2);
    return _cmList;
} 
 
list mBwd() {
    if(_mItra-19<0) return _cmList;
    _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, (_mItra-=19), (_mItra+=9)), 
      ["<= Back"], 0), ["Next =>"], 2);
    return _cmList;
}
 
//pragma inline
integer FPSrand(integer max) {
    integer r = (integer)(llGetRegionFPS() * 10000000.0) % max;
    if(max > 0) return r; else return -r;
}
 
//pragma inline
readMasters() {
    _mList = [];
    _mItra = llGetInventoryNumber(INVENTORY_NOTECARD)-1;
    do {
        if(llGetInventoryName(INVENTORY_NOTECARD, _mItra) == "Masters")
            jump found;
    } while(--_mItra>=0);
    llOwnerSay("No Masters notecard found, skipping...");
    return;
@found;
    _aMaster = llGetNotecardLine("Masters", _comHandle);
}
 
//pragma inline
moveTo(vector target, integer bb) {
    llStopMoveToTarget();
    llTargetRemove(_aMoveTarget);
    vector pointTo = target - llGetPos();
    llOwnerSay("@setrot:" + (string)llAtan2(pointTo.x, pointTo.y) + "=force");
    _aMoveTarget = llTarget(target, 2 + bb);
    llMoveToTarget(target, 2);
}
 
//pragma inline
stopMove() {
    llSensorRemove();
    llStopMoveToTarget();
    llTargetRemove(_aMoveTarget);
    _leashedKey = NULL_KEY;
    llParticleSystem([]);
}
 
default
{
    state_entry() {
        if(_scanType == "clothes") {
            _comHandle = llListen(_comChannel+1, "", _aMaster, "");
            return;
        }
        if(_scanType == "attachments") {
            _comHandle = llListen(_comChannel+2, "", _aMaster, "");
            return;
        }
    }
 
    on_rez(integer param) {
        llOwnerSay("@detach=n");
        readMasters();
    }
 
    sensor(integer num_detected) {
        llListenRemove(_comHandle);
 
        _menuItems = [];
        _objectKeys = [];
        _mItra = num_detected-1;
        do {
            _menuItems += llGetSubString(llDetectedName(_mItra), 0, 23);
            _objectKeys += llDetectedKey(_mItra);
        } while(--_mItra>=0);
 
        _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
 
        if(_scanType == "sit") {
            _comHandle = llListen(_comChannel+3, "", _aMaster, "");
            llDialog(_aMaster, "Please select an object to sit the wearer on:\n", _cmList, _comChannel+3);
            return;
        }
 
        if(_scanType == "go") {
            _comHandle = llListen(_comChannel+4, "", _aMaster, "");
            llDialog(_aMaster, "Please select the destination to send the wearer to:\n", _cmList, _comChannel+4);
            return;
        }
 
        if(_scanType == "leash") {
            _comHandle = llListen(_comChannel+5, "", _aMaster, "");
            llDialog(_aMaster, "Please select the avatar to leash the wearer to:\n", _cmList, _comChannel+5);
            return;
        }
    }
 
    at_target( integer tnum, vector targetpos, vector ourpos ) {
        if(tnum != _aMoveTarget) return;
        llStopMoveToTarget();
        vector pointTo = targetpos - llGetPos();
        llOwnerSay("@setrot:" + (string)llAtan2(pointTo.x, pointTo.y) + "=force");
        llTargetRemove(_aMoveTarget);
    }
 
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(0, FALSE, FALSE);
            llOwnerSay(llKey2Name(_aMaster) + " has made you stay.");
        }
    }
 
    listen(integer channel, string name, key id, string message) {
 
         if(message == "<= Back") {
            _aMaster = id;
            llSetTimerEvent(60);
            llDialog(id, "Please browse the available items:\n", mBwd(), channel);
            return;
        }
 
        if(message == "Next =>") {
            _aMaster = id;
            llSetTimerEvent(60);
            llDialog(id, "Please browse the available items:\n", mFwd(), channel);
            return;
        }
 
        if(message == "FFA: [✖]" || message == "FFA: [✔]") {
            llListenRemove(_comHandle);
            if(_FFA == "FFA: [✖]") {
                _FFA = "FFA: [✔]";
                return;
            }
            if(_FFA == "FFA: [✔]") {
                _FFA = "FFA: [✖]";
                return;
            }
        }
 
        if(message == "LOCK: [✖]" || message == "LOCK: [✔]") {
            llListenRemove(_comHandle);
            if(_LOCK == "LOCK: [✖]") {
                llOwnerSay("@detach=n");
                llOwnerSay("@accepttp:+(string) _aMaster=add");   
                _LOCK = "LOCK: [✔]";
                return;
            }  
               if(_LOCK == "LOCK: [✔]") {
               llOwnerSay("@detach=y");
                llOwnerSay("@accepttp:+(string) _aMaster=rem");
                _LOCK = "LOCK: [✖]";
                return;
            }
        }
 
        if(message == "[ Sits ]" ) {
            _aMaster = id;
            llSetTimerEvent(60);
            llDialog(id, "Please select whether to sit or unsit:\n", ["Sit", "Unsit"], _comChannel);
            return;
        }
 
        if(message == "Unsit") {
            llListenRemove(_comHandle);
            llOwnerSay("@unsit=force");
            return;
        }
 
        if(message == "Sit") {
            llListenRemove(_comHandle);
            llInstantMessage(id, "Scanning for nearby objects, please wait...");
            _aMaster = id;
            _scanType = "sit";
            llSensor("", "", (ACTIVE), 5.0, PI);
            return;        
        }
 
        if(message == "[ Moves ]") {
             _aMaster = id;
            llSetTimerEvent(60);
            llDialog(id, "Please select the desired movement:\n", ["Go To", "Stay", "UnStay"], _comChannel);
             return;
        }
 
         if(message == "UnStay") {
            llListenRemove(_comHandle);
            llReleaseControls();
             llOwnerSay(llKey2Name(id) + " has allowed you to move freely...");
            return;
        }
 
       if(message == "Stay") {
           llListenRemove(_comHandle);
           _aMaster = id;
           llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
           return;
       }

       if(message == "Go To") {
           llListenRemove(_comHandle);
           llInstantMessage(id, "Scanning for nearby targets, please wait...");
           _aMaster = id;
           _scanType = "go";
           llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, 10.0, PI);
           return;
       }

       if(message == "[ Clothes ]" ) {
           _aMaster = id;
           llSetTimerEvent(60);
           llDialog(id, "Please select the type of clothing to remove:\n", ["Wearables", "Attachments"], _comChannel);
           return;
       }

       if(message == "Wearables") {
           _aMaster = id;
           state show_wearables;
           return;
       }

       if(message == "Attachments") {
           _aMaster = id;
           state show_attachments;
           return;
       }

       if(message == "[ Leash ]" ) {
           _aMaster = id;
           llSetTimerEvent(60);
           llDialog(id, "Please select whether to leash or unleash the wearer:\n", ["Leash", "Unleash"], _comChannel);
           return;
       }

       if(message == "Leash" ) {
           llListenRemove(_comHandle);
           llInstantMessage(id, "Scanning for nearby avatars, please wait...");
           _aMaster = id;
           _scanType = "leash";
           llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, 10.0, PI);
           return;    
       }

       if(message == "Unleash" ) {
           llListenRemove(_comHandle);
           llSensorRemove();
           llStopMoveToTarget();
           llTargetRemove(_aMoveTarget);
           _leashedKey = NULL_KEY;
           llParticleSystem([]);
           return;    
       }

       if(channel == _comChannel + 1 && message != "Next =>" && message != "<= Back") {
           llListenRemove(_comHandle);
           llOwnerSay("@remoutfit:" + message + "=force");
           return;
       }

       if(channel == _comChannel + 2 && message != "Next =>" && message != "<= Back") {
           llListenRemove(_comHandle);
           llOwnerSay("@detach:" + message + "=force");
           return;
       }

       if(channel == _comChannel + 3 && message != "Next =>" && message != "<= Back") {
           llListenRemove(_comHandle);
           integer idx = llGetListLength(_menuItems)-1;
           do {
               if(~llSubStringIndex(llList2String(_menuItems, idx), message))
               jump rlvsit;
           } while(--idx>=0);
           return;
@rlvsit;
           llOwnerSay("@sit:" + llList2String(_objectKeys, idx) + "=force"); 
           return;
        }
 
        if(channel == _comChannel + 4 && message != "Next =>" && message != "<= Back") {
            llListenRemove(_comHandle);
            integer idx = llGetListLength(_menuItems)-1;
            do {
                if(~llSubStringIndex(llList2String(_menuItems, idx), message))
                jump rlvmove;
            } while(--idx>=0);
            return;
@rlvmove;
            llParticleSystem([]);
            llSensorRemove();
            _leashedKey = NULL_KEY;
            vector target = llList2Vector(llGetObjectDetails(llList2String(_objectKeys, idx), [OBJECT_POS]), 0);
             integer bb = (integer)(llVecDist(llList2Vector(llGetBoundingBox(llList2String(_objectKeys, idx)), 1),  llList2Vector(llGetBoundingBox(llList2String(_objectKeys, idx)), 0))/2.0);
            moveTo(target, bb);
            return;
        }
 
        if(channel == _comChannel + 5 && message != "Next =>" && message != "<= Back") {
            llListenRemove(_comHandle);
            integer idx = llGetListLength(_menuItems)-1;
            do {
                if(~llSubStringIndex(llList2String(_menuItems, idx), message))
                jump rlvleash;
             } while(--idx>=0);
            return;
@rlvleash;
            _leashedKey = llList2Key(_objectKeys, idx);
            llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0, 1.2-llGetRegionTimeDilation());
            llParticleSystem([12,"245ea72d-bc79-fee3-a802-8e73c0f09473",5,<10.0e-2,10.0e-2,10.0e-2>,6,<10.0e-2,10.0e-2,10.0e-2>,1,<1.0,1.0,1.0>,3,<1.0,1.0,1.0>,2,((float)1.0),4,((float)1.0),15,((integer)10),13,((float)1.0e-3),7,((float)10.0),9,((integer)1),8,<0.0,0.0,-0.1>,0,((integer)355),20,_leashedKey]);
       }
   }

    no_sensor() {
        if(_leashedKey) {
            vector target = llList2Vector(llGetObjectDetails(_leashedKey, [OBJECT_POS]), 0);
            integer distance = (integer)llVecDist(target, llGetPos());
            if(distance > 5 && distance < 65) {
                integer bb = (integer)(llVecDist(llList2Vector(llGetBoundingBox(_leashedKey), 1), llList2Vector(llGetBoundingBox(_leashedKey),  0))/2.0);
                moveTo(target, bb);
                return;
            }
            if(distance >= 65) {
                stopMove();
                 return;
            }
         }
    }
 
     timer() {
        llSetTimerEvent(0);
         llInstantMessage(_aMaster, "Menu timed out...");
        _aMaster = NULL_KEY;
        llListenRemove(_comHandle);
     }

     touch_start(integer total_number)
    {
        //if((llDetectedKey(0) != llGetOwner() && llListFindList(_mList, (list)llDetectedName(0)) == -1) || _FFA != "FFA: [✔]") return;
         _comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        _aMaster = llDetectedKey(0);
        _comHandle = llListen(_comChannel, llDetectedName(0), _aMaster, "");
         llSetTimerEvent(60);
         llDialog(_aMaster, "Please select from the following options:\n\nClothes - will offer a menu for stripping the wearer. \nSits - will allow you to sit the wearer on objects.\nMoves - will enable you to move the wearer around.\nLeash - will offer a menu to leash the wearer to an avatar.\n\nFFA - if this is on, it will allow other people to use the collar menu.\nLOCK - locks the collar on.", ["[ Clothes ]", "[ Sits ]", "[ Moves ]", "[ Leash ]", _FFA, _LOCK], _comChannel);
   }

    changed(integer change) {
        if(change & CHANGED_INVENTORY) {
            readMasters();
            return;
        }
        if(change & CHANGED_REGION) {
            stopMove();
             return;
        }
     }
 
    dataserver(key query_id, string data) {
         if(query_id != _aMaster) return;
         if(data == EOF) {
             llOwnerSay("Masters notecard loaded...");
             return;
       }
       if(data == "") jump continue;
       _mList += (list) data;
@continue;
        _aMaster = llGetNotecardLine("Masters", ++_comHandle);
    }
}
 
state show_wearables
{
    state_entry() {
        _mItra = 1+FPSrand(99);
        llListen(_mItra, "", llGetOwner(), "");
        llOwnerSay("@getoutfit=" + (string)_mItra);
    }
    listen(integer channel,string name,key id,string message) {
        list CLOTHES = [ "gloves","jacket","pants","shirt","shoes","skirt","socks","underpants","undershirt","skin","eyes","hair","shape",  "alpha", "tattoo", "physics" ]; 
       _menuItems = [];
        _mItra = llStringLength(message)-1;
        do {
            if((integer)llGetSubString(message, _mItra, _mItra))
                _menuItems += llList2String(CLOTHES, _mItra);
        } while(--_mItra>=0);
        CLOTHES = [];
        _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
        _scanType = "clothes";
        llDialog(_aMaster, "Please select the clothes to take off:\n", _cmList, _comChannel+1);
        state default;
    }
}
 
state show_attachments
{
    state_entry() {
        _mItra = 1+FPSrand(99);
        llListen(_mItra, "", llGetOwner(), "");
        llOwnerSay("@getattach=" + (string)_mItra);
    }
    listen(integer channel,string name,key id,string message) {
        list ATTACHMENTS = [ "none","chest","skull","left shoulder","right shoulder","left hand","right hand","left foot","right foot","spine","pelvis","mouth","chin","left ear","right ear","left eyeball","right eyeball","nose","r upper arm","r forearm","l upper arm","l forearm","right hip","r upper leg","r lower leg","left hip","l upper leg","l lower leg","stomach","left pec","right pec","center 2","top right","top","top left","center","bottom left","bottom","bottom right" ];
        _menuItems = [];
        _mItra = llStringLength(message)-1;
        do {
            if((integer)llGetSubString(message, _mItra, _mItra))
                _menuItems += llList2String(ATTACHMENTS, _mItra);
        } while(--_mItra>=0);
        ATTACHMENTS = [];
         _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
       _scanType = "attachments"; 
       llDialog(_aMaster, "Please select the attachments to detach:\n", _cmList, _comChannel+2); 
       state default;
    }
}