xkkmEl Posted January 25 Share Posted January 25 So I open a chest, I see 20g and pick it up. A few seconds later, I have a script that looks at the content of the chest and reports there are 20g in it (!?!). But when I go back, as Dragonborn, to check on the chest, it actually is empty (Doh!). What's going on? How should I proceed to get an accurate count? I tried updating my script to add a marker to the chest and then waiting a tiny amount before looking at the content, hoping it would force the game engine to update its view of the chest content, but the script still sees 20g. This only happens with gold. The other item counts are correct. I use chest.getItemCount( Gold001) to count gold, just like all the other items my script is interested in. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 26 Share Posted January 26 Sometimes with pre-placed items, papyrus is unable to accurately see what is inside until the container has been opened and accessed by the player. So I am not sure why your script would be reporting something that was in there after the player has removed the items. If you will be running with SKSE, you could try seeing what results you get by using GetNumItems and GetNthForm on the container and use that result with GetItemCount instead of explicitly checking for an item. Link to comment Share on other sites More sharing options...
xkkmEl Posted January 26 Author Share Posted January 26 Strangely, that is exactly what I am currently doing... cur.addItem( qvDhOF_LootedMarker) int ngold = 0 int nitems = 0 int ntotal = 0 int i = cur.getNumItems() while i i -= 1 Form item = cur.getNthForm( i) int c = cur.getItemCount( item) if c <= 0 elseif item == Gold001 ;ngold += c ngold += cur.getItemCount( item) elseif __isPlayable( item) ntotal += c if qvDhQ_Collector.isLootable( item) nitems += c endif endif endwhile if ngold || nitems qvDhMFX_SpottedGreen.stop( cur) qvDhMFX_SpottedRed.stop( cur) qvDhMFX_SpottedGreen.play( cur, -1) endif qvDhQ_Notification.collectContainer( "Spotted", cur, ngold, nitems, ntotal) Some time before running that, I add and remove a DummyDagger to force-populate the inventory (it's part of a cell scan in which I build the list of containers to loot/inspect). I do not have an easy way of checking whether I empty the chest before or after the DummyDagger add/remove. For now I'll keep monitoring this behavior and see if I can correlate it with some other conditions. I am unsure whether it affects all containers all the time. Link to comment Share on other sites More sharing options...
PeterMartyr Posted January 26 Share Posted January 26 Because the script is really badly written, show me where in the script you remove the gold from the container or transfer it to the player. That is why, when you recheck it, it is still there Link to comment Share on other sites More sharing options...
xkkmEl Posted January 26 Author Share Posted January 26 The gold is not removed by the script, but by the player. The issue is that when the script runs after the player has emptied the container, it still sees gold, but if I return as the player, the chest actually is empty. The purpose of the script is only to report on the content and put an effectshader to attract the attention of the player if the content is interesting. Link to comment Share on other sites More sharing options...
PeterMartyr Posted January 26 Share Posted January 26 OH use states once the player emptied the chest, so the script does not run Edit Not sure if your aware of Big O Notation, but your script does not need a loop, you're making it too complicated if chest.getItemCount(gold01) || chest.Find(item) qvDhMFX_SpottedGreen.stop( cur) qvDhMFX_SpottedRed.stop( cur) qvDhMFX_SpottedGreen.play( cur, -1) endif code not tested and Find might be just for Arrays ¯\_(ツ)_/¯ Just to show you example of how code can be improved, with Big O Notation Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 26 Share Posted January 26 Find is a function usable with form lists. However, it returns the index entry of the item. It cannot be used to find something within a container. The contents are not initially in an accessible array or formlist. SKSE is capable of treating the contents as an array or formlist by first getting the total number of items with GetNumItems and then iterate through the items with GetNthForm. This is what xkkmEl is doing. The alternative is to just use GetItemCount with each individual possible item and hope that it returns a non-zero value. If it is a small number of items, checking for each one directly with GetItemCount would be acceptable. However, for larger quantities, iterating through the contents will be much faster. Not every situation will benefit from simpler methods. Link to comment Share on other sites More sharing options...
xkkmEl Posted January 26 Author Share Posted January 26 (edited) So I've been scratching my head over this for two weeks. And just now I enter a draugr crypt and things start to clear up... First three chests I encounter, I rush to inspect their content before my script does. I do "take all", "take only gold" and "take all but gold" respectively. In all three cases, my script reports exactly 20g more than there are! Huh? Next two chests, I do the same but also check them out with the console. They are baseId 0x20670 "TreasDraugrChest" and their console inventory shows an INVALID 20-count item in each case. Haha! I recheck the first three and see the same. xEdit reveals that the container form 0x20670 as a content template with "20 gold001", and a bunch of leveleditems. This is a bit peculiar; I could find no other vanilla treasure chest forms containing anything other than leveleditems (though there are quite a few examples in non treasure chests). I figure this is the culprit. Dunno what to do about it though.... I imagine the console reports them as invalid because they are either disabled or deleted, but inside a chest neither of these two conditions can be tested. Erratum: the console inventory shows "BAD EDITOR ID" without a count. Edited January 26 by xkkmEl Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 26 Share Posted January 26 It does seem to be the cause. I cannot think of a clean way to work around this, however. Link to comment Share on other sites More sharing options...
xkkmEl Posted January 26 Author Share Posted January 26 When I started modding Skyrim, I must have missed the sign "Abandon every hope, all ye who enter here." Or was it when I first got into computers? Link to comment Share on other sites More sharing options...
Recommended Posts