index 35f4728c2e0..910c97ebddb 100644 --- a/cas_/cas_custompizza.nss +++ b/cas_/cas_custompizza.nss @@ -1,98 +1,199 @@ -const int MAX_TOPPINGS = 5; // Maximum number of toppings allowed - -// Function to return available toppings as a single string -string GetAvailableToppings() -{ - return "Pepperoni,Bacon,Sausage,Pineapple,Spinach,Peppers,Green Pepper,Yellow Pepper,Chipotles,Sardines,Tomatoes,Mushrooms,Olives,Onions,Ham,Jalape?os,Jalapenos,Extra Cheese,Basil"; -} - -// Function to check if a topping is available -int IsToppingAvailable(string sTopping) -{ - string sAvailableToppings = GetAvailableToppings(); - int nPos = FindSubString(sAvailableToppings, sTopping); - if (nPos != -1) return TRUE; - return FALSE; -} - -// Function to delete stored toppings from the NPC after a delay -void DeleteToppingsFromNPC(object oNPC) -{ - int i; - for (i = 1; i <= MAX_TOPPINGS; i++) - { - DeleteLocalString(oNPC, "sTopping" + IntToString(i)); // Delete each stored topping - DeleteLocalInt(oNPC, "ToppingCount"); - } - AssignCommand(oNPC, ActionSpeakString("Topping selections have been cleared.", TALKVOLUME_TALK)); -} - -// Function to process topping selection after the delay -void ProcessToppingInput(object oPC, string sSaid) -{ - // Get the NPC involved in the conversation - object oNPC = GetObjectByTag("C_CAS_PIZZANPC"); - - if (IsToppingAvailable(sSaid)) - { - int nToppingCount = GetLocalInt(oNPC, "ToppingCount"); - - // Check if the topping count has reached the maximum limit - if (nToppingCount >= MAX_TOPPINGS) - { - AssignCommand(oNPC, ActionSpeakString("You can only select up to " + IntToString(MAX_TOPPINGS) + " toppings.", TALKVOLUME_TALK)); - return; - } - - nToppingCount++; // Increment topping count - SetLocalString(oNPC, "sTopping" + IntToString(nToppingCount), sSaid); // Store topping on NPC - SetLocalInt(oNPC, "ToppingCount", nToppingCount); // Update topping count on NPC - - AssignCommand(oNPC, ActionSpeakString(sSaid + " added to your pizza. You now have " + IntToString(nToppingCount) + " toppings.", TALKVOLUME_TALK)); - } - else if (sSaid == "finished" || sSaid == "Finished") - { - AssignCommand(oNPC, ActionSpeakString("You've finished selecting toppings. Proceeding to pizza creation.", TALKVOLUME_TALK)); - - // Break the conversation - AssignCommand(oPC, ActionPauseConversation()); - - // Trigger pizza creation - ExecuteScript("cas_makepizza", oPC); - - // Set a delay of 10 seconds to delete the stored toppings from the NPC - DelayCommand(10.0, DeleteToppingsFromNPC(oNPC)); - } - else - { - AssignCommand(oNPC, ActionSpeakString("Invalid input. Please choose a valid topping or say 'finished' when you're done.", TALKVOLUME_TALK)); - } -} - -// Main function to handle player chat input and store toppings with a delay -// Main function to start the pizza order, ensuring it only looks for a player in the A_CAS_HELLS_KITCHE area -void main() -{ - // Get the area by tag - object oArea = GetObjectByTag("A_CAS_HELLS_KITCHE"); - if (!GetIsObjectValid(oArea)) - { - return; // Exit if the area is not found - } - - // Get the first player character in the A_CAS_HELLS_KITCHE area - object oPC = GetFirstPCInArea(oArea); - - // If no player character is found in the area, exit the script - if (!GetIsObjectValid(oPC)) - { - return; // Exit if no player is found in the area - } - - // Debug message to confirm the script is running - AssignCommand(oPC, ActionSpeakString("cas_makepizza script called successfully.", TALKVOLUME_TALK)); - - // Example of ordering a pizza (assuming toppings are already stored) - OrderPizza(oPC); -} - +// Define constants +const int GOLD_COST_PER_PIZZA = 250; // Cost of a pizza +const float PIZZA_PREP_DELAY = 60.0f; // 2 minutes in seconds for each step +const string RESREF_ORDER_NUMBER_ITEM = "cas_ordernum"; // ResRef of the order number item +const string RESREF_PIZZA_ITEM = "cas_custompizza"; // ResRef of the custom pizza item +const string TAG_HELLS_KITCHE = "A_CAS_HELLS_KITCHE"; // Tag of the area where the NPC is located + +// Function to find the NPC in the specific area +object FindNPCInArea(string sNPC, string sAreaTag) +{ + object oArea = GetObjectByTag(sAreaTag); + object oNPC = GetFirstObjectInArea(oArea); + while (GetIsObjectValid(oNPC)) + { + if (GetTag(oNPC) == sNPC) + { + return oNPC; + } + oNPC = GetNextObjectInArea(oArea); + } + return OBJECT_INVALID; // Return invalid if NPC not found +} + +// Function to find the closest PC in the given area to the specified NPC +object FindClosestPCInArea(object oNPC, string sAreaTag) +{ + object oArea = GetObjectByTag(sAreaTag); + if (!GetIsObjectValid(oArea)) return OBJECT_INVALID; + + object oClosestPC = OBJECT_INVALID; + float fMinDistance = -1.0f; + + // Use GetFirstObjectInArea and GetNextObjectInArea to iterate through all objects in the area + object oCreature = GetFirstObjectInArea(oArea); + while (GetIsObjectValid(oCreature)) + { + // Check if the object is a PC + if (GetIsPC(oCreature)) + { + float fDistance = GetDistanceBetween(oCreature, oNPC); + + // If this is the first valid PC or the distance is less than the current minimum + if (fMinDistance == -1.0f || fDistance < fMinDistance) + { + fMinDistance = fDistance; + oClosestPC = oCreature; + } + } + + oCreature = GetNextObjectInArea(oArea); // Get the next object in the area + } + + return oClosestPC; // Return the closest PC +} + +// Function to notify the player that their pizza is ready and spawn the pizza item with the custom toppings +void PizzaReady(object oPC, int nOrderNumber, string sPizzaToppings) +{ + object oArea = GetArea(oPC); // Assuming the spawner is in the same area as the player + object oPizzaSpawner = GetFirstObjectInArea(oArea); + while (GetIsObjectValid(oPizzaSpawner)) + { + if (GetTag(oPizzaSpawner) == "CAS_PIZZASPAWNER") + { + break; + } + oPizzaSpawner = GetNextObjectInArea(oArea); + } + + if (!GetIsObjectValid(oPizzaSpawner)) + { + return; // Spawner not found + } + + // Create the custom pizza item + object oPizzaItem = CreateItemOnObject(RESREF_PIZZA_ITEM, oPizzaSpawner); + if (GetIsObjectValid(oPizzaItem)) + { + // Set the name and description of the pizza to include the order number and toppings + SetName(oPizzaItem, "Custom Pizza Order #" + IntToString(nOrderNumber)); + string sDescription = "This pizza contains the following toppings: " + sPizzaToppings; + SetDescription(oPizzaItem, sDescription); + } +} + +// Function to handle pizza order and process custom toppings +void OrderPizza(object oPC) +{ + // Find the NPC handling the orders (C_CAS_PIZZANPC) in the area (A_CAS_HELLS_KITCHE) + object oOrderNPC = FindNPCInArea("C_CAS_PIZZANPC", TAG_HELLS_KITCHE); + if (!GetIsObjectValid(oOrderNPC)) + { + AssignCommand(oOrderNPC, ActionSpeakString("The pizza NPC could not be found in the area.", TALKVOLUME_TALK)); + return; + } + + // Check if the player has enough gold + if (GetGold(oPC) < GOLD_COST_PER_PIZZA) + { + AssignCommand(oOrderNPC, ActionSpeakString("You do not have enough gold to order this pizza.", TALKVOLUME_TALK)); + return; + } + + // Charge the player for the pizza + TakeGoldFromCreature(GOLD_COST_PER_PIZZA, oPC, TRUE); + + // Get the current order number and increment it + int nCurrentOrderNumber = GetLocalInt(oOrderNPC, "nNumberOfOrders") + 1; + SetLocalInt(oOrderNPC, "nNumberOfOrders", nCurrentOrderNumber); + + // Initialize the toppings list + string sToppingsList = ""; + + // Fetch the stored toppings from C_CAS_PIZZANPC (the order NPC) + int i; + for (i = 1; i <= 5; i++) // Loop through sTopping1 to sTopping5 + { + string sTopping = GetLocalString(oOrderNPC, "sTopping" + IntToString(i)); + if (sTopping != "") + { + sToppingsList += sTopping; + if (i < 5 && GetLocalString(oOrderNPC, "sTopping" + IntToString(i + 1)) != "") + { + sToppingsList += ", "; // Add a comma separator unless it's the last topping + } + } + } + + // Confirm the selected toppings + AssignCommand(oOrderNPC, ActionSpeakString("Your selected toppings are: " + sToppingsList, TALKVOLUME_TALK)); + + // Announce the order + AssignCommand(oOrderNPC, SpeakString("Custom pizza order! Toppings: " + sToppingsList, TALKVOLUME_TALK)); + + // NPC actions during pizza preparation + object oPrepChef = GetObjectByTag("CAS_PREP_CHEF"); + if (GetIsObjectValid(oPrepChef)) + { + DelayCommand(PIZZA_PREP_DELAY * 1.0, AssignCommand(oPrepChef, ActionSpeakString("[Adds the following ingredients to the pizza: " + sToppingsList + "].", TALKVOLUME_TALK))); + } + + object oDarg = GetObjectByTag("cas_DargtheDretch"); + if (GetIsObjectValid(oDarg)) + { + DelayCommand(PIZZA_PREP_DELAY * 2.0, AssignCommand(oDarg, ActionSpeakString("[Shoves the prepared pizza into the oven.]", TALKVOLUME_TALK))); + DelayCommand(PIZZA_PREP_DELAY * 2.5, AssignCommand(oDarg, ActionSpeakString("[Yanks the pizza from the oven, pushing it through a hole in the wall into the display for the customer]", TALKVOLUME_TALK))); + } + + // Final announcement and pizza spawn, passing the selected toppings for the pizza description + DelayCommand(PIZZA_PREP_DELAY * 2.6, AssignCommand(oOrderNPC, PizzaReady(oPC, nCurrentOrderNumber, sToppingsList))); +} + +// Function to store topping selections on C_CAS_PIZZANPC +void StoreToppingsOnNPC(object oPC, string sTopping) +{ + // Find the NPC handling the orders (C_CAS_PIZZANPC) in the area (A_CAS_HELLS_KITCHE) + object oOrderNPC = FindNPCInArea("C_CAS_PIZZANPC", TAG_HELLS_KITCHE); + if (!GetIsObjectValid(oOrderNPC)) + { + AssignCommand(oOrderNPC, ActionSpeakString("The pizza NPC could not be found in the area.", TALKVOLUME_TALK)); + return; + } + + int nToppingCount = GetLocalInt(oOrderNPC, "ToppingCount"); + + // Check if the topping count has reached the maximum limit + if (nToppingCount >= 5) + { + AssignCommand(oOrderNPC, ActionSpeakString("You can only select up to 5 toppings.", TALKVOLUME_TALK)); + return; + } + + nToppingCount++; // Increment topping count + SetLocalString(oOrderNPC, "sTopping" + IntToString(nToppingCount), sTopping); // Store topping on NPC + SetLocalInt(oOrderNPC, "ToppingCount", nToppingCount); // Update topping count on NPC + + AssignCommand(oOrderNPC, ActionSpeakString(sTopping + " added to your pizza.", TALKVOLUME_TALK)); +} + +// Main function to start the pizza order by finding the closest PC to the NPC in A_CAS_HELLS_KITCHE +void main() +{ + // Find the NPC handling the orders (C_CAS_PIZZANPC) in the area (A_CAS_HELLS_KITCHE) + object oOrderNPC = FindNPCInArea("C_CAS_PIZZANPC", TAG_HELLS_KITCHE); + if (!GetIsObjectValid(oOrderNPC)) + { + return; // Exit if the NPC is not found + } + + // Find the closest player to the NPC in the same area + object oClosestPC = FindClosestPCInArea(oOrderNPC, TAG_HELLS_KITCHE); + if (!GetIsObjectValid(oClosestPC)) + { + return; // Exit if no player is found in the area + } + + // Example of ordering a pizza (assuming toppings are already stored) + OrderPizza(oClosestPC); +}