汎用アバターレーダースクリプト

フォントカラー、センサー周期、レーダーのオン/オフをダイアログからいつでも変更できる汎用アバターレーダーです(ダイアログはタッチで出ます)

アバターレーダーは、スクリプトを書くときのエッセンスがぎっしりつまったものですのでお勉強用ということでw ソースを公開します。

えと、適当なプリムにこのスクリプトをコピーしHUDとしてご利用ください^^

センサーはSIMに負荷をかけますのでご利用はほどほどに^^(なるべくセンサー周期を長めに設定しつつ、afk時はオフにしましょう!!)

code

avatar_radar.lsl
// Avatar Radar :: 2008-08-04
 
// Setup
string my_name = "LB System :: Avatar Radar";
string ver = "ver.1.00.42";
 
uuSetup(){
    llSetObjectName(my_name);
    llSetObjectDesc(ver);
    llOwnerSay(my_name + "  " + ver);
}
 
// Sensor
integer switch;
vector my_pos;
vector av_pos;
integer max_read;
string agent_info;
string dist;
string n_s;
string e_w;
string h_l;
vector font_color = <1.0, 1.0, 1.0>;
 
uuSensor(integer flug){
    switch = flug;
    if (flug){
        llSensorRepeat("", NULL_KEY, AGENT, 96.0, PI, sensor_arc);
        llSetText("Searching", font_color, 1.0);
    }else{
        llSensorRemove();
        llSetText(":: OFF ::", font_color, 1.0);
    }
}
 
uuPos(){
    if (av_pos.y - my_pos.y > 1){
        n_s = "N";
    }else if (av_pos.y - my_pos.y < -1){
        n_s = "S";
    }else{
        n_s = "";
    }
    if (av_pos.x - my_pos.x > 1){
        e_w = "E";
    }else if (av_pos.x - my_pos.x < -1){
        e_w = "W";
    }else{
        e_w = "";
    }
    if (av_pos.z - my_pos.z > 2){
        h_l = "↑";
    }else if (av_pos.z - my_pos.z < -2){
        h_l = "↓";
    }else{
        h_l = "●";
    }
}
 
// Interface
integer d_ch = -11111;
float listen_remove = 60.0;
integer session_id;
float session_timeout = 30.0;
float sensor_arc = 5.0;
list menu_off = ["オン", "文字色", "時間"];
list menu_on = ["オフ", "文字色", "時間"];
list colors = ["白", "黒", "赤", "青", "黄", "緑"];
list color_vector = [<1.0, 1.0, 1.0>, <0.0, 0.0, 0.0>, <1.0, 0.0, 0.0>, <0.0, 0.0, 1.0>, <1.0, 1.0, 0.0>, <0.0, 1.0, 0.0>];
list seconds = ["10", "20", "30", "1", "3", "5"];
integer color_change = FALSE;
 
uuListen(integer session_start){
    if (session_start){
        session_id = llListen(d_ch, "", llGetOwner(), "");
        llSetTimerEvent(session_timeout);
    }else{
        llSetTimerEvent(0.0);
        llListenRemove(session_id);
    }
}
 
uuMainDialog(){
    uuListen(TRUE);
    if (switch){
        llDialog(llGetOwner(), "メインメニュー", menu_on, d_ch);
    }else{
        llDialog(llGetOwner(), "メインメニュー", menu_off, d_ch);
    }
}
 
uuColorDialog(){
    color_change = TRUE;
    uuListen(TRUE);
    llDialog(llGetOwner(), "文字色を選択してください", colors, d_ch);
}
 
uuArcDialog(){
    uuListen(TRUE);
    llDialog(llGetOwner(), "センサー周期を選択してください \n推奨5秒以上 \n \n現在の設定:" + (string)((integer)sensor_arc) + "(秒)", seconds, d_ch);
}
 
// Color Change
uuChangeColor(string str){
    font_color = llList2Vector(color_vector, llListFindList(colors, [str]));
    if (switch){
        llSetText(agent_info, font_color, 1.0);
    }else{
        llSetText(":: OFF ::", font_color, 1.0);
    }
}
 
// Flow
default{
    state_entry(){
        uuSetup();
        uuSensor(TRUE);
    }
 
    sensor(integer num_detected){
        my_pos = llGetPos();
        agent_info = "";
        if (num_detected < 8){
            max_read = num_detected;
        }else{
            max_read = 8;
        }
        integer i;
        for (i = 0; i < max_read; i++){
            av_pos = llDetectedPos(i);
            uuPos();
            dist = " @ " + n_s + e_w + " " + (string)llRound(llVecDist(llGetPos(),av_pos)) + "m " + h_l;
            agent_info += " \n" + llDetectedName(i) + dist;
        }
        llSetText(agent_info, font_color, 1.0);
    }
 
    no_sensor(){
        llSetText("No PPL around here.", font_color, 1.0);
    }
 
    touch_start(integer total_number){
        if (llDetectedKey(0) == llGetOwner()){
            uuMainDialog();
        }
    }
 
    timer(){
        uuListen(FALSE);
    }
 
    listen(integer channel, string name, key id, string message){
        uuListen(FALSE);
        if (message == "オン"){
            uuSensor(TRUE);
        }else if (message == "オフ"){
            uuSensor(FALSE);
        }else if (message == "時間"){
            uuArcDialog();
        }else if (message == "文字色"){
            uuColorDialog();
        }else if (color_change){
            color_change = FALSE;
            uuChangeColor(message);
        }else{
            sensor_arc = (float)message;
            llOwnerSay(message + "秒に設定しました");
        }
    }
}

余談ですがw

あたしはリスンイベントを使うときは次のようなユーザ関数をつくっておいて、コールすることにしています^^

// Listen Session
integer d_ch = -100;
integer session_id;
float session_timeout = 30.0;
 
uuListen(integer session_start){
    if (session_start){
        session_id = llListen(d_ch, "", llGetOwner(), "");
        llSetTimerEvent(session_timeout);
    }else{
        llSetTimerEvent(0.0);
        llListenRemove(session_id);
    }
}

リスンするとき

uuListen(TRUE);

リスンを閉じるとき

uuListen(FALSE);

とコールします^^

これ、便利ですよw

小枝ということで^^

最終更新: 2010年11月08日 20 : 45 by arz Nitely
http://arzNitely.com/lsl/sample/radar.html

Copyright 2007-2010 ©arzNitely.com all right reserved

www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0