From 69f389a5ff432a394a1bea08bf9bbaa38d68b9f3 Mon Sep 17 00:00:00 2001 From: zontreck Date: Wed, 12 Feb 2025 01:49:53 -0700 Subject: [PATCH] begin adding a container! --- LSL/raw/basic_container.lsl | 224 +++++++++++++++++++++++++++++ LSL/raw/basic_container_expire.lsl | 11 ++ 2 files changed, 235 insertions(+) create mode 100644 LSL/raw/basic_container.lsl create mode 100644 LSL/raw/basic_container_expire.lsl diff --git a/LSL/raw/basic_container.lsl b/LSL/raw/basic_container.lsl new file mode 100644 index 0000000..0c946c5 --- /dev/null +++ b/LSL/raw/basic_container.lsl @@ -0,0 +1,224 @@ +#include "Common.lsl" + +key g_kID; +string g_sIngredientType = "none"; +integer g_iQuantity = 0; +integer g_iProdLink=3; +vector g_vScale; +vector g_vParticleColor = ZERO_VECTOR; +key g_kFollow = NULL_KEY; +integer g_iSealed = FALSE; +integer g_iDurability = 100; +integer g_iLastListener=-1; + +setText() { + if(g_sIngredientType == "none") { + llSetText("Empty", <1,1,1>, 1); + }else{ + if(!g_iSealed) + llSetText(g_sIngredientType + ": " + (string)g_iQuantity, <1,1,1>, 1); + else + llSetText("*Sealed*\n" + g_sIngredientType + ": " + (string)g_iQuantity, <0,1,1>, 1); + } +} + +setProductTexture(key kID) { + #ifdef PRODUCT_PRIM + if(g_iProdLink!=-99) { + #ifdef PRODUCT_FACE + llSetLinkTexture(PRODUCT_PRIM, kID, PRODUCT_FACE); + #else + llSetLinkTexture(PRODUCT_PRIM, kID, ALL_SIDES); + #endif + } + #endif +} + + +stopFollowing(float fOffset) { + if(g_kFollow == NULL_KEY)return; + g_kFollow = NULL_KEY; + llSetTimerEvent(0); + llSetPos(llGetPos() - <0,0,fOffset>); +} + +follow(key kID) { + g_kFollow = kID; + llSetTimerEvent(1); +} + +bumpDurability() { + + g_iDurability--; + + if(g_iDurability == 0) { + llSetColor(ZERO_VECTOR, ALL_SIDES); + llSetText("* Broken *", <1,0,0>, 1); + llSetScriptState("Container Expire [AC]", TRUE); + llRemoveInventory(llGetScriptName()); + } +} + + +particles(key kTarget) { + if(kTarget == NULL_KEY) llParticleSystem([]); + else { + llParticleSystem( + [ + // texture parameters: + PSYS_SRC_TEXTURE , "", + PSYS_PART_START_SCALE , <0.67,0.58,0.00>, PSYS_PART_END_SCALE , <0.09,0.09,0.00>, + PSYS_PART_START_COLOR , g_vParticleColor, PSYS_PART_END_COLOR , <0.16,0.71,0.83>, + PSYS_PART_START_ALPHA , (float)1.00, PSYS_PART_END_ALPHA , (float)1.00, + // production parameters: + PSYS_SRC_BURST_PART_COUNT , 16, + PSYS_SRC_BURST_RATE , (float)0.10, + PSYS_PART_MAX_AGE , (float)6.54, + PSYS_SRC_MAX_AGE , (float)0.18, + // placement parameters: + PSYS_SRC_PATTERN , 2, + PSYS_SRC_BURST_SPEED_MIN , (float)1.00, PSYS_SRC_BURST_SPEED_MAX , (float)1.00, + PSYS_SRC_BURST_RADIUS , (float)0.00, + // placement parameters (for angles only): + PSYS_SRC_ANGLE_BEGIN , (float)0.00, + PSYS_SRC_ANGLE_END , (float)0.00, + PSYS_SRC_OMEGA , <0.00,0.00,0.00>, + // after-effects & influences: + PSYS_SRC_ACCEL , <0.00,0.00,0.00>, + PSYS_SRC_TARGET_KEY , kTarget, + PSYS_PART_FLAGS , ( 0 // texture & influence options: + // | PSYS_PART_INTERP_COLOR_MASK + | PSYS_PART_INTERP_SCALE_MASK + // | PSYS_PART_BOUNCE_MASK + // | PSYS_PART_WIND_MASK + // | PSYS_PART_FOLLOW_SRC_MASK + | PSYS_PART_FOLLOW_VELOCITY_MASK + | PSYS_PART_TARGET_POS_MASK + // | PSYS_PART_TARGET_LINEAR_MASK + | PSYS_PART_EMISSIVE_MASK + )] ); + } +} + +default +{ + state_entry() + { + llLinksetDataReset(); + llSetText("Empty", <1,1,1>, 1); + PROTECT(); + + XteaKey(PSK); + + global_ingredients = getIngredientChannel(NULL_KEY); + llListen(global_ingredients, "", "", ""); + particles(llGetKey()); + + setProductTexture(TEXTURE_TRANSPARENT); + g_kID = llGenerateKey(); + llSay(0, "> Product initialization complete"); + } + + touch_start(integer num_detected) + { + llParticleSystem([]); + if(g_kFollow == NULL_KEY) { + follow(llDetectedKey(0)); + }else { + stopFollowing(g_vScale.z-0.2); + } + } + + timer () { + g_vScale = llGetAgentSize(g_kFollow); + if(g_vScale == ZERO_VECTOR) { + stopFollowing(g_vScale.z-0.2); + }else { + list lData = llGetObjectDetails(g_kFollow, [OBJECT_POS, OBJECT_ROT]); + vector vPos = llList2Vector(lData,0); + rotation rPos = llList2Rot(lData,1); + llSetRegionPos(vPos + <1.1, -1, 1> * rPos); + } + } + + on_rez(integer n) { + llSetText("Empty", <1,1,1>, 1); + + if(g_iLastListener != -1) llListenRemove(g_iLastListener); + + g_iLastListener = llListen(getIngredientChannel(llGetKey()), "", "", ""); + setProductTexture(TEXTURE_TRANSPARENT); + + // Check if ingredient type was already set. This is not a storage container. + if(g_sIngredientType != "none" && !g_iSealed) { + llWhisper(0, "I spilled in your inventory, consider using a sealed storage container."); + + g_sIngredientType = "none"; + g_iQuantity = 0; + g_vParticleColor = ZERO_VECTOR; + setProductTexture(NULL_KEY); + }else { + // Inform any nearby object that is waiting that we've been rezzed + llWhisper(global_ingredients, xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "alive", "type", INGREDIENT_HOLDER_TYPE]))); + } + } + + listen(integer c,string n,key i,string m) { + // Decode message + string params = xtea_decrypt_string(m); + + // Get operation + if(c == global_ingredients) { + if(g_kID == NULL_KEY) return; + else { + if(llJsonGetValue(params, ["cmd"]) == "query") { + llRegionSayTo(i,c,xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "reply", "ingredient", g_sIngredientType, "id", g_kID]))); + } + } + }else { + if(llJsonGetValue(params, ["cmd"]) == "deposit") { + if(g_sIngredientType == "none" || g_sIngredientType == llJsonGetValue(params, ["type"])) { + g_sIngredientType = llJsonGetValue(params, ["type"]); + string sStatus = "fail"; + + if(g_iQuantity == 0) { + g_iQuantity += (integer)llJsonGetValue(params, ["amount"]); + sStatus = "ok"; + setProductTexture(llJsonGetValue(params, ["texture"])); + g_vParticleColor = (vector)llJsonGetValue(params, ["particle"]); + //g_iDies = (integer)llJsonGetValue(params, ["dies"]); + + particles(llGetKey()); + llMessageLinked(LINK_SET, 0, "", ""); + } + + setText(); + + + llRegionSayTo(i, getIngredientChannel(NULL_KEY), xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "deposit_reply", "status", sStatus]))); + + particles(NULL_KEY); + } + + } else if(llJsonGetValue(params, ["cmd"]) == "use" && llJsonGetValue(params, ["id"]) == g_kID) { + particles(i); + if(g_iQuantity==0) { + llRegionSayTo(i,global_ingredients,llList2Json(JSON_OBJECT, ["cmd", "use_reply", "id", NULL_KEY, "amount", 0])); + return; + } + g_iQuantity--; + llRegionSayTo(i,global_ingredients,llList2Json(JSON_OBJECT, ["cmd", "use_reply", "id", g_kID, "amount", 1, "ingredient", g_sIngredientType])); + + setText(); + if(g_iQuantity<=0) { + g_iQuantity=0; + setProductTexture(TEXTURE_TRANSPARENT); + + g_sIngredientType = "none"; + + bumpDurability(); + } + } + } + } +} \ No newline at end of file diff --git a/LSL/raw/basic_container_expire.lsl b/LSL/raw/basic_container_expire.lsl new file mode 100644 index 0000000..729e8cf --- /dev/null +++ b/LSL/raw/basic_container_expire.lsl @@ -0,0 +1,11 @@ +default +{ + state_entry() + { + llSetScriptState(llGetScriptName(), FALSE); + } + + touch_start(integer iNum) { + llDie(); + } +} \ No newline at end of file