// Dragon Shape - part of the Dragon Library for a Dragon AI Connect agent (Mind plan and up). // 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. // Guide: https://dragonaiconnect.com/docs/runtime/library // // 9110 <- API {"do":"shape","size","color","alpha","glow","bright","light","light_color","light_radius","rotation", // "type": box|cylinder|prism|sphere|torus|tube|ring, "hollow": 0-0.95, "phantom": 0|1} // 9118 -> API {"type":"hello","part":"shape"} on start 9113 <- API "announce yourself" // Changes the prim this script is in; the server already clamped every value. hello() { llMessageLinked(LINK_THIS, 9118, "{\"type\":\"hello\",\"part\":\"shape\"}", NULL_KEY); } list primType(string t) // a plain new prim of this type (hollow is applied afterwards) { if (t == "sphere") return [PRIM_TYPE_SPHERE, PRIM_HOLE_DEFAULT, <0, 1, 0>, 0.0, <0, 0, 0>, <0, 1, 0>]; integer ty = PRIM_TYPE_BOX; if (t == "cylinder") ty = PRIM_TYPE_CYLINDER; else if (t == "prism") ty = PRIM_TYPE_PRISM; else if (t == "torus") ty = PRIM_TYPE_TORUS; else if (t == "tube") ty = PRIM_TYPE_TUBE; else if (t == "ring") ty = PRIM_TYPE_RING; if (ty == PRIM_TYPE_TORUS || ty == PRIM_TYPE_TUBE || ty == PRIM_TYPE_RING) return [ty, PRIM_HOLE_DEFAULT, <0, 1, 0>, 0.0, <0, 0, 0>, <1, 0.25, 0>, <0, 0, 0>, <0, 1, 0>, <0, 0, 0>, 1.0, 0.0, 0.0]; return [ty, PRIM_HOLE_DEFAULT, <0, 1, 0>, 0.0, <0, 0, 0>, <1, 1, 0>, <0, 0, 0>]; } shape(string a) { list p; string v = llJsonGetValue(a, ["size"]); if (v != JSON_INVALID) p += [PRIM_SIZE, (vector)v]; vector c = llGetColor(0); float al = llGetAlpha(0); integer cc; v = llJsonGetValue(a, ["color"]); if (v != JSON_INVALID) { c = (vector)v; cc = TRUE; } v = llJsonGetValue(a, ["alpha"]); if (v != JSON_INVALID) { al = (float)v; cc = TRUE; } if (cc) p += [PRIM_COLOR, ALL_SIDES, c, al]; v = llJsonGetValue(a, ["glow"]); if (v != JSON_INVALID) p += [PRIM_GLOW, ALL_SIDES, (float)v]; v = llJsonGetValue(a, ["bright"]); if (v != JSON_INVALID) p += [PRIM_FULLBRIGHT, ALL_SIDES, (integer)v]; v = llJsonGetValue(a, ["light"]); if (v != JSON_INVALID) { vector lc = <1, 1, 1>; float lr = 5.0; string s = llJsonGetValue(a, ["light_color"]); if (s != JSON_INVALID) lc = (vector)s; s = llJsonGetValue(a, ["light_radius"]); if (s != JSON_INVALID) lr = (float)s; p += [PRIM_POINT_LIGHT, (integer)v, lc, 1.0, lr, 0.75]; } v = llJsonGetValue(a, ["rotation"]); if (v != JSON_INVALID) p += [PRIM_ROTATION, llEuler2Rot((vector)v * DEG_TO_RAD)]; v = llJsonGetValue(a, ["phantom"]); if (v != JSON_INVALID) p += [PRIM_PHANTOM, (integer)v]; string t = llJsonGetValue(a, ["type"]); string h = llJsonGetValue(a, ["hollow"]); if (t != JSON_INVALID || h != JSON_INVALID) { list cur = llGetLinkPrimitiveParams(LINK_THIS, [PRIM_TYPE]); if (t != JSON_INVALID) cur = primType(t); if (h != JSON_INVALID) { if (llList2Integer(cur, 0) != PRIM_TYPE_SCULPT) cur = llListReplaceList(cur, [(float)h], 3, 3); } if (llList2Integer(cur, 0) != PRIM_TYPE_SCULPT) p += [PRIM_TYPE] + cur; } llSetLinkPrimitiveParamsFast(LINK_THIS, p); } default { state_entry() { hello(); } on_rez(integer p) { llResetScript(); } changed(integer c) { if (c & CHANGED_OWNER) llResetScript(); } link_message(integer sender, integer num, string str, key id) { if (num == 9113) { if (str == "status") { llOwnerSay("dragon-shape, " + (string)(llGetFreeMemory() / 1024) + " KB free"); return; } hello(); return; } if (num != 9110) return; integer i; string a = llJsonGetValue(str, [0]); while (a != JSON_INVALID && i < 8) { if (llJsonGetValue(a, ["do"]) == "shape") shape(a); a = llJsonGetValue(str, [++i]); } } }