LoginSignup
0
1

More than 5 years have passed since last update.

セカンドライフ Cafe などで利用される分配チップジャーのサンプル

Last updated at Posted at 2017-05-06
1 / 2

周囲20m の従業員を検知し、分配するチップジャースクリプト

tipjar.lsl

//start_unprocessed_text
// TipJar ver.1.0
// Written by いっちゃん
// 2016.11.26

//ユーザ設定関数、ユーザで環境を変更してください。
string Jar_title = "Tip Jar";   //チップジャーのタイトル
string thanks_msg = "様、お心遣い有難う御座います。";     //サンクスメッセージ(名前に続く言葉) 
float range_sencer = 20.0;                              //チップ分配の範囲(m)
list price_lists = [5,10,30,39];

// 従業員の UUID (プロフィールから調べて入れてください。
list employees_uuid_lists = [
"???????",
"???????"
];

//---------------------------------------------------------------------------------------------------------

//システム使用変数
integer num_money = 0;
integer get_money = 0;
integer price;

set_commodity()
{
    llSetText(Jar_title + "\n--------------------\nTotal:L$" + (string)num_money,<1.0,1.0,1.0>,1.0);
}

default {
    on_rez(integer start_param)
    {
        llResetScript();
    }
    state_entry()
    {
        num_money = 0;
        llSetPayPrice(price, price_lists);
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }

    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_DEBIT)
        {
            state active;
        }
        else
        {
            llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
        }
    }
}

state active {
    on_rez(integer start_param)
    {
        llResetScript();
    }
    state_entry()
    {
        //「支払う」の内容を変更
        llSetPayPrice(price, price_lists);
        //金額の表示
        set_commodity();
    }
    money(key giver, integer amount)
    {
        get_money = 0;
        //持ち主にIMでお礼
        llInstantMessage(giver,llKey2Name(giver) + thanks_msg);
        //合計金額にプラス
        num_money += amount;
        get_money = amount;
        //プラスの金額を反映させる
        set_commodity();
        //20m以内のアバターを検出する
        llSensor( "", NULL_KEY,AGENT, range_sencer, PI );
    }

    sensor(integer total_number)
    {
        integer i;
        integer j;
        integer k;
        integer cnt_employee = 0;
        integer pey_price = 0;
        integer is_owner = FALSE;
        list pay_for_lists = [];

        //検出したアバターの所属グループを検出、人数をカウント
        for (i = 0; i < total_number; i++)
        {
            for(j = 0 ; j < llGetListLength(employees_uuid_lists) ; j++)
            {
                if (llDetectedKey(i) == llList2Key(employees_uuid_lists,j))
                {
                    for(k = 0 ; k < llGetListLength(pay_for_lists) ; k++)
                    {
                        if(llDetectedKey(i) == llList2Key(pay_for_lists,k))
                        {
                            jump break;
                        }
                    }
                    pay_for_lists += llDetectedKey(i);
                    cnt_employee++;
                }
                @break;

                if(llDetectedKey(i) == llGetOwner())
                {
                    is_owner = TRUE;
                    //cnt_employee++;
                }
            }
        }

        if(cnt_employee == 0)
        {
            jump goto_end;
        }

        // もしオーナー不在でも オーナーはカウントする
        //if(is_owner == FALSE)
        //{
        //    cnt_employee += 1;
        //}
        if(is_owner == TRUE)
        {
            //cnt_employee++;
        }

        pey_price = get_money / cnt_employee;
        //検出した同グループアバターに支払い(但しオーナー除く)
        for(j = 0 ; j < llGetListLength(pay_for_lists) ; j++)
        {
            llGiveMoney(llList2Key(pay_for_lists,j),pey_price);
        }

        @goto_end;
        pay_for_lists = [];
    }
}


0
1
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
1