Author Topic: Help with removing inventory items  (Read 314 times)

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Help with removing inventory items
« on: April 27, 2013, 02:33:38 am »


               I am lost and confused. I am building a mod for the paladin class. I am trying to come up with a script that will remove all magic items over the 10 allowed. In the first leg of the script I want to take all armor from thier inventory.
void main()
{
 object oPC = GetFirstPC();
 object oArmor = GetFirstItemInInventory(oPC);
 int  nArmor = BASE_ITEM_ARMOR;
 while(GetBaseItemType(oArmor)  == nArmor)
  {
    SetPlotFlag(oArmor,FALSE);
    DestroyObject(oArmor);
    oArmor = GetNextItemInInventory(oPC);
  }
}
This script compiles. In game it removes all armor except armor in a bag of holding. Lexicon calls it nested inventory. What is this idiot doing wrong ?                               Ed Venture
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Help with removing inventory items
« Reply #1 on: April 27, 2013, 03:46:17 am »


               <counting on...>

Looking at this, say the *second* item after the first bit of armor is *not* armor... what happens?
You've just destroyed the first piece. You get the next inventory item (lets say it's some rum (obscure reference)). The 'while' check triggers and... the item isn't armor so it drops through to the end of main().

You need an outer loop that will process all inventory and just use the inner loop for things that *are* armor.

<...his fingers>
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Help with removing inventory items
« Reply #2 on: April 27, 2013, 09:49:30 pm »


               or just say != nArmor then get the next item until you get armor then destroy it.
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Help with removing inventory items
« Reply #3 on: April 28, 2013, 12:31:08 am »


               Try...

void main()
{
 object oPC = GetFirstPC();
 object oArmor = GetFirstItemInInventory(oPC);
 while(GetIsObjectValid(oArmor))
{
 if( GetBaseItemType(oArmor) == BASE_ITEM_ARMOR )
  {
    SetPlotFlag(oArmor,FALSE);
    DestroyObject(oArmor);
  }
 oArmor = GetNextItemInInventory(oPC);
}
 if( GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_CHEST,oPC)) )
 {
    SetPlotFlag(oArmor,FALSE);
    DestroyObject(oArmor);
 }    
}

Naming  the variable oArmor when you are setting it equal to GetFirstItemInInventory() is misleading.  In this case, oArmor is equal to whatever the first item is.  Purely my preference, but I generally use oItem in an instance like this.
Also, you may need to check if they have an armor equiped already and destroy that too.  Hope that helps.
               
               

               


                     Modifié par Terrorble, 27 avril 2013 - 11:37 .
                     
                  


            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Help with removing inventory items
« Reply #4 on: April 28, 2013, 02:56:58 am »


               Thank you all. Adding the if/else statement did the trick. I am so glad that there are people out there that are still willing to help out new builders.
Terrorble, I use oArmor because the script also removes oBelt oBoots ect. I do not want to completely strip the paladin. I just want them in the 10 items or less line.
I bow to you all.                                                Ed Venture
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Help with removing inventory items
« Reply #5 on: April 29, 2013, 10:20:15 pm »


               Yeah I get that.  I did something similar with artifacts, something about how they conflict with each-other.  So only 1 artifact can be equipped at one time.  I thought of making an exception for item sets, but since I don't have any it would be irrelevant.