0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LSL Animesh サンプルスクリプト (ランダムでアニメーションを切り替える)

Posted at

Animesh なオブジェクトに一緒にいれたアニメをランダムで切り替えるスクリプトです。
1番上の行の 30.0 は30秒ごとに切り替えるよってことです。

(同じアニメが選択される可能性があります。これはアニメが1つしか入ってない場合の制御省略ということでw)

ではみなさん おたのしんでね!!


float gap = 30.0; // アニメーションを切り替えるランダムタイマーの間隔(秒)

list anim_list;
integer anim_cnt = 0;
integer index = 0;


string current_anim = "";

list get_anims()
{
    list result = [];
    integer n = llGetInventoryNumber(INVENTORY_ANIMATION);
 
    while(n)
    {
        result = llGetInventoryName(INVENTORY_ANIMATION, --n) + result;
    }
 
    return result;
}

stop_all_animations()
{
    list curr_anims = llGetObjectAnimationNames();
    integer i;

    for(i = 0 ; i < llGetListLength(curr_anims) ; i++)
    {
        string anim = llList2String(curr_anims, i);
        llStopObjectAnimation(anim);
    }
}

integer random_integer( integer min, integer max )
{
    return min + (integer)( llFrand( max - min + 1 ) );
}

start_rand_anim()
{
    if(current_anim != "")
    {
        llStopObjectAnimation(current_anim);
    }
    index = random_integer(0, anim_cnt -1 );
    current_anim = llList2String(anim_list,index);
    llStartObjectAnimation(current_anim);
}

default
{
    state_entry()
    {
        llSetTimerEvent(0);
        
        stop_all_animations();
        anim_list = get_anims();
        anim_cnt = llGetListLength(anim_list);
        start_rand_anim();
        
        llSetTimerEvent(gap);
    }
    
    changed(integer change)
    {
        if((change & CHANGED_OWNER) || (change & CHANGED_INVENTORY))
        {
            llResetScript();
        }
    }
    
    on_rez(integer start_param)
    {
        llResetScript();
    }
    
    timer()
    {
        start_rand_anim();
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?