Author Topic: bookcase help  (Read 316 times)

Legacy_Surek

  • Full Member
  • ***
  • Posts: 169
  • Karma: +0/-0
bookcase help
« on: September 08, 2012, 01:19:31 am »


                Its been along time since I have played NWN but I’m glad I’m back.
I apologize ahead of time my scripting knowledge is a bit rusty.On to the matter at hand, I am having trouble scripting something and would like some help.
This script is called from a conversation under the actions taken tab
I have the conversation set up like this.
Search the bookcaseYes.No.When someone clicks on yes I would like them to get an item in their inventory but only a 50% chance on getting the item.  I hope that makes sense. Any help would be appreciated
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
bookcase help
« Reply #1 on: September 08, 2012, 02:49:35 am »


               if(Random(2)) CreateItemOnObject(<item ref>, GetPCSpeaker());



Kato
               
               

               


                     Modifié par Kato_Yang, 08 septembre 2012 - 01:49 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
bookcase help
« Reply #2 on: September 08, 2012, 02:55:30 am »


               [Edit: thats what I get for being long winded... Kato beat me to it]

The function you need is CreateItemOnObject
You should check out the lexicon for other functions as well: 
http://palmergames.c...xicon_1_69.html 

That function will go in a script you create which is executed by the "Yes" conversation option. And it will go in the "Main" of that script.

Since you also want a chance of this object showing up there are a number of ways to do this. The most straight forward is to wrap an if statement around the CreateItemOnObject function

Example (pseudo code)

void main()
{
   object oPC  = GetPCSpeaker(); 
   if(d2() ==1)
   {
      string sItemResref  = "enter_the_item_resref_here";
      CreateItemOnObject(sItemResref, oPC);
   }
   else
   {
      // PC does not get any item
     // perhaps a good place to provide a failure message as follows
        FloatingTextStringOnCreature(GetName(oPC)+" finds nothing on the "+GetName(OBJECT_SELF)+".", oPC);
   }
}
               
               

               


                     Modifié par henesua, 08 septembre 2012 - 01:56 .
                     
                  


            

Legacy_Surek

  • Full Member
  • ***
  • Posts: 169
  • Karma: +0/-0
bookcase help
« Reply #3 on: September 08, 2012, 03:35:09 am »


               Just wanted to thank both of you it works great.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
bookcase help
« Reply #4 on: September 09, 2012, 01:59:29 am »


               Make sure the conversation can only be done once, or the player will just keep doing it until they get the item, or they just keep getting the item over and over again.
You can prevent this by putting a local on the PC.