次のような自分の行動の情報を取得してみます。
・自分が喋った回数
・人から聞いた回数(アバターが話したものに限定)
・空を飛んでいる時間(ホバーは含めない)
・海の中を泳いでいる時間(ホバーは含めない)
・歩いている時間
・走った時間
・ジャンプ中の時間
・テレポートした回数
・SIMをまたいだ回数
・人や当たり判定がある物体と衝突した回数
以下、サンプルです。
このコードを適当なオブジェクトに入れた後、HUDとして装備してください。
drawStatusと発言すると、自分の情報が表示されます。
ログインした回数とかも取れるかなと思ったのですが、
装備した回数と見分けがつかないので諦めました。
integer count_attack = 0;
integer count_speak = 0;
integer count_listen = 0;
integer count_flying = 0;
integer count_swimming = 0;
integer count_running = 0;
integer count_walking = 0;
integer count_teleport = 0;
integer count_simtraversal = 0;
integer count_jumping = 0;
integer TYPE_ATTACK = 0;
integer TYPE_SPEAK = 1;
integer TYPE_LISTEN = 2;
integer TYPE_FLYING = 3;
integer TYPE_SWIMMING = 4;
integer TYPE_RUNNING = 5;
integer TYPE_WALKING = 6;
integer TYPE_TELEPORT = 7;
integer TYPE_SIMTRAVERSAL = 8;
integer TYPE_JUMPING = 9;
integer show_dialog = FALSE;
integer listen_handle = -1;
addAction(integer action) {
// llOwnerSay("action : "+ (string)action);
if(action == TYPE_ATTACK) {
count_attack = count_attack + 1;
}
else if(action == TYPE_SPEAK) {
count_speak = count_speak + 1;
}
else if(action == TYPE_LISTEN) {
count_listen = count_listen + 1;
}
else if(action == TYPE_FLYING) {
count_flying = count_flying + 1;
}
else if(action == TYPE_SWIMMING) {
count_swimming = count_swimming + 1;
}
else if(action == TYPE_RUNNING) {
count_running = count_running + 1;
}
else if(action == TYPE_WALKING) {
count_walking = count_walking + 1;
}
else if(action == TYPE_TELEPORT) {
count_teleport = count_teleport + 1;
}
else if(action == TYPE_SIMTRAVERSAL) {
count_simtraversal = count_simtraversal + 1;
}
else if(action == TYPE_JUMPING) {
count_jumping = count_jumping + 1;
}
}
showStatus() {
llWhisper(0,
"attack\t:" + (string) count_attack + " times\n" +
"speak\t:" + (string) count_speak + " times\n" +
"listen\t:" + (string) count_listen + " times\n" +
"teleport\t:" + (string) count_teleport + " times\n" +
"simtraversal\t:" + (string) count_simtraversal + " times\n" +
"flying\t\t:" + (string) count_flying + " sec\n" +
"swimming\t\t:" + (string) count_swimming + " sec\n" +
"running\t:" + (string) count_running + " sec\n" +
"walking\t:" + (string) count_walking + " sec\n" +
"jumping\t:" + (string) count_jumping + " sec"
);
}
openDialog() {
if(listen_handle != -1) {
llListenRemove(listen_handle);
}
listen_handle = llListen(-100, "", llGetOwner(), "");
llDialog( llGetOwner(), "Which operation?\nYou say \"drawStatus\"... or \"resetStatus\"", ["status", "reset", "cancel"], -100 );
llSetTimerEvent(0.0);
llSetTimerEvent(30.0);
show_dialog = TRUE;
}
closeDialog() {
if(listen_handle != -1) {
llListenRemove(listen_handle);
}
show_dialog = FALSE;
listen_handle = llListen(0, "", "", "");
llSetTimerEvent(0.0);
llSetTimerEvent(1.0);
}
default {
state_entry() {
llOwnerSay("Start Script !\nYou say \"drawStatus\"... or \"resetStatus\"");
closeDialog();
}
touch_start(integer total_number) {
openDialog();
}
timer() {
if(show_dialog) {
closeDialog();
}
else {
string my_animatin = llGetAnimation(llGetOwner());
if(my_animatin == "Flying") {
vector v = llGetPos();
if(llWater(v) > v.z) {
addAction(TYPE_SWIMMING);
}
else {
addAction(TYPE_FLYING);
}
}
else if(my_animatin == "Running") {
addAction(TYPE_RUNNING);
}
else if(my_animatin == "Walking") {
addAction(TYPE_WALKING);
}
else if(my_animatin == "Jumping") {
addAction(TYPE_JUMPING);
}
}
}
listen( integer channel, string name, key id, string message ) {
// llOwnerSay(""+ (string)channel +" " + name + " " + (string)id + " " + message);
if(show_dialog) {
if(message == "status") {
showStatus();
}
else if(message == "reset") {
llResetScript();
}
else if(message == "cancel") {
}
closeDialog();
}
else {
if(id == llGetOwner()) {
if(message == "drawStatus") {
showStatus();
}
else if(message == "resetStatus") {
llResetScript();
}
else {
addAction(TYPE_SPEAK);
}
}
else if(llGetAgentSize(id)){
addAction(TYPE_LISTEN);
}
}
}
changed(integer mask) {
if(mask & CHANGED_OWNER) {
llResetScript();
}
if((mask & CHANGED_TELEPORT) && (mask & CHANGED_REGION)) {
addAction(TYPE_TELEPORT);
}
else if(mask & CHANGED_TELEPORT) {
addAction(TYPE_TELEPORT);
}
else if(mask & CHANGED_REGION) {
addAction(TYPE_SIMTRAVERSAL);
}
}
collision_start(integer num) {
if(llDetectedType(0) & ACTIVE) {
vector my_velocity = llGetVel();
vector velocity = llDetectedVel(0);
float power = llVecMag(my_velocity - velocity);
if(power >= 1.0) {
addAction(TYPE_ATTACK);
}
}
}
on_rez(integer param) {
// 1 ログイン、装備、rez
}
attach(key attached) {
if(attached) {
// 2 ログイン、装備
}
}
}



コメント