begin adding a container!
This commit is contained in:
parent
a31b0deea1
commit
69f389a5ff
2 changed files with 235 additions and 0 deletions
224
LSL/raw/basic_container.lsl
Normal file
224
LSL/raw/basic_container.lsl
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
LSL/raw/basic_container_expire.lsl
Normal file
11
LSL/raw/basic_container_expire.lsl
Normal file
|
@ -0,0 +1,11 @@
|
|||
default
|
||||
{
|
||||
state_entry()
|
||||
{
|
||||
llSetScriptState(llGetScriptName(), FALSE);
|
||||
}
|
||||
|
||||
touch_start(integer iNum) {
|
||||
llDie();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue