Greslin Posted March 13, 2017 Share Posted March 13, 2017 (edited) Okay, I'm out of ideas here. I did a fair amount of scripting in FNV, skipped Skyrim altogether, and am now trying to get around the corners of Papyrus with FO4. And at this point my brain is just plain busted, over what seems to me should be a really simple script. I'm trying to get an accurate Stimpak inventory count from a companion at bleedout. Current code, attached to the Piper NPC record: Scriptname CA_CheckStimpak extends ReferenceAlias const Potion Property Stimpak Auto Const Event OnEnterBleedout() StimpakCheck() endEvent function StimpakCheck() actor actorRef = getActorRef() Int curStims = actorRef.GetItemCount(Stimpak) Debug.Notification("BLEEDOUT - w/" + curStims + " stims") endFunction I load up the game. Piper has 10 stimpaks in her inventory. I shoot Piper in the head, she goes down with immediate bleedout. The OnEnterBleedout() event fires just fine. I get the notification message with a zero stimpak count. I've tried extending ReferenceAlias, Actor, and ObjectReference. I've tried doing this via perk/MGEF, and I've tried attaching the script to her companion quest (ala the Jack Cabot MS09 script, which does basically this same thing - but works). The event fires, but I can't get the accurate number. In some cases, when I don't get a zero, I get 356. She has 10. That led me to wonder if, in these cases, I'm getting a count of ALL Stimpaks currently loaded in the game world. Or if I'm getting something significantly wrong with the actor reference, and am pulling some junk integer data from misplaced memory somewhere. In any case, no matter what I do, I get back either zero or 356. I know I'm missing something obvious and stupid, and am just too close to it now. Could someone please save me the pain and embarrassment of continuing to trip over my own shoelaces here? :smile: Edited March 13, 2017 by Greslin Link to comment Share on other sites More sharing options...
Greslin Posted March 13, 2017 Author Share Posted March 13, 2017 Incidentally, this is the code that gives me the 356 result. Also attached to the NPC record. Scriptname CA_AutoStimpak extends Actor Potion Property Stimpak Auto Int curStims Event OnEnterBleedout() StimpakCheck() endEvent function StimpakCheck() curStims = GetItemCount(Stimpak) Debug.Notification("BLEEDOUT - w/" + curStims + " stims") endFunction Like I said, I feel like I'm missing something really basic with the actorrefs here. The property in CK is manually set to the stimpaks potion record. Thanks in advance to anyone who can help. Link to comment Share on other sites More sharing options...
shavkacagarikia Posted March 13, 2017 Share Posted March 13, 2017 Your script isnt working because it cant detect which actor you want to get item count from. You are using getactorref() bur thats used for reference alias and wont do anything for you. Paste this in your stimpackcheck function:Actor[] playerFollowers = Game.GetPlayerFollowers( ) int index = 0 while (index < playerFollowers.Length) playerFollowers[index].getItemCount(stimpack) index += 1 debug.notification("this actor has" + stimpack + "stimpacks) endWhile This will work even if you have multiple companions with you (there are mods which do that) and show stimpack count for each od them. Link to comment Share on other sites More sharing options...
Greslin Posted March 13, 2017 Author Share Posted March 13, 2017 (edited) Good point about multiple companions, thanks. Unfortunately your solution still gets me that strange 356 Stimpaks number (when Piper only has 10). Current code, attached to Piper NPC: Scriptname CA_AutoStimpak extends Actor Potion Property Stimpak Auto Const Int curStims Event OnEnterBleedout() StimpakCheck() endEvent function StimpakCheck() Actor[] playerFollowers = Game.GetPlayerFollowers( ) int index = 0 while (index < playerFollowers.Length) curStims = playerFollowers[index].getItemCount(Stimpak) index += 1 debug.notification("this actor has " + curStims + " stimpaks") endWhile endFunction I would also need to apply some sort of check in there to isolate the stimpak count for one particular follower, but that's a separate problem. Right now I'd be ecstatic with accurate counts, even if I had a list of them for everyone. I'm fairly confident now that we're getting the right Actor ref, so now I'm starting to wonder if the issue has something to do with how the Stimpak form ID is being passed to the script. The script property for Stimpak is manually set for the right potion record, as far as I can tell (name "Stimpak", type "Potion const", value "Stimpak (00023736)"). For the record, when I prid Piper in console and do a getitemcount from there, I get the correct 10 answer. This is really starting to bug me. Any other ideas? Edited March 13, 2017 by Greslin Link to comment Share on other sites More sharing options...
vkz89q Posted March 13, 2017 Share Posted March 13, 2017 Have you tried Debug.Trace instead of Debug.Notification? I found that sometimes Notification gives strange numbers but trace always works correctly. Link to comment Share on other sites More sharing options...
Greslin Posted March 13, 2017 Author Share Posted March 13, 2017 Nope, 356 according to the logs with debug.trace. I've also tried inserting logic that throws up the notification only if the returned value is 10, and then if it's 356. It's not a display error - the value reaching the notification line is Integer 356. Type casting maybe? This value is supposed to be an integer, isn't it? Link to comment Share on other sites More sharing options...
Greslin Posted March 13, 2017 Author Share Posted March 13, 2017 So here's the part that's really driving me insane at this point. This is the base script MS09JackAliasScript.psc, attached to the Jack Cabot quest: Scriptname MS09JackAliasScript extends ReferenceAlias Const Potion Property Stimpak Auto Const Event OnEnterBleedout() StimpakCheck() endEvent Event OnCombatStateChanged(Actor akTarget, int aeCombatState) if aeCombatState == 1 StimpakCheck() endif endEvent function StimpakCheck() MS09Script myQuest = GetOwningQuest() as MS09Script ; only during final battle, and Jack is friendly if myQuest.GetStageDone(1450) == true && myQuest.GetStage() < 1500 && myQuest.Mission3PlayerSidesWithCabots actor jack = getActorRef() if jack.GetItemCount(Stimpak) < 2 jack.AddItem(Stimpak) endif endif endFunction Presumably, it works. And other than being attached to the NPC rather than a quest (and yes, I've tried attaching it to the COMPiper quest, with no luck), I'm at a loss to see what I'm doing so differently. I've tried extending ReferenceAlias, as above, with no success. How the heck is this script getting a correct getitemcount() and mine isn't? Link to comment Share on other sites More sharing options...
vkz89q Posted March 13, 2017 Share Posted March 13, 2017 (edited) Hmmh, well I'm using something similiar.. I have npc with ton of ammo and player can't pickpocket him. Then, when he dies, I remove that ammo and put small amount instead so player won't loot 1000+ ammo. I'm doing this just because my npc is useless if someone is using mod with "NPCs use ammo" for common weapons. Here is my script and it "just works". The npc has ammo between my min and max ints. Scriptname XX:xxxxx extends ReferenceAlias Event OnDying(Actor akKiller) Actor tempActor = Self.GetReference() as Actor int ammoCount = tempActor.GetItemCount(AmmoToRemove) tempActor.RemoveItem(AmmoToRemove, ammoCount) int newCount = Utility.RandomInt(RandomMin, RandomMax) tempActor.AddItem(AmmoToRemove, newCount) EndEvent Ammo Property AmmoToRemove Auto Const Int Property RandomMin Auto Const Int Property RandomMax Auto Const Try using referencealias again, and try get count from Actor tempActor = Self.GetReference() as Actor ? You kinda do that with the actor array anyway but.. I dont know. And here comes to final question, are you testing on clean save? Save that is made before that script was in that save? If not, do that. Edit: Anyone wondering, yes, I found the "teammatedontuseammo" keyword later. Not sure if it works on hostile npcs tho. Edited March 13, 2017 by vkz89q Link to comment Share on other sites More sharing options...
shavkacagarikia Posted March 13, 2017 Share Posted March 13, 2017 Thats odd... I am using similar fragment in my mod and it works perfectly. Have you tried attaching the fragment Ive suggested to the reference alias of that actor? Link to comment Share on other sites More sharing options...
vkz89q Posted March 13, 2017 Share Posted March 13, 2017 Ok, I just tried this on my custom companion reference alias in quest: Scriptname XX:StimpakTest extends ReferenceAlias Potion Property Stimpak Auto Const Event OnEnterBleedOut() StimpakCheck() EndEvent function StimpakCheck() int stimcount = 0 Actor tempActor = Self.GetReference() as Actor stimcount = tempActor.GetItemCount(Stimpak) Debug.Notification("stims:"+stimcount) EndFunction I gave my companion 10 stimpaks and I had 4 in player inventory. First result says 29. Then I noticed I forgot to FILL the stimpak Property, so it was empty and took random item to count on. Then I filled the property and the result was 10 every time. Test on clean save and make sure your Properties are filled right. Link to comment Share on other sites More sharing options...
Recommended Posts