Author Topic: onInventoryDisturbed script  (Read 360 times)

Legacy_TrekSL

  • Newbie
  • *
  • Posts: 35
  • Karma: +0/-0
onInventoryDisturbed script
« on: July 21, 2011, 02:15:30 pm »


               Got a problem - basically I have a script where all I want it to do is that when three books are acquired (all have same tag) an effect is played and a variable changed. I've gone through lilac soul's on acquire item method and made sure everything is set up so that the books are a tagged module item. My problem is i don't know how to convert the module item in the script so it is counted as a value of nbooks which will then fire the 'if' statement script.

void main()
{

object oPC = GetModuleItemAcquiredBy();

object oItem;
oItem = GetModuleItemAcquired();
if (!GetIsPC(oPC)) return;

//int nBooks = oItem;

//int nBooks = GetNumItems(oPC, "Conjugation");

if (nBooks == 3)
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_HEALING_L),oPC, 0.0);
    SetLocalString(oPC, "hasbooks", "TRUE");

    return;
}
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
onInventoryDisturbed script
« Reply #1 on: July 21, 2011, 02:36:32 pm »


               Could try:

if( GetNumItems( oPC, "Conjugation" ) == 3)
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
onInventoryDisturbed script
« Reply #2 on: July 21, 2011, 02:40:17 pm »


               You may want to make sure that the acquiring of anything else does not accidently fire that by enclosing that in another if.

IE:

if( GetTag( oItem ) == "Conjugation" )
{
    if( GetNumItems( oPC, "Conjugation" ) == 3 )
    {
         // Do stuff here
    }
}
               
               

               
            

Legacy_TrekSL

  • Newbie
  • *
  • Posts: 35
  • Karma: +0/-0
onInventoryDisturbed script
« Reply #3 on: July 21, 2011, 02:54:10 pm »


               trying that - it returns no right bracket on expression for the second if statement (if's and nested if's confuse the heck out of me)

EDIT - ahh missed out an include
               
               

               


                     Modifié par TrekSL, 21 juillet 2011 - 02:09 .
                     
                  


            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
onInventoryDisturbed script
« Reply #4 on: July 21, 2011, 05:42:48 pm »


               you shouldn't use a LocalString , you should use a LocalInt. it doesn't make sense to save a string "TRUE" you should set it to true. Baragg safty step isn't good enough. the player can drop a book and pick it up again and fire the effect part each time.

Use your Local Variable as protection instead.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
onInventoryDisturbed script
« Reply #5 on: July 21, 2011, 06:17:28 pm »


               Here's a script that I use to allow a player to take up to 3 items out of a chest. While there are more choices available, they can only pick/take 3. Written for NWN2 so may need some edits. Also, this destroys any remaining inventory in the chest and then destroys the chest itself (used as a "reward chest"):

void main()
{
object oSelf = OBJECT_SELF; // This is the chest that has this script OnInventoryDisturbed
object oMasterPC = GetFirstPC(TRUE);
object oPC = GetFirstPC(FALSE);

int nRewardValue = 3;
int nCurrentValue = 0;

// If we have not yet taken 3 items from chest
if(nCurrentValue != nRewardValue)
   {
               // Add +1 each time an item is taken
   nCurrentValue += 1;
   SetLocalInt(oSelf, "CurrentValue", nCurrentValue);
   
   int nNewValue = GetLocalInt(oSelf, "CurrentValue");
               // If we have taken 3 items, close the GUI screen, destroy inventory and destroy chest
   if(nNewValue == nRewardValue)
      {
      CloseGUIScreen( oPC, "SCREEN_CONTAINER_DEFAULT");
      object oInv = GetFirstItemInInventory(oSelf);
      while(oInv != OBJECT_INVALID)
         {
         DestroyObject(oInv, 0.0, FALSE);
         
         oInv = GetNextItemInInventory(oSelf);
         }
         
      if(oInv == OBJECT_INVALID)
         {
         DestroyObject(oSelf, 0.0f, FALSE);
         }
      }
   }   
}
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
onInventoryDisturbed script
« Reply #6 on: July 21, 2011, 09:25:00 pm »


               Here's a tag based script for OnAcquire. Just give it the same name as the tag of your book. Should work:


#include "x2_inc_switches"
#include "nw_i0_plot"
void main()
{
    int iEvent = GetUserDefinedItemEventNumber();
    if (iEvent != X2_ITEM_EVENT_ACQUIRE) return;

    object oBook = GetModuleItemAcquired();
    object oPC = GetModuleItemAcquiredBy();

    if (GetNumItems(oPC, GetTag(oBook)) == 3)
    {
        ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_HEALING_L),oPC, 0.0);
        SetLocalString(oPC, "hasbooks", "TRUE");
    }
}
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
onInventoryDisturbed script
« Reply #7 on: July 22, 2011, 12:46:47 pm »


               

CID-78 wrote...

you shouldn't use a LocalString , you should use a LocalInt. it doesn't make sense to save a string "TRUE" you should set it to true. Baragg safty step isn't good enough. the player can drop a book and pick it up again and fire the effect part each time.

Use your Local Variable as protection instead.


Dag nab it, I forgot that they will be sneaky like that, lol.