装着物をタッチしてアニメを選択出来るようにするスクリプトのサンプル

装着物をタッチしてアニメを選択出来るようにするスクリのサンプル

装着物にアニメと一緒にいれててみてください。

ではおたのしんでね！

```[_3z_AnimSelect.LSL]
// 装着物よう アニメ選択すくり
// written by esforco

string store_name = "";
list anim_list = [];
string current_anim = "";
integer current_index = 0;

integer dlg_channel = 0;
integer listen_handle = 0;
string check_1_str = "🗸 ";

open_anim_select_dlg(key av)
{
    if(listen_handle != 0)
    {
        llListenRemove(listen_handle);
        listen_handle = 0;
    }
    listen_handle = llListen(dlg_channel,"",av,"");
    
    list buttons = anim_list + ["[CLOSE]"];

    buttons = llListReplaceList( buttons, [check_1_str + llList2String(buttons,current_index)],
                    current_index, current_index );

    string msg = "\n            store_name\n\n\Please, Select animation.";
                     
    llDialog(av, msg, buttons, dlg_channel);
    
    buttons = [];
}


change_anim(string anim)
{
    //if(anim != current_anim)
    {
        string temp_anim = current_anim;
        
        current_anim = anim;
        llStartAnimation(current_anim);
        
        if(temp_anim != anim)
        {
            llStopAnimation(temp_anim);
        }
    }
}

integer genCh()
{
    integer gen;
    key id = llGetKey();
    string str = llGetSubString((string)id,0,3);
    gen = -1-(integer)("0x"+str);
    return gen;
}

// 文字列置換
string strReplace(string str, string search, string replace)
{
    return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
}

list get_anims()
{
    list       result = [];
    integer    n = llGetInventoryNumber(INVENTORY_ANIMATION);

    while(n)
    {
        result = llGetInventoryName(INVENTORY_ANIMATION, --n) + result;
    }
    
    return result;
}

default
{
    state_entry()
    {
        anim_list = get_anims();
        
        dlg_channel = genCh();
        current_index = 0;
        current_anim = llList2String(anim_list, current_index);
        llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
    }

    touch_start(integer num)
    {
        if(llDetectedKey(0) == llGetOwner())
        {
            open_anim_select_dlg(llGetOwner());
        }
    }

    run_time_permissions(integer parm)
    {
        if(parm == PERMISSION_TRIGGER_ANIMATION)
        {
            if(current_anim != "")
            {
                llStartAnimation(current_anim);
            }
            else
            {
                current_anim = llList2String(anim_list, current_index);
                llStartAnimation(current_anim);
            }
        }
    }
    
    listen( integer channel, string name, key id, string msg )
    {
        if(llGetOwner() != llGetOwnerKey(id)) return;
        
        msg = strReplace(msg, check_1_str, "");
        
        if(msg == "[CLOSE]")
        {
        }
        else
        {
            current_index = llListFindList(anim_list, [msg]);
            string anim = msg;
            
            change_anim(anim);
            
            open_anim_select_dlg(llGetOwner());
        }
    }

    attach(key id)
    {
        if(id)
        {
            //llOwnerSay((string)genCh());
            llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
            llStartAnimation(current_anim);
        }
        else
        {
            if(current_anim != "")
            {
                //llStopAnimation(current_anim);
            }
        }
    }

    changed(integer change)
    {
        if(change & CHANGED_OWNER || change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
}

```