Script for Crafting
liannaduh
plain_text
2 years ago
6.9 kB
8
Indexable
string[] potionOptions = [
"Healing Elixir",
"Potion of Tranquility",
"Potion of Water Breathing",
"Brew of Keen Sight",
"Potion of Levitation",
"Elixir of True Sight"
];
default
{
state_entry()
{
llSetText("Click to use", <1.0, 1.0, 1.0>, 1.0);
}
touch_start(integer total_number)
{
// Check if the user is on cooldown
integer brewingCooldown = llGetInventoryNumber("brewingCooldown");
if (brewingCooldown > 0)
{
llSay(0, "You must wait an hour before attempting to brew another potion.");
return;
}
// Check if the user has the right class
if (llGetInventoryType(llGetOwner()) == INVENTORY_NONE)
{
llSay(0, "You do not have the necessary class to use this brewing station.");
return;
}
// Present the menu with potion options
llDialog(llGetOwner(), "Select a potion to brew:", potionOptions, 1);
}
touch_end(integer total_number)
{
// Do nothing on touch end
}
listen(integer channel, string name, key id, string message)
{
if (channel == 1)
{
integer index = llListFindList(potionOptions, [message]);
if (index != -1)
{
// Check if the user is allowed to craft more potions today
integer dailyCrafts = llGetInventoryNumber("PotionCraftCount");
integer maxPotions = llGetInventoryNumber("MaxPotions"); // Use the attribute
if (dailyCrafts >= maxPotions)
{
llSay(0, "You've reached your daily limit for potion crafting.");
return;
}
// Check if the user has recently crafted a potion
integer recentlyCrafted = llGetInventoryNumber("RecentlyCrafted");
if (recentlyCrafted)
{
llSay(0, "Sorry, you've recently crafted a potion. Come back later.");
return;
}
// Roll for success (1d20)
integer roll = llFloor(llFrand(20) + 1);
string potionCrafted = "";
string potionPrompt = "";
string ingredients = "";
// Check the roll for each potion and define ingredients
if (roll >= 15)
{
potionCrafted = "Healing Elixir";
potionPrompt = "You combine the necessary ingredients for the Healing Elixir and attempt to brew the potion.";
ingredients = "Mystic Herb, Crystal Water, Unicorn Horn Powder";
}
else if (roll >= 11)
{
integer randomPotionIndex = llFloor(llFrand(3));
potionCrafted = llList2String(["Potion of Tranquility", "Potion of Water Breathing", "Potion of Levitation"], randomPotionIndex);
if (potionCrafted == "Potion of Tranquility")
{
potionPrompt = "You combine the necessary ingredients for the Potion of Tranquility and attempt to brew the potion.";
ingredients = "Lavender Oil, Dreamroot, Essence of Serenity";
}
else if (potionCrafted == "Potion of Water Breathing")
{
potionPrompt = "You combine the necessary ingredients for the Potion of Water Breathing and attempt to brew the potion.";
ingredients = "Seaweed Extract, Deep Sea Coral, Aquatic Essence";
}
else if (potionCrafted == "Potion of Levitation")
{
potionPrompt = "You combine the necessary ingredients for the Potion of Levitation and attempt to brew the potion.";
ingredients = "Sky Orchid Petals, Feather of Griffin, Ethereal Essence";
}
}
else if (roll >= 13)
{
integer randomPotionIndex = llFloor(llFrand(2));
potionCrafted = llList2String(["Brew of Keen Sight", "Elixir of True Sight"], randomPotionIndex);
if (potionCrafted == "Brew of Keen Sight")
{
potionPrompt = "You combine the necessary ingredients for the Brew of Keen Sight and attempt to brew the potion.";
ingredients = "Hawk Eye Berry, Nightshade Root, Essence of Perception";
}
else if (potionCrafted == "Elixir of True Sight")
{
potionPrompt = "You combine the necessary ingredients for the Elixir of True Sight and attempt to brew the potion.";
ingredients = "Owl Feather Powder, Essence of Clarity, Moonlight Dew";
}
}
else
{
// Unsuccessful brewing
llSay(0, "Your brewing attempt fails. Better luck next time.");
return;
}
// Successful brewing
llSay(0, potionPrompt);
llGiveInventory(llGetOwner(), ingredients);
// Set the cooldown
llGiveInventory(llGetOwner(), "brewingCooldown");
llAttachToAvatarTemp(ATTACH_HUD_BOTTOM, llGetOwner());
llSetTimerEvent(3600); // Cooldown time in seconds (1 hour)
// Increment daily craft count
llGiveInventory(llGetOwner(), "PotionCraftCount");
// Apply the crafted potion effect
integer duration = 3600; // Duration of the effect in seconds (1 hour)
integer effectDuration = gsGetEffectDuration(CALLER, potionCrafted);
if (effectDuration < 0)
{
// Apply the effect if it's not already active
integer result = gsApplyEffect(CALLER, potionCrafted, duration);
if (result != 0)
{
llSay(0, "Failed to apply the potion effect. Please contact support.");
}
}
}
}
}
timer()
{
// Remove the cooldown timer
llSetTimerEvent(0);
llDetachFromAvatar(llGetOwner());
}
}
Editor is loading...
Leave a Comment