Chemist18 Posted May 13, 2014 Share Posted May 13, 2014 Hello All :) I'm working on several containers that I want the player to only be able to add specific items to. To help make this compatible with other mods I'm using "Keywords" to filter items added. Below is the script I'm working on right now. I've created a FormList of Keywords because all the items won't have the same keywords. The Orange statements will be coming out once I'm satisfied it is working. The Green I added for this post. The Formlist looks like this:VendorItemSoulGemVendorItemJewelryVendorItemGemArmorJewelryClothingCircletClothingRingClothingNecklaceNote that it is possible for an item to be acceptable due to multiple keywords. In testing the container works exactly as I expected as long as the items aren't from another mod. For example: I use Left Hand Rings by duggelz. I wanted to make sure this container was compatible with his rings. I checked, each of the Left-handed rings has at least two of the acceptable keywords (ClothingRing, ArmorJewelry, and VendorItemJewelry) When I attempt to drop one of the left-handed rings into the bag, the script tells me that the item is acceptable but puts it back in my inventory anyway. Scriptname aaCh18_FilterOnKeywordFormlist extends ObjectReference FormList Property ElligibleKeywordsFLST AutoActor Property PlayerREF Auto Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) If akSourceContainer == PlayerREF Int iCount = ElligibleKeywordsFLST.GetSize() Bool bAcceptable = False (not acceptable by default) While iCount iCount -= 1 Keyword kReference = ElligibleKeywordsFLST.GetAt(iCount) as Keyword If akBaseItem.HasKeyWord(kReference) bAcceptable = true Debug.Messagebox("Acceptable " + kReference) (At this point bAcceptable is set to True and there should be no way for it to return to False) Endif EndWhile If bAcceptable == False RemoveItem(akBaseItem, aiItemCount, True, akSourceContainer) Debug.Messagebox("Invalid Item") Endif EndIf EndEvent Link to comment Share on other sites More sharing options...
jaxonz Posted May 13, 2014 Share Posted May 13, 2014 Looks good. I don't have that mod, but it may be that the left-handed rings are derived from normal rings and that the akBaseItem isn't actually pointing to the script with the attached keywords. Consider adding a test statement; if akBaseItem.GetNumKeywords() == 0 then akBaseItem = akBaseItem.GetObjectBase() I'm also not sure how you get the RemoveItem statement to compile without an object reference. Shouldn't that read Self.RemoveItem ? To make the script more efficient you might also want to add a statement that stops iteration in the While loop once bAcceptable is true. You can do this either by setting iCount = 0 or by adding && !bAcceptable to the While condition statement. Hope that helps. Link to comment Share on other sites More sharing options...
Chemist18 Posted May 13, 2014 Author Share Posted May 13, 2014 Absolutely that helps :). I wanted to jump out of the loop at "true" but was outthinking myself... Either of your suggestions will work fine :). Link to comment Share on other sites More sharing options...
Chemist18 Posted May 13, 2014 Author Share Posted May 13, 2014 While I'm at this, I wanted to create an "Enchanted Medicine Bag" for potions but I haven't the faintest idea how to allow crafted potions to be placed into it... Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 13, 2014 Share Posted May 13, 2014 While I'm at this, I wanted to create an "Enchanted Medicine Bag" for potions but I haven't the faintest idea how to allow crafted potions to be placed into it...If it is just for the player to add items to and spit items back out that do not match. Then all you need to do is add a check for the item being added to be a potion. ;... OnItemAdded eventIf !(akBaseItem as Potion);... return to playerElse;... keep themEndIf Then leave it to the player to decide if they want to mix poisons with potions. Link to comment Share on other sites More sharing options...
Chemist18 Posted May 14, 2014 Author Share Posted May 14, 2014 mm... so crafted potions can just be referenced as "Potion"? That's excellent :). There are a few people I've noticed that are very helpful and responsive in this community, you two are among them. I am grateful. I've been programming in one form or another for my own use for 30+ years but without the help you guys have offered me here I would have completely skipped Papyrus scripting. Link to comment Share on other sites More sharing options...
jaxonz Posted May 14, 2014 Share Posted May 14, 2014 We're happy to help. There's a pretty great modder community that continues to extend the game. I don't get the impression that Papyrus was originally intended to "go public" as a scripting language (poor documentation, limited functional access, quite a few bugs, no error handling). It can really be frustrating at times. Nonetheless, Papyrus is what the game content is built with and what we have to work with (unless you want to write a C++ extension). IMHO, all the more reason to help one another out. Link to comment Share on other sites More sharing options...
Recommended Posts