Problems with a couple of NVSE functions.

Post » Tue May 17, 2011 9:52 am

Hi guys,


It would appear that GetObjectType and Player.GetNumItems aren't working, always return 0.

I'm calling GetObjectType with a reference returned from GetHotKeyItem after checking that it's non-zero, like so:

set rItem to GetHotKeyItem Index;set ObjectType to rItem.GetObjectType;if ( ObjectType == 40 ) ; Weapon...   ; add reference to exception list here.endif


I'm cycling through the hotkey items for weapons prior to iterating the player's inventory to removing weapons from him into storage; I don't want to remove hotkey items.

In preparation for iterating, I'm calling GetNumItems to determine loop boundaries, like so:

set ListIndex to Player.GetNumItems - 1;...


GetNumItems is always returning 0.

Can anyone shed some light on what's going on here?

Thanks!
User avatar
Meghan Terry
 
Posts: 3414
Joined: Sun Aug 12, 2007 11:53 am

Post » Tue May 17, 2011 2:40 pm

Hard to tell exactly what's happening without more of your script. For instance this line "set rItem to GetHotKeyItem Index" I'm guessing index is a short variable? If so where are you setting it, if you just call it like that index == 0 which would return 0 for rItem. Maybe it's in some part of your script though.

Next I'm not sure GetNumberItems is supported in the current beta of NVSE unless you have a newer version that I don't have. I can't even compile a script using that function so something is strange there.
User avatar
Richus Dude
 
Posts: 3381
Joined: Fri Jun 16, 2006 1:17 am

Post » Tue May 17, 2011 3:40 pm

Hard to tell exactly what's happening without more of your script. For instance this line "set rItem to GetHotKeyItem Index" I'm guessing index is a short variable? If so where are you setting it, if you just call it like that index == 0 which would return 0 for rItem. Maybe it's in some part of your script though.

Next I'm not sure GetNumberItems is supported in the current beta of NVSE unless you have a newer version that I don't have. I can't even compile a script using that function so something is strange there.


I'm using the Beta 6 that everyone has, and GetNumItems does compile, although it's not documented; I found a reference to it in a script sample browsing this forum. As to Index, it's set to 1 before a label, incremented below the segment of code I showed, and jumps back to the label if <= 8. The NVSE documentation states that it gets hotkey slots 1 through 8. That one IS documented, and that part of the script works; I successfully enumerate the hotkeys. it's the GetNumItems and the GetObjectType that don't work...
User avatar
helen buchan
 
Posts: 3464
Joined: Wed Sep 13, 2006 7:17 am

Post » Tue May 17, 2011 10:15 am

Could be the way this line is phrased "set ListIndex to Player.GetNumItems - 1". Not sure you can tack on the - 1 like that. Try setting it without the -1, then below it do set ListIndex to ListIndex - 1

And ya it does compile I was using number not num.
User avatar
Amy Cooper
 
Posts: 3400
Joined: Thu Feb 01, 2007 2:38 am

Post » Tue May 17, 2011 4:10 am

rgr; I'll give that a try.

Thanks!
User avatar
Sherry Speakman
 
Posts: 3487
Joined: Fri Oct 20, 2006 1:00 pm

Post » Tue May 17, 2011 11:27 am

Use GetObjectType this way:

short iItemTyperef rItemset iItemType to GetObjectType rItem

User avatar
Ryan Lutz
 
Posts: 3465
Joined: Sun Sep 09, 2007 12:39 pm

Post » Tue May 17, 2011 4:30 am

Could be the way this line is phrased "set ListIndex to Player.GetNumItems - 1". Not sure you can tack on the - 1 like that. Try setting it without the -1, then below it do set ListIndex to ListIndex - 1

And ya it does compile I was using number not num.


I doubt that is his problem, as I'm current using the below code fragment and getting the correct number of items:

set iIndex to player.GetNumItems - 1Label 10set rCurrentItem to player.GetInventoryObject iIndexif (iIndex >= 0)	ShowMessage gccrMessageGeneralIntegerTest iIndex <-- This is how I know it's detecting the correct number of items	set nSetCapsAmount to GetValue rCurrentItem	set nSetCapsAmount to (nSetCapsAmount * fExchangeRate)	rCurrentItem.SetItemValue nSetCapsAmount	set iIndex to iIndex - 1	Goto 10endif


However, I'm having my own problem where this loop just keeps repeating since I see the same index value displayed over and over again... and I don't know why.

EDIT: If "Inventory walking functions" from the NVSE thread's Not Implemented list means GetInventoryObject, I think I might though. Would it compile despite not being implemented?
User avatar
Arrogant SId
 
Posts: 3366
Joined: Sat May 19, 2007 11:39 am

Post » Tue May 17, 2011 2:04 pm

@Glowcat
If the script is halting on one of these lines,

set nSetCapsAmount to GetValue rCurrentItem  rCurrentItem.SetItemValue nSetCapsAmount 



Then
set iIndex to iIndex - 1
will never execute

Since rCurrentItem is a Base Object, it's probably choking on the call by reference for SetItemValue.
User avatar
Justin Bywater
 
Posts: 3264
Joined: Tue Sep 11, 2007 10:44 pm

Post » Tue May 17, 2011 12:31 pm

@RickerHK Aha! Thank you so much! The loop started working after I fixed that.

EDIT: Though it seems to set the item's value across all saves until the game restarts. Is there a way to fix that?
User avatar
Lucky Boy
 
Posts: 3378
Joined: Wed Jun 06, 2007 6:26 pm

Post » Tue May 17, 2011 1:56 pm

@RickerHK Aha! Thank you so much! The loop started working after I fixed that.

EDIT: Though it seems to set the item's value across all saves until the game restarts. Is there a way to fix that?


Interesting; I knew syntactically the GetNumItems - 1 wasn't the problem. Anyone had any experience with GetObjectType? 40 is a weapon form according to the documentation, and that's what my condition needs to be. Always getting 0 from it.

Your code isn't much different from mine mechanically speaking.
User avatar
Symone Velez
 
Posts: 3434
Joined: Thu Sep 07, 2006 12:39 am

Post » Tue May 17, 2011 7:23 am

Interesting; I knew syntactically the GetNumItems - 1 wasn't the problem. Anyone had any experience with GetObjectType? 40 is a weapon form according to the documentation, and that's what my condition needs to be. Always getting 0 from it.

Your code isn't much different from mine mechanically speaking.


Ok, here we go; there are 2 ways to call GetObjectType;
set ItemType to rItem.GetOjectType;


and

set ItemType to GetObjectType rItem;


The second way works; the first isn't working for me.

Looks like problem solved.
User avatar
Lalla Vu
 
Posts: 3411
Joined: Wed Jul 19, 2006 9:40 am

Post » Tue May 17, 2011 6:55 am

@RickerHK Aha! Thank you so much! The loop started working after I fixed that.

EDIT: Though it seems to set the item's value across all saves until the game restarts. Is there a way to fix that?


If the values aren't in the savegame, then it's a limitation of what NVSE is currently capable of. A work-around could be using quest script variables to store the new values for items, then use GETGameLoaded at startup to reset the values. http://fose.silverlock.org/fose_command_doc.html#GetGameLoaded
User avatar
Skrapp Stephens
 
Posts: 3350
Joined: Mon Aug 06, 2007 5:04 am

Post » Tue May 17, 2011 1:36 am

If the values aren't in the savegame, then it's a limitation of what NVSE is currently capable of. A work-around could be using quest script variables to store the new values for items, then use GETGameLoaded at startup to reset the values. http://fose.silverlock.org/fose_command_doc.html#GetGameLoaded


Not needed, but thanks for the tip and info about NVSE.

The script only temporarily assigns values for the duration of a barter anyway. Once I take care of a logic error it should be good to go.
User avatar
jesse villaneda
 
Posts: 3359
Joined: Wed Aug 08, 2007 1:37 pm

Post » Tue May 17, 2011 5:30 am

Did I see someone reference a tutorial by Cipsis regarding Inventory items and such? I'd sure like to have a look at it, but need a link, if someone has it...?

Thanks, guys!
User avatar
Leanne Molloy
 
Posts: 3342
Joined: Sat Sep 02, 2006 1:09 am

Post » Tue May 17, 2011 7:40 am

Did I see someone reference a tutorial by Cipsis regarding Inventory items and such? I'd sure like to have a look at it, but need a link, if someone has it...?

Thanks, guys!

His tutorials are here, http://www.cipscis.com/fallout/tutorials/ but I didn't see anything for FOSE/NVSE inventory functions. I've done a bunch of inventory stuff in my FO3 mod. Was there something in particular you were looking for?


Edit: This stuff is still applicable http://cs.elderscrolls.com/constwiki/index.php/Walking_through_Items_in_an_Inventory
User avatar
Eddie Howe
 
Posts: 3448
Joined: Sat Jun 30, 2007 6:06 am

Post » Tue May 17, 2011 5:31 am

His tutorials are here, http://www.cipscis.com/fallout/tutorials/ but I didn't see anything for FOSE/NVSE inventory functions. I've done a bunch of inventory stuff in my FO3 mod. Was there something in particular you were looking for?


Edit: This stuff is still applicable http://cs.elderscrolls.com/constwiki/index.php/Walking_through_Items_in_an_Inventory


Appreciate the links, and yeah, there is something specific; I'm having problems with removing from a formlist; I use it to build a list on the fly of hotkeyed weapons so I don't remove them to storage. The removal works sometimes, the first time, but never a second; it gives me a CTD.

Here's the code; maybe you can spot something that's causing a problem; I've been fighting it for weeks now. The problem is in the loop at the bottom of the GameMode block; you'll see some extra code in a few places that I put in on hunches and haven't removed yet. Iv'e learned over 30 years of banging bits for a living to code defensively, and that applies in spades with TES script. If I comment out the clearing of the hotkeyItem list at the bottom, problem goes away, but that defeats the purpose. Sorry about the formatting; this code tag is kinda twitchy...

ScriptName WSTNWeaponsMoverScriptref rContainer;ref rItem;ref rBaseObject;int Button;int nItems;int ListIndex;int Count;int PlayerTotal;int ItemType;int tempIndex;float fWeaponHealth;short bActivated;Begin OnActivate	set rContainer to GetLinkedRef;	set bActivated to 1;	ShowMessage WSTNMsgWeapons;EndBegin GameMode	if ( bActivated )		set Button to GetButtonPressed;			if ( Button == 0 ) ; first option in menu is "Open it."			rContainer.Activate;			elseif ( Button == 1 )			; Get a list of weapons assigned to hotkeys; these			; will not be removed.			set ListIndex to 1;						label 10			set rItem to Player.GetHotKeyItem ListIndex;			if ( rItem )				set ItemType to GetObjectType rItem;				PrintToConsole "HKItem %n, type = %x", rItem, ItemType;				if ( ItemType == 40 )					ListAddForm WSTNHKItemList, rItem;				endif				set rItem to 0;			endif						set ListIndex to ListIndex + 1;			if ( ListIndex <= 8 )				goto 10;			endif			; Move all but the hotkeyed weapons into storage.			set nItems to Player.GetNumItems;			if ( nItems )				set nItems to ListGetCount WSTNHKItemList;				if ( nItems )					Player.RemoveAllTypedItems rContainer, 0, 1, 40, WSTNHKItemList;				else					Player.RemoveAllTypedItems rContainer, 0, 1, 40;				endif			endif			; Now clear the hotkey list.			set nItems to ListGetCount WSTNHKItemList;                                                     label 30			if ( nItems )                                                         printc "%x items in WSTNHKItemList", nItems;			    set rItem to ListGetNthForm WSTNHKItemList, 0;			    if ( rItem )			        printc "Removing %n", rItem;			        ListRemoveForm WSTNHKItemList, rItem;			        set rItem to 0;			    endif			    set nItems to nItems - 1;                                                         goto 30			endif ; ( nItems )		endif ; ( Button == 1 )		set bActivated to 0;	endif ;  ( bActivated )		End

User avatar
STEVI INQUE
 
Posts: 3441
Joined: Thu Nov 02, 2006 8:19 pm

Post » Tue May 17, 2011 4:45 am

Did I see someone reference a tutorial by Cipsis regarding Inventory items and such? I'd sure like to have a look at it, but need a link, if someone has it...?
I've only scanned the thread, but I noticed this and thought I'd point you to what you might have heard of.

In the http://www.cipscis.com/fallout/tutorials/loops.aspx#examples section of my http://www.cipscis.com/fallout/tutorials/loops.aspx tutorial, which can be accessed via the page RickerHK linked you to, is an example of how to use script extender functions to walk through the player's inventory.

Cipscis
User avatar
josh evans
 
Posts: 3471
Joined: Mon Jun 04, 2007 1:37 am

Post » Tue May 17, 2011 2:47 am

I suspect that some formlist functions are just as buggy in FNV as they were in FO3. The FNV Geck crashes when you remove the last item in a list - I wonder if this carries over into the engine, since they share libraries. For the FO3 script, I resorted to using two misc items - RHKNullItem and RHKBlankForm to make things work consistently.

When adding forms, I always used AddFormToFormList for the RHKNullItem so it would always be added at index 0, then a ListReplaceForm to replace the null item with my new item.

For reading back items, ListGetCount, ListGetFormIndex and ListGetNthForm worked fine

For clearing formlists, I would read back the list using ListGetNthForm. Then for each item would use ListReplaceForm and write RHKBlankForm over it. I would re-use the index count from when I added the items, in case there were trailing RHKBlanKForms from previous calls the routine - did not use ListGetCount. So now you have a formlist with however many duplicate RHKBlankForm items. These duplicate items are cleaned out of the list by the game engine after a save/exit game/reload - not sure when exactly. So it doesn't bloat.


I avoided the functions to remove items because of the CTD potential. I also avoided ListReplaceNthForm because sometimes it's index was off by 1 - I don't know under what conditions, but someone else reported the same behavior.

This is my experience with formlist functions ;)

Edit - forgot to mention the reason for adding the nullitem at the beginning and using ListReplaceForm was so that I could add multiple of the same item to a list. If that's not needed, then AddFormToFormList is all you need.
User avatar
JD bernal
 
Posts: 3450
Joined: Sun Sep 02, 2007 8:10 am

Post » Tue May 17, 2011 5:21 am

I suspect that some formlist functions are just as buggy in FNV as they were in FO3. The FNV Geck crashes when you remove the last item in a list - I wonder if this carries over into the engine, since they share libraries. For the FO3 script, I resorted to using two misc items - RHKNullItem and RHKBlankForm to make things work consistently.

When adding forms, I always used AddFormToFormList for the RHKNullItem so it would always be added at index 0, then a ListReplaceForm to replace the null item with my new item.

For reading back items, ListGetCount, ListGetFormIndex and ListGetNthForm worked fine

For clearing formlists, I would read back the list using ListGetNthForm. Then for each item would use ListReplaceForm and write RHKBlankForm over it. I would re-use the index count from when I added the items, in case there were trailing RHKBlanKForms from previous calls the routine - did not use ListGetCount. So now you have a formlist with however many duplicate RHKBlankForm items. These duplicate items are cleaned out of the list by the game engine after a save/exit game/reload - not sure when exactly. So it doesn't bloat.


I avoided the functions to remove items because of the CTD potential. I also avoided ListReplaceNthForm because sometimes it's index was off by 1 - I don't know under what conditions, but someone else reported the same behavior.

This is my experience with formlist functions ;)

Edit - forgot to mention the reason for adding the nullitem at the beginning and using ListReplaceForm was so that I could add multiple of the same item to a list. If that's not needed, then AddFormToFormList is all you need.


ah-hah! I thought I was doing something wrong; thank you for comfirming that I probably haven't been... This is a treasure trove of valuable information, and most appreciated! What did you use as RHKNullItem and RHKBlankForm?

It'd sure be nice if the NVSE crew would include a ListClear, so we don't have to waste so many cycles in script doing that...

BTW, are you planning on bringing Brisa over to NV? I'd love to have her here... :)
User avatar
Crystal Clarke
 
Posts: 3410
Joined: Mon Dec 11, 2006 5:55 am

Post » Tue May 17, 2011 9:50 am

I've only scanned the thread, but I noticed this and thought I'd point you to what you might have heard of.

In the http://www.cipscis.com/fallout/tutorials/loops.aspx#examples section of my http://www.cipscis.com/fallout/tutorials/loops.aspx tutorial, which can be accessed via the page RickerHK linked you to, is an example of how to use script extender functions to walk through the player's inventory.

Cipscis


Thank you Cipsis; greatly appreciated! :)
User avatar
Lakyn Ellery
 
Posts: 3447
Joined: Sat Jan 27, 2007 1:02 pm

Post » Tue May 17, 2011 5:18 am

As it turns out, there is in fact a ListClear function in NVSE, and it appears to work fine. I found it in the list produced in NVSE.log.

EDIT: WOOPSIE! ListClear DOES NOT work.

It would also appear that the problem I'm having is due to the RemoveAllTypedItems function; it works (sometimes) on the first call to it, Then crashes on subsequent calls. The crash occurs whether you call it with an exception formlist or not. I suspect that this may have something to do with inventory item ownership not being cleared when the items are placed in a destination container.

I'd recode this to use a loop to remove the items, but the problem I have with that is that it appears impossible to get the current health of an inventory item; I don't want to put weapons in storage with AddItem, which will automatically repair them to 100%.

Any thoughts on this?

Thanks!
User avatar
Iain Lamb
 
Posts: 3453
Joined: Sat May 19, 2007 4:47 am

Post » Tue May 17, 2011 5:49 am

ah-hah! I thought I was doing something wrong; thank you for comfirming that I probably haven't been... This is a treasure trove of valuable information, and most appreciated! What did you use as RHKNullItem and RHKBlankForm?

I just made a couple of Misc items, but anything that could be added to a formlist in the Geck should work.

BTW, are you planning on bringing Brisa over to NV? I'd love to have her here... :)


All the voice files are FO3 assets, so I can't use those. I've started from scratch on another mod for FNV. Not sure where it will end up, but what I want to do is a mod with a companion, a home, and some kind of quest. So far I haven't lost interest in it, though New Vegas just isn't as epic for me as FO3. Probably because I live in Vegas ;)
User avatar
Auguste Bartholdi
 
Posts: 3521
Joined: Tue Jun 13, 2006 11:20 am

Post » Tue May 17, 2011 12:26 am

As it turns out, there is in fact a ListClear function in NVSE, and it appears to work fine. I found it in the list produced in NVSE.log.

EDIT: WOOPSIE! ListClear DOES NOT work.

It would also appear that the problem I'm having is due to the RemoveAllTypedItems function; it works (sometimes) on the first call to it, Then crashes on subsequent calls. The crash occurs whether you call it with an exception formlist or not. I suspect that this may have something to do with inventory item ownership not being cleared when the items are placed in a destination container.

I'd recode this to use a loop to remove the items, but the problem I have with that is that it appears impossible to get the current health of an inventory item; I don't want to put weapons in storage with AddItem, which will automatically repair them to 100%.

Any thoughts on this?

Thanks!


Have you tried using a container with it's own persistent ref, instead as a linked ref? Just something to try, but i'm using RemoveAllTypedItems with and without a formlist between containers/NPC and player without CTD. The casino frisking scripts use containers with persistent refs too.
User avatar
marie breen
 
Posts: 3388
Joined: Thu Aug 03, 2006 4:50 am

Post » Tue May 17, 2011 3:13 am

I just made a couple of Misc items, but anything that could be added to a formlist in the Geck should work.



All the voice files are FO3 assets, so I can't use those. I've started from scratch on another mod for FNV. Not sure where it will end up, but what I want to do is a mod with a companion, a home, and some kind of quest. So far I haven't lost interest in it, though New Vegas just isn't as epic for me as FO3. Probably because I live in Vegas ;)


HAHAHAHAHAHAA! ROFLMAO! I hear ya; you know Vegas too well to have any real suspension of disbelief! Well, however the new one ends up, I'm sure she'll be great. I'll be watching the Nexus for your name on new mods...! ;)
User avatar
Ilona Neumann
 
Posts: 3308
Joined: Sat Aug 19, 2006 3:30 am

Post » Tue May 17, 2011 3:15 am

Have you tried using a container with it's own persistent ref, instead as a linked ref? Just something to try, but i'm using RemoveAllTypedItems with and without a formlist between containers/NPC and player without CTD. The casino frisking scripts use containers with persistent refs too.


I have, but the script looks significantly different from what I started with. I'll revert to the actual reference, and see if that helps. Good to know you're using RemovedAllTypedItems without issue; now all I need to do is get it working for me! Sure appreciate all your help, Ricker; thanks!
User avatar
Inol Wakhid
 
Posts: 3403
Joined: Wed Jun 27, 2007 5:47 am

Next

Return to Fallout: New Vegas