// Dragon Effects - 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 puts on a show. Guide: https://dragonaiconnect.com/docs/runtime/library // // Hands: particles (the recipe comes from the server), play_sound, loop_sound, play_animation (animesh), // set_look (colour and glow), spin. // 9110 <- API actions; 9112 hello -> API; 9113 <- API integer gFxUntil; hello(string why) { string m = "dragon-effects, " + (string)(llGetFreeMemory() / 1024) + " KB free"; if (why == "status") { llOwnerSay(m); return; } llMessageLinked(LINK_THIS, 9112, m, NULL_KEY); } particles(string rules, integer secs) { // [rule, type, value, ...], type i (integer), f (float), v (vector), k (key: who the effect flies to) list r = llJson2List(rules); list p; integer i; for (i = 0; i + 2 < llGetListLength(r); i += 3) { string t = llList2String(r, i + 1); string v = llList2String(r, i + 2); p += llList2Integer(r, i); if (t == "i") p += (integer)v; else if (t == "f") p += (float)v; else if (t == "k") p += (key)v; else p += (vector)v; } llParticleSystem(p); if (secs <= 0) { gFxUntil = 0; llSetTimerEvent(0); return; } // 0 = until someone says stop gFxUntil = llGetUnixTime() + secs; llSetTimerEvent(1.0); } string where(key t) // "Blake is 23 m north-east of me, 2 m up", worked out right now { vector d = llList2Vector(llGetObjectDetails(t, [OBJECT_POS]), 0); if (d == ZERO_VECTOR) return ""; d -= llGetPos(); float flat = llVecMag(); list dirs = ["east", "north-east", "north", "north-west", "west", "south-west", "south", "south-east"]; integer i = (integer)llRound(llAtan2(d.y, d.x) / (PI / 4)); if (i < 0) i += 8; string s = llKey2Name(t) + " is " + (string)llRound(flat) + " m " + llList2String(dirs, i % 8) + " of me"; if (d.z > 2) s += ", " + (string)llRound(d.z) + " m up"; else if (d.z < -2) s += ", " + (string)llRound(-d.z) + " m down"; if (flat < 1.5) s = llKey2Name(t) + " is right here"; return s + "."; } perform(string a) { string w = llJsonGetValue(a, ["do"]); if (w == "point") { // a particle pointer: a beam to someone or something, and where it is key t = (key)llJsonGetValue(a, ["t"]); string s = where(t); key who = (key)llJsonGetValue(a, ["who"]); if (s == "") { if (who) llRegionSayTo(who, 0, "I can't find that in this region."); return; } particles(llJsonGetValue(a, ["rules"]), (integer)llJsonGetValue(a, ["seconds"])); if (who) { if (llJsonGetValue(a, ["quiet"]) != "1") llRegionSayTo(who, 0, s + " Follow the beam."); } return; } if (w == "particles") { if (llJsonGetValue(a, ["effect"]) == "stop") llParticleSystem([]); else particles(llJsonGetValue(a, ["rules"]), (integer)llJsonGetValue(a, ["seconds"])); } else if (w == "play_sound") { string s = llJsonGetValue(a, ["sound"]); integer ok = (llGetInventoryType(s) == INVENTORY_SOUND); // a name inside, or a library key if ((key)s) ok = TRUE; if (ok) llPlaySound(s, 1.0); } else if (w == "loop_sound") { string s = llJsonGetValue(a, ["sound"]); if (s == "" || s == JSON_INVALID) llStopSound(); else { integer ok = (llGetInventoryType(s) == INVENTORY_SOUND); if ((key)s) ok = TRUE; if (ok) llLoopSound(s, 1.0); } } else if (w == "play_animation") { string an = llJsonGetValue(a, ["anim"]); if (llGetInventoryType(an) != INVENTORY_ANIMATION) return; list p = llGetObjectAnimationNames(); integer i; for (i = 0; i < llGetListLength(p); ++i) llStopObjectAnimation(llList2String(p, i)); llStartObjectAnimation(an); } else if (w == "set_look") { vector c = <1.0, 1.0, 1.0>; float g; if (llJsonGetValue(a, ["color"]) != "normal") { c = <(float)llJsonGetValue(a, ["color", 0]), (float)llJsonGetValue(a, ["color", 1]), (float)llJsonGetValue(a, ["color", 2])>; g = (float)llJsonGetValue(a, ["glow"]); } llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_COLOR, ALL_SIDES, c, 1.0, PRIM_GLOW, ALL_SIDES, g]); } else if (w == "spin") { if (llJsonGetValue(a, ["on"]) == JSON_TRUE) llTargetOmega(<0.0, 0.0, 1.0>, 0.5, 1.0); else llTargetOmega(ZERO_VECTOR, 0.0, 0.0); } } default { state_entry() { hello(""); } on_rez(integer p) { llResetScript(); } changed(integer c) { if (c & CHANGED_OWNER) llResetScript(); } timer() { if (llGetUnixTime() >= gFxUntil) { llParticleSystem([]); llSetTimerEvent(0); } } link_message(integer sender, integer num, string str, key id) { if (num == 9113) { hello(str); return; } if (num != 9110) return; integer i; string a = llJsonGetValue(str, [0]); while (a != JSON_INVALID && i < 8) { perform(a); a = llJsonGetValue(str, [++i]); } } }