And sooo now here is the working script !!! The station gives the crafted item into the inventory of the crafter and then deletes the ingredients YAY!! Ingredients and crafted item can be changed in the script though i did try getting Chat GPT to make a config card it would not work for me.
// Crafting Station Script
integer dialogChannel; // Channel for dialog
list recipes; // List of recipes
list requiredIngredients; // Ingredients needed for crafting
string craftedItem; // Variable to hold the name of the crafted item
integer foundCount; // Counter for found ingredients
list detectedIngredientKeys; // List to hold keys of detected ingredients
key crafterKey; // Variable to hold the key of the player crafting
default
{
state_entry()
{
// Define some crafting recipes as a list of lists
recipes = [
"Chair", "Wood1", "Nails",
"Table", "Wood", "Nails",
"Stone Wall", "Stone", "Cement"
];
llSay(0, "Welcome to the Crafting Station! Touch to see available recipes.");
}
touch_start(integer total_number)
{
// Store the key of the player who touched the crafting station
crafterKey = llDetectedKey(0);
// Create a list of crafted item names for the dialog
list itemNames = [
"Chair",
"Table",
"Stone Wall"
];
// Generate a unique dialog channel for this user
dialogChannel = (integer)llFrand(10000); // Random channel between 0 and 9999
llDialog(crafterKey, "Select an item to craft:", itemNames, dialogChannel);
llListen(dialogChannel, "", crafterKey, ""); // Start listening for dialog responses
}
listen(integer channel, string name, key id, string message)
{
if (channel != dialogChannel) return;
// Check if the item is in the recipes list
integer index = llListFindList(recipes, [message]);
if (index != -1)
{
// Get the required ingredients for the selected item
requiredIngredients = llList2List(recipes, index + 1, index + 2);
craftedItem = message; // The crafted item name is the selected message
// Provide feedback on required ingredients
llSay(0, "You need: " + llDumpList2String(requiredIngredients, ", ") + " to craft a " + craftedItem + ".");
// Reset the detected ingredient keys list
detectedIngredientKeys = [];
// Check for ingredients nearby after a short delay
llSetTimerEvent(0.5); // Set a timer for 0.5 seconds
}
else
{
llSay(0, "Recipe not found. Please try again.");
}
llListenRemove(channel); // Stop listening after processing the message
}
timer()
{
llSensor("", NULL_KEY, ACTIVE, 10.0, PI); // Start sensing for nearby objects
llSetTimerEvent(0.0); // Stop the timer
}
sensor(integer total_number)
{
list detectedObjects = [];
list foundIngredients = []; // List to hold found required ingredients
for (integer i = 0; i < total_number; i++)
{
detectedObjects += llDetectedName(i);
}
// Check if all required ingredients are found
integer count = llGetListLength(requiredIngredients);
foundCount = 0; // Reset found count for this sensor event
detectedIngredientKeys = []; // Reset the detected ingredient keys list
for (integer i = 0; i < count; i++)
{
string ingredient = llList2String(requiredIngredients, i);
// Case-insensitive matching
if (llListFindList(detectedObjects, [ingredient]) != -1 ||
llListFindList(detectedObjects, [llToLower(ingredient)]) != -1)
{
foundCount++;
// Store the key of the detected ingredient
key ingredientKey = llDetectedKey(i); // Get the key of the detected ingredient
detectedIngredientKeys += [ingredientKey]; // Add to the list of detected ingredient keys
foundIngredients += [ingredient]; // Add found ingredient to the list
}
}
// If all ingredients are found, craft the item
if (foundCount == count)
{
llSay(0, "You have crafted a " + craftedItem + "!");
// Check if the crafted item exists in inventory before giving it
if (llGetInventoryType(craftedItem) != INVENTORY_NONE)
{
llGiveInventory(crafterKey, craftedItem); // Give the crafted item to the crafter
llSay(0, "Giving " + craftedItem + " to " + llDetectedName(0));
}
else
{
llSay(0, "Crafted item not found in inventory.");
}
// Call the function to delete ingredients from the world
deleteIngredients(detectedIngredientKeys);
}
else
{
// Only announce the found required ingredients
llSay(0, "You do not have all the required ingredients nearby. Found: " + llDumpList2String(foundIngredients, ", ") + ".");
}
}
on_rez(integer start_param)
{
llResetScript();
}
}
// Function to delete ingredients from the world
deleteIngredients(list ingredientKeys)
{
integer count = llGetListLength(ingredientKeys);
for (integer i = 0; i < count; i++)
{
key ingredientKey = llList2Key(ingredientKeys, i);
// Send a message to the ingredient to delete itself without any announcement
llRegionSayTo(ingredientKey, 0, "DeleteSelf"); // This message will be listened for by the ingredient scripts
}
}
liked(1)