Talk:Quick Collar: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
Created page with "This is an edit of the original Quick Collar script. I've changed it so that when it's locked, it'll read the Master list notecard. I've also changed the leash/goto commands to o…"
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is an edit of the original Quick Collar script. I've changed it so that when it's locked, it'll read the Master list notecard. I've also changed the leash/goto commands to only seek out avatars instead of objects.
Allison Lynagh
  //////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////
  // [K] Kira Komarov - 2011, License: GPLv3              //
  // [K] Kira Komarov - 2011, License: GPLv3              //
Line 61: Line 57:
  //pragma inline
  //pragma inline
  moveTo(vector target, integer bb) {
  moveTo(vector target, integer bb) {
    llStopMoveToTarget();
    llStopMoveToTarget();
    llTargetRemove(_aMoveTarget);
    llTargetRemove(_aMoveTarget);
    vector pointTo = target - llGetPos();
    vector pointTo = target - llGetPos();
    llOwnerSay("@setrot:" + (string)llAtan2(pointTo.x, pointTo.y) + "=force");
    llOwnerSay("@setrot:" + (string)llAtan2(pointTo.x, pointTo.y) + "=force");
    _aMoveTarget = llTarget(target, 2 + bb);
    _aMoveTarget = llTarget(target, 2 + bb);
    llMoveToTarget(target, 2);
    llMoveToTarget(target, 2);
  }
  }
 
  //pragma inline
  //pragma inline
  stopMove() {
  stopMove() {
    llSensorRemove();
    llSensorRemove();
    llStopMoveToTarget();
    llStopMoveToTarget();
    llTargetRemove(_aMoveTarget);
    llTargetRemove(_aMoveTarget);
    _leashedKey = NULL_KEY;
    _leashedKey = NULL_KEY;
    llParticleSystem([]);
    llParticleSystem([]);
  }
  }
 
  default
  default
  {
  {
    state_entry() {
    state_entry() {
        if(_scanType == "clothes") {
        if(_scanType == "clothes") {
            _comHandle = llListen(_comChannel+1, "", _aMaster, "");
            _comHandle = llListen(_comChannel+1, "", _aMaster, "");
            return;
            return;
        }
        }
        if(_scanType == "attachments") {
        if(_scanType == "attachments") {
            _comHandle = llListen(_comChannel+2, "", _aMaster, "");
            _comHandle = llListen(_comChannel+2, "", _aMaster, "");
            return;
            return;
        }
        }
    }
    }
 
    on_rez(integer param) {
    on_rez(integer param) {
        llOwnerSay("@detach=n");
        llOwnerSay("@detach=n");
        readMasters();
        readMasters();
    }
    }
 
    sensor(integer num_detected) {
    sensor(integer num_detected) {
        llListenRemove(_comHandle);
        llListenRemove(_comHandle);
 
        _menuItems = [];
        _menuItems = [];
        _objectKeys = [];
        _objectKeys = [];
        _mItra = num_detected-1;
        _mItra = num_detected-1;
        do {
        do {
            _menuItems += llGetSubString(llDetectedName(_mItra), 0, 23);
            _menuItems += llGetSubString(llDetectedName(_mItra), 0, 23);
            _objectKeys += llDetectedKey(_mItra);
            _objectKeys += llDetectedKey(_mItra);
        } while(--_mItra>=0);
        } while(--_mItra>=0);
 
        _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
        _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
 
        if(_scanType == "sit") {
        if(_scanType == "sit") {
            _comHandle = llListen(_comChannel+3, "", _aMaster, "");
            _comHandle = llListen(_comChannel+3, "", _aMaster, "");
            llDialog(_aMaster, "Please select an object to sit the wearer on:\n", _cmList, _comChannel+3);
            llDialog(_aMaster, "Please select an object to sit the wearer on:\n", _cmList, _comChannel+3);
            return;
            return;
        }
        }
 
        if(_scanType == "go") {
        if(_scanType == "go") {
            _comHandle = llListen(_comChannel+4, "", _aMaster, "");
            _comHandle = llListen(_comChannel+4, "", _aMaster, "");
            llDialog(_aMaster, "Please select the destination to send the wearer to:\n", _cmList, _comChannel+4);
            llDialog(_aMaster, "Please select the destination to send the wearer to:\n", _cmList, _comChannel+4);
            return;
            return;
        }
        }
 
        if(_scanType == "leash") {
        if(_scanType == "leash") {
            _comHandle = llListen(_comChannel+5, "", _aMaster, "");
            _comHandle = llListen(_comChannel+5, "", _aMaster, "");
            llDialog(_aMaster, "Please select the avatar to leash the wearer to:\n", _cmList, _comChannel+5);
            llDialog(_aMaster, "Please select the avatar to leash the wearer to:\n", _cmList, _comChannel+5);
            return;
            return;
        }
        }
    }
    }
 
    at_target( integer tnum, vector targetpos, vector ourpos ) {
    at_target( integer tnum, vector targetpos, vector ourpos ) {
        if(tnum != _aMoveTarget) return;
        if(tnum != _aMoveTarget) return;
        llStopMoveToTarget();
        llStopMoveToTarget();
        vector pointTo = targetpos - llGetPos();
        vector pointTo = targetpos - llGetPos();
        llOwnerSay("@setrot:" + (string)llAtan2(pointTo.x, pointTo.y) + "=force");
        llOwnerSay("@setrot:" + (string)llAtan2(pointTo.x, pointTo.y) + "=force");
        llTargetRemove(_aMoveTarget);
        llTargetRemove(_aMoveTarget);
    }
    }
 
    run_time_permissions(integer perm)
    run_time_permissions(integer perm)
    {
    {
        if (perm & PERMISSION_TAKE_CONTROLS)
        if (perm & PERMISSION_TAKE_CONTROLS)
        {
        {
            llTakeControls(0, FALSE, FALSE);
            llTakeControls(0, FALSE, FALSE);
            llOwnerSay(llKey2Name(_aMaster) + " has made you stay.");
            llOwnerSay(llKey2Name(_aMaster) + " has made you stay.");
        }
        }
    }
    }
 
    listen(integer channel, string name, key id, string message) {
    listen(integer channel, string name, key id, string message) {
 
        if(message == "<= Back") {
          if(message == "<= Back") {
            _aMaster = id;
            _aMaster = id;
            llSetTimerEvent(60);
            llSetTimerEvent(60);
            llDialog(id, "Please browse the available items:\n", mBwd(), channel);
            llDialog(id, "Please browse the available items:\n", mBwd(), channel);
            return;
            return;
        }
        }
 
        if(message == "Next =>") {
        if(message == "Next =>") {
            _aMaster = id;
            _aMaster = id;
            llSetTimerEvent(60);
            llSetTimerEvent(60);
            llDialog(id, "Please browse the available items:\n", mFwd(), channel);
            llDialog(id, "Please browse the available items:\n", mFwd(), channel);
            return;
            return;
        }
        }
 
        if(message == "FFA: [✖]" || message == "FFA: [✔]") {
        if(message == "FFA: [✖]" || message == "FFA: [✔]") {
            llListenRemove(_comHandle);
            llListenRemove(_comHandle);
            if(_FFA == "FFA: [✖]") {
            if(_FFA == "FFA: [✖]") {
                _FFA = "FFA: [✔]";
                _FFA = "FFA: [✔]";
                return;
                return;
            }
            }
            if(_FFA == "FFA: [✔]") {
            if(_FFA == "FFA: [✔]") {
                _FFA = "FFA: [✖]";
                _FFA = "FFA: [✖]";
                return;
                return;
            }
            }
        }
        }
 
        if(message == "LOCK: [✖]" || message == "LOCK: [✔]") {
        if(message == "LOCK: [✖]" || message == "LOCK: [✔]") {
            llListenRemove(_comHandle);
            llListenRemove(_comHandle);
            if(_LOCK == "LOCK: [✖]") {
            if(_LOCK == "LOCK: [✖]") {
                llOwnerSay("@detach=n");
                llOwnerSay("@detach=n");
                llOwnerSay("@accepttp:+(string) _aMaster=add");
                llOwnerSay("@accepttp:+(string) _aMaster=add");  
       
                _LOCK = "LOCK: [✔]";
   
                return;
                _LOCK = "LOCK: [✔]";
            }
                return;
 
            }
                if(_LOCK == "LOCK: [✔]") {
            if(_LOCK == "LOCK: [✔]") {
                 llOwnerSay("@detach=y");
                 llOwnerSay("@detach=y");
                llOwnerSay("@accepttp:+(string) _aMaster=rem");
                llOwnerSay("@accepttp:+(string) _aMaster=rem");
                _LOCK = "LOCK: [✖]";
                _LOCK = "LOCK: [✖]";
                return;
                return;
            }
            }
        }
        }
 
        if(message == "[ Sits ]" ) {
        if(message == "[ Sits ]" ) {
            _aMaster = id;
            _aMaster = id;
            llSetTimerEvent(60);
            llSetTimerEvent(60);
            llDialog(id, "Please select whether to sit or unsit:\n", ["Sit", "Unsit"], _comChannel);
            llDialog(id, "Please select whether to sit or unsit:\n", ["Sit", "Unsit"], _comChannel);
            return;
            return;
        }
        }
 
        if(message == "Unsit") {
        if(message == "Unsit") {
            llListenRemove(_comHandle);
            llListenRemove(_comHandle);
            llOwnerSay("@unsit=force");
            llOwnerSay("@unsit=force");
            return;
            return;
        }
        }
 
        if(message == "Sit") {
        if(message == "Sit") {
            llListenRemove(_comHandle);
            llListenRemove(_comHandle);
            llInstantMessage(id, "Scanning for nearby objects, please wait...");
            llInstantMessage(id, "Scanning for nearby objects, please wait...");
            _aMaster = id;
            _aMaster = id;
            _scanType = "sit";
            _scanType = "sit";
            llSensor("", "", (PASSIVE | ACTIVE), 10.0, PI);
            llSensor("", "", (ACTIVE), 5.0, PI);
            return;         
            return;         
        }
        }
 
        if(message == "[ Moves ]") {
        if(message == "[ Moves ]") {
            _aMaster = id;
              _aMaster = id;
            llSetTimerEvent(60);
            llSetTimerEvent(60);
            llDialog(id, "Please select the desired movement:\n", ["Go To", "Stay", "UnStay"], _comChannel);
            llDialog(id, "Please select the desired movement:\n", ["Go To", "Stay", "UnStay"], _comChannel);
            return;
              return;
        }
        }
 
        if(message == "UnStay") {
          if(message == "UnStay") {
            llListenRemove(_comHandle);
            llListenRemove(_comHandle);
            llReleaseControls();
            llReleaseControls();
            llOwnerSay(llKey2Name(id) + " has allowed you to move freely...");
              llOwnerSay(llKey2Name(id) + " has allowed you to move freely...");
            return;
            return;
        }
        }
 
         if(message == "Stay") {
         if(message == "Stay") {
             llListenRemove(_comHandle);
             llListenRemove(_comHandle);
Line 271: Line 266:
         if(message == "Leash" ) {
         if(message == "Leash" ) {
             llListenRemove(_comHandle);
             llListenRemove(_comHandle);
             llInstantMessage(id, "Scanning for nearby objects, please wait...");
             llInstantMessage(id, "Scanning for nearby avatars, please wait...");
             _aMaster = id;
             _aMaster = id;
             _scanType = "leash";
             _scanType = "leash";
Line 309: Line 304:
             return;
             return;
  @rlvsit;
  @rlvsit;
             llOwnerSay("@sit:" + llList2String(_objectKeys, idx) + "=force");
             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;
             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;
  @rlvmove;
            llParticleSystem([]);
            llParticleSystem([]);
            llSensorRemove();
            llSensorRemove();
            _leashedKey = NULL_KEY;
            _leashedKey = NULL_KEY;
            vector target = llList2Vector(llGetObjectDetails(llList2String(_objectKeys, idx), [OBJECT_POS]), 0);
            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);
              integer bb = (integer)(llVecDist(llList2Vector(llGetBoundingBox(llList2String(_objectKeys, idx)), 1), llList2Vector(llGetBoundingBox(llList2String(_objectKeys, idx)), 0))/2.0);
            moveTo(target, bb);
            moveTo(target, bb);
            return;
            return;
        }
        }
 
        if(channel == _comChannel + 5 && message != "Next =>" && message != "<= Back") {
        if(channel == _comChannel + 5 && message != "Next =>" && message != "<= Back") {
            llListenRemove(_comHandle);
            llListenRemove(_comHandle);
            integer idx = llGetListLength(_menuItems)-1;
            integer idx = llGetListLength(_menuItems)-1;
            do {
            do {
                if(~llSubStringIndex(llList2String(_menuItems, idx), message))
                if(~llSubStringIndex(llList2String(_menuItems, idx), message))
                jump rlvleash;
                jump rlvleash;
            } while(--idx>=0);
              } while(--idx>=0);
            return;
            return;
  @rlvleash;
  @rlvleash;
            _leashedKey = llList2Key(_objectKeys, idx);
            _leashedKey = llList2Key(_objectKeys, idx);
            llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0, 1.2-llGetRegionTimeDilation());
            llSensorRepeat("", NULL_KEY, AGENT, 0.1, 0, 1.2-llGetRegionTimeDilation());
            llParticleSystem([12,"0560a0ad-ee6e-9a87-6a27-9322bad689ce",5,<3.0e-2,3.0e-2,3.0e-2>,6,<5.0e-2,5.0e-2,5.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]);
            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() {
    no_sensor() {
        if(_leashedKey) {
        if(_leashedKey) {
            vector target = llList2Vector(llGetObjectDetails(_leashedKey, [OBJECT_POS]), 0);
            vector target = llList2Vector(llGetObjectDetails(_leashedKey, [OBJECT_POS]), 0);
            integer distance = (integer)llVecDist(target, llGetPos());
            integer distance = (integer)llVecDist(target, llGetPos());
            if(distance > 5 && distance < 65) {
            if(distance > 5 && distance < 65) {
                integer bb = (integer)(llVecDist(llList2Vector(llGetBoundingBox(_leashedKey), 1), llList2Vector(llGetBoundingBox(_leashedKey), 0))/2.0);
                integer bb = (integer)(llVecDist(llList2Vector(llGetBoundingBox(_leashedKey), 1), llList2Vector(llGetBoundingBox(_leashedKey), 0))/2.0);
                moveTo(target, bb);
                moveTo(target, bb);
                return;
                return;
            }
            }
            if(distance >= 65) {
            if(distance >= 65) {
                stopMove();
                stopMove();
                return;
                  return;
            }
            }
        }
          }
    }
    }
 
      timer() {
        llSetTimerEvent(0);
          llInstantMessage(_aMaster, "Menu timed out...");
        _aMaster = NULL_KEY;
        llListenRemove(_comHandle);
      }
   
   
    timer() {
      touch_start(integer total_number)
        llSetTimerEvent(0);
    {
        llInstantMessage(_aMaster, "Menu timed out...");
        //if((llDetectedKey(0) != llGetOwner() && llListFindList(_mList, (list)llDetectedName(0)) == -1) || _FFA != "FFA: [✔]") return;
        _aMaster = NULL_KEY;
          _comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        llListenRemove(_comHandle);
        _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);
     }
     }
   
   
    touch_start(integer total_number)
    changed(integer change) {
    {
        if(change & CHANGED_INVENTORY) {
        //if((llDetectedKey(0) != llGetOwner() && llListFindList(_mList, (list)llDetectedName(0)) == -1) || _FFA != "FFA: [✔]") return;
            readMasters();
        _comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
            return;
        _aMaster = llDetectedKey(0);
        }
        _comHandle = llListen(_comChannel, llDetectedName(0), _aMaster, "");
        if(change & CHANGED_REGION) {
        llSetTimerEvent(60);
            stopMove();
        llDialog(_aMaster, "Please select from the following options:\n\nClothes - will offer a menu for stripping the wearer of the collar.\nSits - will allow you to sit the wearer of the collar on objects.\nMoves - will enable you to move the wearer of the collar around.\nLeash - will offer a menu to leash the wearer to an object or avatar.\n\nFFA - if this is on, it will allow other people to use the collar menu.\nLOCK - will make sure that the collar cannot be detached (for example, for outfit changes).", ["[ Clothes ]", "[ Sits ]", "[ Moves ]", "[ Leash ]", _FFA, _LOCK], _comChannel);
              return;
    }
        }
      }
    changed(integer change) {
 
        if(change & CHANGED_INVENTORY) {
    dataserver(key query_id, string data) {
            readMasters();
          if(query_id != _aMaster) return;
            return;
          if(data == EOF) {
        }
              llOwnerSay("Masters notecard loaded...");
        if(change & CHANGED_REGION) {
              return;
            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;
         if(data == "") jump continue;
         _mList += (list) data;
         _mList += (list) data;
  @continue;
  @continue;
        _aMaster = llGetNotecardLine("Masters", ++_comHandle);
        _aMaster = llGetNotecardLine("Masters", ++_comHandle);
    }
    }
  }
  }
 
  state show_wearables
  state show_wearables
  {
  {
    state_entry() {
    state_entry() {
        _mItra = 1+FPSrand(99);
        _mItra = 1+FPSrand(99);
        llListen(_mItra, "", llGetOwner(), "");
        llListen(_mItra, "", llGetOwner(), "");
        llOwnerSay("@getoutfit=" + (string)_mItra);
        llOwnerSay("@getoutfit=" + (string)_mItra);
    }
    }
    listen(integer channel,string name,key id,string message) {
    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" ];
        list CLOTHES = [ "gloves","jacket","pants","shirt","shoes","skirt","socks","underpants","undershirt","skin","eyes","hair","shape", "alpha", "tattoo", "physics" ];  
         _menuItems = [];
         _menuItems = [];
        _mItra = llStringLength(message)-1;
        _mItra = llStringLength(message)-1;
        do {
        do {
            if((integer)llGetSubString(message, _mItra, _mItra))
            if((integer)llGetSubString(message, _mItra, _mItra))
                _menuItems += llList2String(CLOTHES, _mItra);
                _menuItems += llList2String(CLOTHES, _mItra);
        } while(--_mItra>=0);
        } while(--_mItra>=0);
        CLOTHES = [];
        CLOTHES = [];
        _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
        _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
        _scanType = "clothes";
        _scanType = "clothes";
        llDialog(_aMaster, "Please select the clothes to take off:\n", _cmList, _comChannel+1);
        llDialog(_aMaster, "Please select the clothes to take off:\n", _cmList, _comChannel+1);
        state default;
        state default;
    }
    }
  }
  }
 
  state show_attachments
  state show_attachments
  {
  {
    state_entry() {
    state_entry() {
        _mItra = 1+FPSrand(99);
        _mItra = 1+FPSrand(99);
        llListen(_mItra, "", llGetOwner(), "");
        llListen(_mItra, "", llGetOwner(), "");
        llOwnerSay("@getattach=" + (string)_mItra);
        llOwnerSay("@getattach=" + (string)_mItra);
    }
    }
    listen(integer channel,string name,key id,string message) {
    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" ];
        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 = [];
        _menuItems = [];
        _mItra = llStringLength(message)-1;
        _mItra = llStringLength(message)-1;
        do {
        do {
            if((integer)llGetSubString(message, _mItra, _mItra))
            if((integer)llGetSubString(message, _mItra, _mItra))
                _menuItems += llList2String(ATTACHMENTS, _mItra);
                _menuItems += llList2String(ATTACHMENTS, _mItra);
        } while(--_mItra>=0);
        } while(--_mItra>=0);
        ATTACHMENTS = [];
        ATTACHMENTS = [];
        _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
          _cmList = llListInsertList(llListInsertList(llList2List(_menuItems, _mItra=0, (_mItra+=9)), ["<= Back"], 0), ["Next =>"], 2);
         _scanType = "attachments";
         _scanType = "attachments";  
         llDialog(_aMaster, "Please select the attachments to detach:\n", _cmList, _comChannel+2);
         llDialog(_aMaster, "Please select the attachments to detach:\n", _cmList, _comChannel+2);  
         state default;
         state default;
    }
    }
  }
  }

Latest revision as of 13:00, 3 July 2013

//////////////////////////////////////////////////////////
// [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;
    }
}