// Dragon Presence - part of the Dragon Library for a Dragon AI Connect agent. Put it next to dragon_api.lsl. // The Library is a set of small scripts, one per kind of ability, each with its own 64 KB: add only the ones // you want. No logic and no secrets: the server decides, this script notices people. Guide: https://dragonaiconnect.com/docs/runtime/library // // Senses: arrivals (someone comes within 20 m; the server decides whether to greet) and tips (pay, when // the tip jar is on). Each goes to the API on 9119, which asks the AI and answers. // 9112 hello -> API; 9113 <- API "announce yourself"; 9114 <- API settings (tips on/off) list gNear; integer gScanned; integer gTips = -1; hello(string why) { string m = "dragon-presence, " + (string)(llGetFreeMemory() / 1024) + " KB free"; if (why == "status") { llOwnerSay(m); return; } llMessageLinked(LINK_THIS, 9112, m, NULL_KEY); } list nearby() { list near; integer i; list ag = llGetAgentList(AGENT_LIST_REGION, []); vector me = llGetPos(); for (i = 0; i < llGetListLength(ag) && llGetListLength(near) < 12; ++i) { key k = llList2Key(ag, i); if (llVecDist(me, llList2Vector(llGetObjectDetails(k, [OBJECT_POS]), 0)) <= 20.0) near += k; } return near; } tips(integer on) { if (on == gTips) return; gTips = on; if (on) llSetPayPrice(PAY_DEFAULT, [50, 100, 250, 500]); else llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]); } default { state_entry() { tips(FALSE); hello(""); llSetTimerEvent(15.0); } on_rez(integer p) { llResetScript(); } changed(integer c) { if (c & (CHANGED_OWNER | CHANGED_REGION_START)) llResetScript(); } timer() { list before = gNear; gNear = nearby(); if (!gScanned) { gScanned = TRUE; return; } // the first look only takes note of who's here integer i; integer sent; for (i = 0; i < llGetListLength(gNear) && sent < 3; ++i) { key a = llList2Key(gNear, i); if (llListFindList(before, [a]) == -1) { llMessageLinked(LINK_THIS, 9119, llList2Json(JSON_OBJECT, ["prompt", "", "speaker", a, "speaker_name", llGetDisplayName(a), "event", "arrival"]), NULL_KEY); ++sent; } } } money(key who, integer amount) { llMessageLinked(LINK_THIS, 9119, llList2Json(JSON_OBJECT, ["prompt", "", "speaker", who, "speaker_name", llGetDisplayName(who), "event", "payment", "amount", amount, "max_tokens", 120]), NULL_KEY); } link_message(integer sender, integer num, string str, key id) { if (num == 9113) hello(str); else if (num == 9114) tips(llJsonGetValue(str, ["tips"]) == JSON_TRUE); } }