//================================================================== // Parcel prim counter // $Id: primcount.lsl 701 2010-08-09 06:33:29Z myuse $ //================================================================== list gObjIds; integer gTotalPrims; key gTgtParcelId; integer gTimerCount; float gTimerInterval = 0.97; float gBeamTimeout = 30.0; float gBeamRest; integer gListenHndl = -1;
// 位置情報の簡略表示 string makePosString (vector pos) { return "<" + (string)((integer)pos.x) + ", " + (string)((integer)pos.y) + ", " + (string)((integer)pos.z) + ">"; }
default { // ユーザーがプリムカウンターを脱着した attach (key id) { list parcelParams;
// システム初期化 llParticleSystem([]); llSetTimerEvent(0.0); if (gListenHndl >= 0) { llListenRemove(gListenHndl); }
if (id == llGetOwner()) { // ユーザーがプリムカウンターを着用 // 計測開始 gObjIds = []; gTotalPrims = 0; gTimerCount = 0; parcelParams = llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_ID, PARCEL_DETAILS_NAME]); gTgtParcelId = llList2Key(parcelParams, 0); llOwnerSay("Start counting object for this parcel (" + llList2String(parcelParams, 1) + ")."); llListen(0, "", llGetOwner(), ""); llSetTimerEvent(gTimerInterval); } else { // 計測終了 llSetTimerEvent(0.0); } }
// センサーでオブジェクトを探索 // 1イベント毎に scripted, non-scripted を交互に検索 timer() { if (gBeamRest > 0.0) { gBeamRest -= gTimerInterval; if (gBeamRest <= 0.0) { llParticleSystem([]); } }
gTimerCount = 1 - gTimerCount; if (gTimerCount) { llSensor("", NULL_KEY, PASSIVE, 40.0, PI); } else { llSensor("", NULL_KEY, PASSIVE | SCRIPTED, 40.0, PI); } }
// ユーザーが指定したオブジェクトに矢印パーティクルを指し示す listen (integer ch, string name, key id, string mes) { list words = llParseString2List(mes, [" "], []); key tgt;
if ((llList2String(words, 0) == "show") && (llGetListLength(words) == 2)) { tgt = llList2Key(gObjIds, (integer) llList2String(words, 1));
if (tgt == NULL_KEY) { llOwnerSay("ERROR : Unknown object number."); return; }
gBeamRest = gBeamTimeout; llParticleSystem([PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP, PSYS_SRC_TARGET_KEY, tgt, PSYS_PART_START_COLOR, <1.0, 1.0, 1.0>, PSYS_PART_START_ALPHA, 1.0, PSYS_PART_START_SCALE, <0.5, 1.0, 0.0>, PSYS_PART_MAX_AGE, 9.0, PSYS_SRC_BURST_RATE, 0.6, PSYS_SRC_TEXTURE, "a990f9a1-ab01-5071-444e-552b0f3f4983", PSYS_SRC_BURST_PART_COUNT, 1, PSYS_PART_FLAGS, PSYS_PART_TARGET_POS_MASK | PSYS_PART_EMISSIVE_MASK | PSYS_PART_FOLLOW_VELOCITY_MASK ]); } }
// センサー、検出したオブジェクトの判定 // 一度検出したオブジェクトはスキップ sensor (integer numDetected) { integer n; key id; vector pos; string name; integer prim;
for (n=0; n<numDetected; n+=1) { id = llDetectedKey(n); pos = llDetectedPos(n); if (llList2Key(llGetParcelDetails(pos, [PARCEL_DETAILS_ID]), 0)==gTgtParcelId) { if (llListFindList(gObjIds, [id]) < 0) { gObjIds += [id]; prim = llGetObjectPrimCount(id); name = llDetectedName(n); gTotalPrims += prim; if (llGetOwnerKey(id) == llGetOwner()) { // Your object llOwnerSay("@ No." + (string) llGetListLength(gObjIds) + ", " + (string) prim + "prim, " + name + " " + makePosString(pos) + ", total " + (string) gTotalPrims + "prims"); } else { // Not your's llOwnerSay(" No." + (string) llGetListLength(gObjIds) + ", " + (string) prim + "prim, " + name + " " + makePosString(pos) + ", total " + (string) gTotalPrims + "prims"); } } } } } }
|