khmp Posted August 8, 2014 Share Posted August 8, 2014 (edited) Neophyte to papyrus scripting would be an understatement. Gleaning as I go. Not knowing enough and still plunging into the dark unknown. I am attempting to make a generic sorting routine for items. Similar to the Schoolhouse Base mod by Mike Hancho, et al of course. While I love them and the idea behind them - I wanted to go a bit deeper. Something that is "mostly generic" and by only being given an item's properties, sort it effectively. For example:"Ah that's Super Bouncing Stretch Armstrong Mk2 from Mk2 Destructo mod. The Form ID says it's a weapon and more specifically a mine. Let me put that in the mine box. No need for a form list or prior knowledge of the mod's existence to get that stuff on lock." If this has been done before can you point the way otherwise please continue reading. My question: Is there an easy way to determine whether or not the object you are looking at (rCurrentObject in the code) is equipped on your character? That's the gist of my issue. Here's the relevant snippet: short nPos ; Position in the container through which we are iterating short nFormItemType ; Type of the item we are currently on during iteration (Form Type ID) ref rCurrentObject ; The current object we are looking in the player's inventory set nPos to player.GetNumItems while (nPos) ; Define the position thereby the object we want to examine let nPos -= 1 set rCurrentObject to player.GetInventoryObject nPos set nFormItemType to GetType rCurrentObject ; Form Type ID comparison tests if (nFormItemType == 24) ; Armor Check ; Are we wearing this piece of armor? ;... endif loopMy fear is that I will have to compare the object against each equipment slot (20) for each and every item that is considered armor. While certainly doable I cringe at long potentially unnecessary if elseif elseif elseif...zzz statements. I figured I would ask for advice before going to sleep and cross my fingers. If you see something out of place please feel free to correct or question. :blush: <- guarded optimist? Edited August 8, 2014 by khmp Link to comment Share on other sites More sharing options...
jazzisparis Posted August 8, 2014 Share Posted August 8, 2014 GetEquipped Link to comment Share on other sites More sharing options...
khmp Posted August 10, 2014 Author Share Posted August 10, 2014 *Charlie Brown Augh* The description fits exactly what I was looking for. I have no idea how but I only ever saw GetEquippedObject. This will shorten the code down immensely. Thank you ever so much jazzisparis. :) Link to comment Share on other sites More sharing options...
luthienanarion Posted August 10, 2014 Share Posted August 10, 2014 If you need to check for more than one item, you can pass a form list of those items instead of calling GetEquipped on each of them individually. Link to comment Share on other sites More sharing options...
khmp Posted August 10, 2014 Author Share Posted August 10, 2014 (edited) If you need to check for more than one item, you can pass a form list of those items instead of calling GetEquipped on each of them individually.Thanks for the input luthienanrion. I assume you mean using RemoveAllTypedItems because of the formlist? And 100% agree that it is very concise and easy on the eyes. There are two issues though that I couldn't bypass without a bit of trickery. And please correct me as I move forward if my thinking is off. The first being that I don't want to remove the items I have equipped. It was my major bug-a-boo with sorting mods I had encountered and the reasoning behind my personal venture to learn. But if I still wanted to use it which I have thought of doing, I would first have to move my equipped items into a temporary container. Then call removealltypeditems and then shift my equipment back and re-equip. Second but more importantly. My demand is not having to rely on a formlist (list of known inventory objects) not for the sake of obstinacy but rather the fear of missing items outside the scope of this mod. For example: "Mod Y introduces X armor. But the FormList only takes into account Z armor." Now I say that because AFAIK I cannot generate a formlist dynamically in game and have it save some level of permanancy without creating an overhead "runonce" script. But for the sake of learning if you have the time/will could you explain how you would go about it. I'm at my "sponge" settting in regards to scripting so impress and mold how you like XD [edit]As I sit back and think about it some more... If I could potentially "exclude" items on the fly from a dynamically generated formlist, assuming I only have 1 of any particular piece, it would and could work. Edited August 10, 2014 by khmp Link to comment Share on other sites More sharing options...
luthienanarion Posted August 11, 2014 Share Posted August 11, 2014 I literally meant passing a form list to GetEquipped: if(actor.GetEquipped AllPowerArmor)Err... I have an NVSE plugin with functions that let you access all loaded forms and put them in lists. Link is in my signature if you're interested in that sort of thing. Link to comment Share on other sites More sharing options...
khmp Posted August 12, 2014 Author Share Posted August 12, 2014 I literally meant passing a form list to GetEquipped: if(actor.GetEquipped AllPowerArmor)Err... I have an NVSE plugin with functions that let you access all loaded forms and put them in lists. Link is in my signature if you're interested in that sort of thing. The official wiki does not mention that it can accept formlists as an argument. Overridden/extended by NVSE? My apologies for the presumption before. And yes I am interested. Downloading your plugin now. Just to be clear, I can create a list dynamically taking into account all the mods I have loaded during run time - in turn, I can then use that list for comparison testing using your plugin? I hope that question is as clear as I think it sounds :laugh: Link to comment Share on other sites More sharing options...
luthienanarion Posted August 13, 2014 Share Posted August 13, 2014 My own mods check for equipped items using form lists extensively, so I can assure you that it works. That's what the GetLoadedType function does, yes. In answer to your original question, NVSE 4.5b6 added an IsEquipped function that can be called on an inventory reference to determine if it's currently equipped or not. You can find it here. Link to comment Share on other sites More sharing options...
khmp Posted August 13, 2014 Author Share Posted August 13, 2014 How convenient as I look at the release date. Bookmarking the link. I had no idea development was still going on. Thank you for answering all these tangents luthienanarion. Back to reading. Have a good week. :) Link to comment Share on other sites More sharing options...
Recommended Posts