Aller au contenu

Photo

Help with removing inventory items


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
Ed Venture

Ed Venture
  • Members
  • 102 messages
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

#2
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<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>

#3
ffbj

ffbj
  • Members
  • 593 messages
or just say != nArmor then get the next item until you get armor then destroy it.

#4
Terrorble

Terrorble
  • Members
  • 194 messages
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 .


#5
Ed Venture

Ed Venture
  • Members
  • 102 messages
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

#6
ffbj

ffbj
  • Members
  • 593 messages
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.