Attach/Detach attachments by touch using RLV - SLUniverse Forums
Navigation » SLUniverse Forums > Development Discussion and Support > Scripting > Script Library » Attach/Detach attachments by touch using RLV


Script Library Post useful scripts here.

Reply
 
LinkBack Thread Tools Display Modes
Old 06-13-2018, 11:03 AM   #1 (permalink)
*blink*
 
Soen Eber's Avatar
Vatican mole
 
Join Date: Oct 2009
Location: Minneapolis, Minnesota, USA
Posts: 7,131
My Mood:

Awards: 1
SLU Creepy Avatar Competition 2014 Participant 
Attach/Detach attachments by touch using RLV

I made this so friends could make me wear silly things.

Code:
// Attach items on touch using RLV
// 6/13/18 Soen Eber
// Open source, use however you like, commercial use is acceptable

// Populate the list _menu_all (below) with your attachments. 
// First column must always be "Attach"
// Second column is a short name for the attachment
//   The short name is the name which will appear in the "Attach" menu when the
//   attachment containing this menu script is clicked.
//   The short name is also the folder name for the attachment in the #RLV folder
//     the folder name will also have the attachment point in paranthesis
//       example: Bow (neck)
//     the list of attachment points can be found in the rlv api (google for it)
//     and are:
//       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,neck,root
//     HUD attachment points are:
//       center 2,top right,top,top left,center,bottom left,bottom,bottom right
//     the actual attachment will be in the folder; you do not have to change its name
//
// In your #RLV folder, create a subfolder for your avatar
//   example: #RLV/Teddy_Bear
//   in the Teddy_Bear folder, create a new folder "Attach"
//     example: #RLV/Teddy_Bear/Attach
//     in the Attach folder, create a folder for each attachment
//       Keep it SHORT! It will be used as a menu item
//       You will need to add the attachment point in parenthesis after the name
//       example: #RLV/Teddy_Bear/Attach/Bow (neck)
//         note the space before (neck)
//
// Replace "Teddy_Bear" in _Avatar with the name you will be using for your 
// avatar in the #RLV folder
string _Avatar = "Teddy_Bear";

// Replace the two "Attach" items in the _menu_all list with your attachment info
//
list    _menu_all = [
    "Attach","Bell",
    "Attach","Bow"
];

key    _id_agent;

integer _dlg_ch;
integer _dlg_hdl;
integer _dlg_wait = 10;

integer _viewer_ch;

list    _menu_main = [];
list    _menu_sub = [];
string  _menu_context = "main";
string  _selected_type;
integer _attach_i;
integer _attach_n;

setMainMenu()
{
    integer i = 0;
    integer n = llGetListLength(_menu_all);
    string sType;
    for (i=0; i< n; i+=2) {
        sType = llList2String(_menu_all,i);
        if (llListFindList(_menu_main, [sType]) == -1) {
            _menu_main += [sType];
        }
    }
}
subMenuInit(string searchType)
{
    _menu_sub = []; // clear previous contents
    string sType;
    integer n = llGetListLength(_menu_all);
    integer i = 0;
    _attach_i = 0;
    _attach_n = 0;
    
    for (i=0; i<n; i+=2) {
        sType = llList2String(_menu_all,i);
        if (searchType == sType) {
            _attach_n++;
        }
    }
}
buildSubMenu(string searchType)
{
    string sType;
    string sItem;
    string sRLVCmd;
    integer n = llGetListLength(_menu_all);
    integer i = 0;
    
    for (i = _attach_i*2; i<n; i+=2) {
        sType = llList2String(_menu_all,i);
        sItem = llList2String(_menu_all,i+1);
        if (searchType == sType) {
            string folder = "/"+_Avatar+"/"+sType+"/"+sItem;
            sRLVCmd = "@getinvworn:"+folder+"="+(string)_viewer_ch;
            llOwnerSay(sRLVCmd);
            jump break;
        }
    }
    call_menu();
    @break;
}
call_menu()
{
    llSetTimerEvent(_dlg_wait);
    llListenControl(_dlg_hdl, TRUE);
    if (_menu_context == "main") {
        llDialog(_id_agent, "Main", _menu_main, _dlg_ch);
    }
    else if (_menu_context = "sub") {
        llDialog(_id_agent, _selected_type, _menu_sub, _dlg_ch);
    }
}
default
{
    state_entry()
    {
        _dlg_ch = (integer)("0x"+llGetSubString((string)llGetKey(),-8,-1))+10;
        _dlg_hdl = llListen(_dlg_ch,"","","");
        _viewer_ch = llAbs((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)));
        llListen(_viewer_ch,"","","");
        setMainMenu();
    }
    on_rez(integer startup_param)
    {
        llResetScript();
    }
    changed(integer change)
    {
        if(change & CHANGED_OWNER) {
            llResetScript();
        }
        if (change & CHANGED_INVENTORY) {
            llOwnerSay("Resetting script due to change in inventory");
            llResetScript();
        }
    }
    listen(integer ch, string name, key id, string msg)
    {
        llSetTimerEvent(0);
        llListenControl(_dlg_hdl, FALSE);
        if (ch == _viewer_ch) {
            string item = llList2String(_menu_all, (_attach_i*2)+1);
            if (llGetSubString(msg,0,0) == "|") {
                if (llGetSubString(msg,1,1) == "3") {
                    _menu_sub += ["■ "+item];
                }
                else if (llGetSubString(msg,1,1) == "1") {
                    _menu_sub += ["□ "+item];
                }
            }
            _attach_i++;
            buildSubMenu(_selected_type);
        }
        else if (ch == _dlg_ch && _menu_context == "main") {
            if (llListFindList(_menu_main, [msg]) != -1) {
                _menu_context = "sub";
                _selected_type = msg;
                subMenuInit(_selected_type);
                buildSubMenu(_selected_type);
            }
        }
        else if (ch == _dlg_ch && _menu_context == "sub") {
            string sWorn = llGetSubString(msg,0,0);
            integer worn = FALSE;
            if (sWorn == "■") worn = TRUE;
            msg = llGetSubString(msg, 2, -1);  // strip out worn indicator and space
            string folder = "/"+_Avatar+"/"+_selected_type+"/"+msg;
            string sRLVCmd;
            _menu_context = "main";
            if (!worn) {
                sRLVCmd = "@attachover:"+folder+"=force";
            }
            else {
                sRLVCmd = "@detach:"+folder+"=force";
            }
            llOwnerSay(sRLVCmd);
        }
    }
    touch_start(integer num_detected)
    {
        _id_agent = llDetectedKey(0);
        call_menu();
    }
    timer()
    {
        llSetTimerEvent(0.0);
        _menu_context = "main";
        llListenControl(_dlg_hdl, FALSE);
    }
}
EDIT: 6/14/18 Removed some unused code.
__________________
Hey troll, don't you have a rapture to pray for or some poor people to run over or some beatitudes to ignore or newspapers to burn or something?

You can wish-list items and return to SLU to purchase through the affiliate link.
Note: Some people refuse to buy from Amazon due to predatory tactics against publishers as noted here and here by Jacqueline Trudeau.

Last edited by Soen Eber; 06-14-2018 at 06:30 AM.
Soen Eber is offline   Reply With Quote
1 User Said Thanks:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On




SEO by vBSEO