Author Topic: Inn Order  (Read 462 times)

Legacy_Kingdom_Of_Hearts

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Inn Order
« on: February 02, 2014, 02:51:48 pm »


               Hello! This is going off of a conversation asking to order. I am trying to get if the PC tells them an item on the menu, and they have the coins, they get the item. However, it is saying the message for if they don't have enough coins and order as well as taking the coins and giving them the items.

(Sorry that it is kind of long!) For some reason it was pasting weird here.

Script Here

Also having trouble at the end of the script. I can't figure out how to make it say if what they ordered wasn't on the menu, that it would have the innkeeper say a message to them.
               
               

               


                     Modifié par Kingdom_Of_Hearts, 02 février 2014 - 02:55 .
                     
                  


            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Inn Order
« Reply #1 on: February 02, 2014, 03:09:22 pm »


               I'd just put a

return;

after the gold is taken or not.

if (sSay == "chicken broth" && nGP >= 10)
{
 CreateItemOnObject("ChickenBroth", oPC, 1);
 TakeGoldFromCreature(10, oPC, TRUE);
 return;
}
if (sSay == "chicken broth" && nGP < 10)
{
 AssignCommand(OBJECT_SELF, SpeakString(sNoCoins));
 return;
}


FP!
               
               

               
            

Legacy_Kingdom_Of_Hearts

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Inn Order
« Reply #2 on: February 02, 2014, 03:14:17 pm »


               Awesome. Thanks! What about the end?
if (sSay is not  "seven kingdom mead" or "dwarven stout ale")
{
AssignCommand(OBJECT_SELF, SpeakString(sDontHave + sChat));
}
I am not sure what how to script what I wrote in! (Sorry for all the noobishness!)
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Inn Order
« Reply #3 on: February 02, 2014, 03:17:58 pm »


               Don't think it would make a difference, since it's the last check in the script for the conversation selection made.

FP!
               
               

               
            

Legacy_Kingdom_Of_Hearts

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Inn Order
« Reply #4 on: February 02, 2014, 03:20:32 pm »


               What I'm trying to do is notify that the PC isn't ordering something on the menu. Is there any way to script that anyways, just for a bit of flavor?
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Inn Order
« Reply #5 on: February 02, 2014, 03:28:57 pm »


               Well, just have a response for items not on the menu.

if (sSay  "blue berry raven pie" || "peanut butter cake" || "caramel ripple covered apples" || "banana muffins" || "sweet tarts")
{
AssignCommand(OBJECT_SELF, SpeakString(sDontHave + sChat));
}


and just continue adding what you don't have on the menu.

FP!
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
Inn Order
« Reply #6 on: February 02, 2014, 04:49:49 pm »


               Alternatively, after the first "if" statement change the remaining "if" statements to "else if" then for your final statement do this

else
{
   AssignCommand(OBJECT_SELF, SpeakString(sDontHave + sChat));
}
               
               

               
            

Legacy_Kingdom_Of_Hearts

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Inn Order
« Reply #7 on: February 02, 2014, 06:07:22 pm »


               Oh. That's right, thanks. I'm still a scripting noob. '<img'> Forgot about the ||

Edit:  Error: NSC1003: Operator (||) not valid for specified typesCompilation aborted with errors.

Edit: Is there any way to just make it say that if something said is not on the menu? Like if says anything but the items..
               
               

               


                     Modifié par Kingdom_Of_Hearts, 02 février 2014 - 06:09 .
                     
                  


            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Inn Order
« Reply #8 on: February 02, 2014, 07:40:17 pm »


               Sorry, I didn't put in the ==

if (sSay == "blue berry raven pie" || "peanut butter cake" || "caramel ripple covered apples" || "banana muffins" || "sweet tarts")
{
AssignCommand(OBJECT_SELF, SpeakString(sDontHave + sChat));
}


Additionally, you could just put all your food items in the last one and change == to !=.

if (sSay != "chicken broth" || "slice of bread" || "cheese" || "local fish" || "strongberry wine" || "dwarven stout ale" || "seven kingdom mead")
{
AssignCommand(OBJECT_SELF, SpeakString(sDontHave + sChat));
}


If you don't want to go this route, then go the route Pstemarie suggested.

   

    void main()
    {
    object oPC = GetPCSpeaker();
    string sChat = GetLocalString(oPC, "LastSaid");
    string sSay = GetStringLowerCase(sChat);
    int nGP = GetGold(oPC);
    string sNoCoins = GetLocalString(OBJECT_SELF, "NoCoins");
    string sDontHave = GetLocalString(OBJECT_SELF, "DontHave");
    /*Chicken Broth  - 10 GP
    Slice of Bread  - 8 GP
    Loaf of Bread   - 25 GP
    Cheese            - 15 GP
    Local Fish        - 12 GP
    */
    if (sSay == "chicken broth" && nGP >= 10)
    {
      CreateItemOnObject("ChickenBroth", oPC, 1);
      TakeGoldFromCreature(10, oPC, TRUE);
      return;
    }
    else if (sSay == "chicken broth" && nGP < 10)
    {
      AssignCommand(OBJECT_SELF, SpeakString(sNoCoins));
      return;
    }
    
    
    else if (sSay == "slice of bread" && nGP >= 8)
    {
      CreateItemOnObject("SliceOfBread", oPC, 1);
      TakeGoldFromCreature(8, oPC, TRUE);
      return;
    }
    else if (sSay == "slice of bread" && nGP < 8)
    {
      AssignCommand(OBJECT_SELF, SpeakString(sNoCoins));
      return;
    }
    
    else if (sSay == "cheese" && nGP >= 15)
    {
      CreateItemOnObject("Cheese", oPC, 1);
      TakeGoldFromCreature(15, oPC, TRUE);
      return;
    }
    else if (sSay == "cheese" && nGP < 15)
    {
      AssignCommand(OBJECT_SELF, SpeakString(sNoCoins));
      return;
    }
    
    
    else if (sSay == "local fish" && nGP >= 12)
    {
      CreateItemOnObject("LocalFish", oPC, 1);
      TakeGoldFromCreature(12, oPC, TRUE);
      return;
    }
   
    /*   Drinks
    Strongberry Wine         - 18 GP
    Dwarven Stout Ale       - 12 GP
    Seven Kingdom Mead  - 15 GP
    */
    
    
    else if (sSay == "strongberry wine" && nGP >= 18)
    {
      CreateItemOnObject("StrongberryWine", oPC, 1);
      TakeGoldFromCreature(18, oPC, TRUE);
      return;
    }
    else if (sSay == "strongberry wine" && nGP < 18)
    {
      AssignCommand(OBJECT_SELF, SpeakString(sNoCoins));
      return;
    }
    
    else if (sSay == "dwarven stout ale" && nGP >= 12)
    {
      CreateItemOnObject("DwarvenStoutAle", oPC, 1);
      TakeGoldFromCreature(12, oPC, TRUE);
      return;
    }
    else if (sSay == "dwarven stout ale" && nGP < 12)
    {
      AssignCommand(OBJECT_SELF, SpeakString(sNoCoins));
      return;
    }
    
    else if (sSay == "seven kingdom mead" && nGP >= 15)
    {
      CreateItemOnObject("SevenKingdomMead", oPC, 1);
      TakeGoldFromCreature(15, oPC, TRUE);
      return;
    }
    else if (sSay == "seven kingdom mead" && nGP < 15)
    {
      AssignCommand(OBJECT_SELF, SpeakString(sNoCoins));
      return;
    }
    
    else
    {
     AssignCommand(OBJECT_SELF, SpeakString(sDontHave + sChat));
    }
    
    }


Also, you have two checks for "cheese". One check <= 15 and the other <=12. I removed one in the above script.

FP!
               
               

               


                     Modifié par Fester Pot, 02 février 2014 - 07:43 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Inn Order
« Reply #9 on: February 02, 2014, 08:01:46 pm »


               

Fester Pot wrote...

Sorry, I didn't put in the ==

if (sSay == "blue berry raven pie" || "peanut butter cake" || "caramel ripple covered apples" || "banana muffins" || "sweet tarts")
{
AssignCommand(OBJECT_SELF, SpeakString(sDontHave + sChat));
}


Additionally, you could just put all your food items in the last one and change == to !=.

if (sSay != "chicken broth" || "slice of bread" || "cheese" || "local fish" || "strongberry wine" || "dwarven stout ale" || "seven kingdom mead")
{
AssignCommand(OBJECT_SELF, SpeakString(sDontHave + sChat));
}

This won't work as written. You need to have a valid expression for each section of the OR:

if (sSay == "chicken broth"     ||
    sSay == "slice of bread"    ||
    sSay == "cheese"            ||
    sSay == "local fish"        ||
    sSay == "strongberry wine"  ||
    sSay == "dwarven stout ale" ||
    sSay == "seven kingdom mead")

               
               

               


                     Modifié par Squatting Monk, 02 février 2014 - 08:04 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Inn Order
« Reply #10 on: February 02, 2014, 08:45:03 pm »


               Coupla more things. First, you don't need to assign commands to OBJECT_SELF. OBJECT_SELF is the doer of commands by default.

Secondly, by using a few variables, you can greatly simplify this script and reduce code duplication. In this version I set the price and resref of the item depending on the item being ordered, then call CreateItemOnObject() only once.

void main()
{
    object oPC   = GetPCSpeaker();
    string sChat = GetLocalString(oPC, "LastSaid");

    /*
    Food
    Chicken Broth      - 10 GP
    Slice of Bread     - 8 GP
    Loaf of Bread      - 25 GP
    Cheese             - 15 GP
    Local Fish         - 12 GP

    Drinks
    Strongberry Wine   - 18 GP
    Dwarven Stout Ale  - 12 GP
    Seven Kingdom Mead - 15 GP
    */

    // Sanity check
    if (sChat == "") 
    {
        FloatingTextStringOnCreature("You didn't order anything!", oPC, FALSE);
        return;
    }

    // Check if the PC's order matches any of the available items.
    int    nCost;
    string sResRef;
    string sSay = GetStringLowerCase(sChat);

    if (sSay == "chicken broth")
    {
        sResRef = "ChickenBroth";
        nCost   = 10;
     }
    else if (sSay == "slice of bread")
    {
        sResRef = "SliceOfBread";
        nCost   = 8;
    }
    else if (sSay == "cheese")
    {
        sResRef = "Cheese";
        nCost   = 15;
    }
    else if (sSay == "local fish")
    {
        sResRef = "LocalFish";
        nCost   = 12;
    }
    else if (sSay == "strongberry wine")
    {
        sResRef = "StrongberryWine";
        nCost   = 18;
    }
    else if (sSay == "dwarven stout ale")
    {
        sResRef = "DwarvenStoutAle";
        nCost   = 12;
    }
    else if (sSay == "seven kingdom mead")
    {
        sResRef = "SevenKingdomMead";
        nCost   = 15;
    }
    else
    {
        SpeakString(GetLocalString(OBJECT_SELF, "DontHave") + sChat);
        return;
    }

    // See if the PC has the required gold onhand and, if so, create the item.
    if (GetGold(oPC) >= nCost)
    {
        CreateItemOnObject(sResRef, oPC);
        TakeGoldFromCreature(nCost, oPC, TRUE);
    }
    else
        SpeakString(GetLocalString(OBJECT_SELF, "NoCoins"));
}

               
               

               


                     Modifié par Squatting Monk, 02 février 2014 - 08:53 .
                     
                  


            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Inn Order
« Reply #11 on: February 03, 2014, 12:06:40 am »


               Great work Mr. Monk! Certainly better than what I could ever do.

There's your cleaned up script, Kingdom_of_Hearts!

FP!
               
               

               
            

Legacy_Kingdom_Of_Hearts

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Inn Order
« Reply #12 on: February 03, 2014, 08:18:18 pm »


               Thank you! So much better.