Author Topic: Some help with if and else statements....  (Read 508 times)

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Some help with if and else statements....
« on: February 07, 2016, 07:27:10 am »


               

okay I never really worked with this kind of scripting before so any help would be appreciated! 


 


so basically what I want is that the PC is able to feed animals at the zoo, though with the sharks there is a change they will bite!


 


I am honestly confused with how this work so I really hope to get some help here with this script so thanks in advance for those who help me figure this out '<img'> 


 




void main()

{

    // Get the PC who is in this conversation.

    object oPC = GetPCSpeaker();

 

    // Decide what to do based on a die roll.

    switch ( d20() )

    {

        case 1:

        {

            // Take "b_feed_Fish" from the PC.

            DestroyObject(GetItemPossessedBy(oPC, "b_feed_Fish"));

        } break;

        default:

        {

        }

    }

}

 

 



 



I know I probably did it wrong, so this is a very good learning experience '<img'> 



               
               

               
            

Legacy_Li'l Rose

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +0/-0
Some help with if and else statements....
« Reply #1 on: February 07, 2016, 01:12:37 pm »


               Actually case 1 should be the shark biting, as it will occur on a dice roll of 1. The case number refers to the number rolled on the dice. Default refers to any dice rolls not listed as case numbers. In this case it would be for dice rolls 2 to 20. Put your normal feeding in the default brackets.
               
               

               
            

Legacy_LoA_Tristan

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +0/-0
Some help with if and else statements....
« Reply #2 on: February 12, 2016, 11:26:11 pm »


               Whenever checking player's inventory, it is just a good habit to throw lines that prevent the rest of the script from running if a required object is not found. Inventories are such sensitive matters.

Both the OC and player-made modules are great showcases of the good old "drop your moneybags on the ground" trick to get out of actually paying fines, bribes, tips, etc.

Also has teh revision suggested by Li'l Rose


void main()
{
   // Get the PC who is in this conversation.
   object oPC = GetPCSpeaker();

   // Let's declare the fishfood object outside of the switch
   object oFishFood = GetItemPossessedBy(oPC, "b_feed_Fish");

   // ...And only take action if the fishfood exists
   if (oFishFood == OBJECT_INVALID) return;

   DestroyObject(oFishFood);

   // Decide what to do based on a die roll.
   switch ( d20() )
   {
      case 1:
         {
            Print("Shark Attack!!!");
            ApplyEffectToObject(0, EffectVisualEffect(VFX_FNF_UNDEAD_DRAGON), oPC);
         }
         break;
      default:
         {
            Print("Fish Successfully Fed.");
         }
         break;
   }
}