Jump to content

Problem with InventorySorter Script


Neograf

Recommended Posts

I am trying to pimp one of my favourite playerhomes with an automatic inventory sorter.

Because I have absolutely no scripting-knowledge, I went onto the internet, looking for something I could grab ;)

 

I made a few containers (in this case ammo-boxes), called "AKSLammoXXXCont" later in the script.

I managed to make the containers greet me with a message that allows me to store the ammo for this box (e.g. 9mm) automatically.

 

But of course I want an activator that allows me to sort all ammo in my inventory automatically into the right box.

It works so far that all my ammo is removed from my inventory and I get the messages about this ("10 10mm removed"...), BUT nothing shows up in my containers. Not a single piece of ammo in any of them.

EDIT: I played around a bit more. I have a creature (Mister Gutsy) act as my activator. I found out, my ammo was added to the creature's inventory instead to my ammo-boxes. :(

 

I'm shure, the error is a simple one, but like I said, I barely understand about 50% of the script. I just copy and paste, then try and error ;)

 

removed

 

I'm writing this because it's 2 o'clock in the morning for me now and I really need to sleep ;)

And as you can propably see, English isn't my first language. Hope it's comprehensible anyway.

Edited by Neograf
Link to comment
Share on other sites

Is AKSLammo10mmCont a RefID of a box placed in the world, or just a container object in the Geck (base object)? If the latter, it won't work. The box needs to be placed in the world with a persistent refID.
Link to comment
Share on other sites

Oh thank you for pointing me into the right direction :)

 

My containers were placed in the world, but I didn't give them a Reference Editor ID. Now my ammo is placed in my boxes :) Well, most of my ammo ;)

 

New problems:

It seems, only some of my ammo is removed and stored. It looks like the last 4 of my 14 ammotypes are not affected.

Also my "Mister Gutsy" (the activator for my script) can only be activated ONE time. If I store my ammo once, I can no longer activate it. I have to restart FNV, a reload doesn't help.

 

EDIT: I changed positions of my ammo-types in the list (e.g. I put the 5.56 - which was not sorted before - at position 2). Now these ammotypes are sorted, but I still cannot activate my Mister Gutsy another time.

 

Here my new script:

Sorry for all the text, I'll remove the script from my first post.

removed

Edited by Neograf
Link to comment
Share on other sites

IDK - never had that many Label/Goto loops in one script before. You could try commenting out loops 1,2,3 to see if it continues past 10 after that. That would be a good indication of a limit.

 

Another way you might be able to optimize the script, is have two additional form lists, one is created dynamically when the script is activated, and is a list you build of your container references (MasterContainerList). The other list is a list of ammo formlists that you are sorting - build this in the geck (MasterAmmoList) - yes, you can have lists of lists. You build your dynamic container formlist so that the container references in your container list would have the same index as the ammo formlists in the master ammo list. Make sure the two lists will have the same number of objects.

 

The bottom of this page shows how to use references in a loop:

http://www.cipscis.c...ials/loops.aspx

 

This script could be a start - not guaranteed to be bug free, but you should be able to get the picture:

 

scn AKSLButtlerArmoryScr

short nButton
short buttonPressed
int listnumF
int myCount
int formrefnumF
ref formref
ref rContainer

Begin OnActivate

           	showmessage AKSLbutlerArmoryMSG
set buttonPressed to 1
set init to 0

End

Begin Menumode   

if init == 0
;make sure list is empty
   Label 10
       if ListGetCount MasterContainerList
  	     set rContainer to ListRemoveNthForm MyFormList 0
  	     Goto 10
       endif
;Build the list of containers
   AKSLammo10mmContREF.ListAddReference MasterContainerList    ;append to end of list
   AKSLammo127mmContREF.ListAddReference MasterContainerList
   AKSLammo45ContREF.ListAddReference MasterContainerList
   ...etc

   set iListCount to ListGetCount MasterContainerList    ;we are asuming this number = listcount of master ammo list
   set iIndex to 0
   
   
   set init to 1
endif
   

if buttonPressed == 1
   	set nbutton to getbuttonpressed

   	if nbutton > -1
           	set buttonPressed to  0

   	if nButton == 0
  



Label 20
   if iListCount
       set rCurrentContainerREF to ListRemoveNthForm MasterContainerList 0        ;always remove index 0 - stuff shifts up
       set rCurrentAmmoREF to ListGetNthForm MasterAmmoList iIndex
       set iListCount to iListCount - 1
       set iIndex to iIndex + 1
       
       Label 30
  	     set formrefnumF to ListGetCount rCurrentAmmoREF
  	     set rContainer to rCurrentContainerREF
  	     if listnumF <= formrefnumF
  			     set formref to listgetnthform rCurrentAmmoREF listnumF
  			     set myCount to player.getitemcount formref
  			     player.removeitem formref myCount
  			     rContainer.additem formref myCount
  			     set listnumF to listnumF + 1
  			     goto 30
       Goto 20
   endif

 

Link to comment
Share on other sites

Ok, I tried something else

 

scn AKSLButtlerArmoryScr

short nButton
short buttonPressed
short stage
int listnumF
int myCount
int formrefnumF
ref rcontlist
ref formref
ref rContainer

Begin OnActivate
		showmessage AKSLbutlerArmoryMSG
	set buttonPressed to 1
End
Begin Menumode
if buttonPressed == 1
set nbutton to getbuttonpressed
if nbutton > -1
	set buttonPressed to  0
       if nButton == 0

	set stage to 1
	
	Label 1
	if stage == 1
		set formrefnumF to ListGetCount AmmoList10mm
		set rcontlist to AmmoList10mm
		set rContainer to AKSLammo10mmContREF
		
	if stage == 2
		set formrefnumF to ListGetCount AmmoList9mm
		set rcontlist to AmmoList9mm
		set rContainer to AKSLammo9mmContREF

	endif

	Label 2
	if listnumF <= formrefnumF
	        set formref to listgetnthform rcontlist listnumF
	        set myCount to player.getitemcount formref
	        player.removeitem formref myCount
	        rContainer.additem formref myCount
	        set listnumF to listnumF + 1
	        goto 2
	endif
	set listnumF to 0
	set stage to stage + 1
	goto 1


 elseif nButton == 1
return
endif
endif
endif
endif
END

 

My 10mm ammo is removed and stored as it should be, but the transition to stage 2 seems to fail - propably a noob error ;)

Something wrong with "set stage to stage + 1" ?

At least the script doesn't end in a loop, I can activate it again.

Edited by Neograf
Link to comment
Share on other sites

Use printc to help debug your script http://fose.silverlo...#PrintToConsole

The format strings for it are here: http://fose.silverlo...ormatSpecifiers

 

Place the printc commands in strategic places, like this:

 

set iListCount to ListGetCount MasterContainerList	;we are asuming this number = listcount of master ammo list
printc "List Count: %.0f ", iListCount

 

set rCurrentContainerREF to ListRemoveNthForm MasterContainerList 0    	;always remove index 0 - stuff shifts up
printc "Current Container: %i", rCurrentContainerREF

 

One thing about your script - if you are activating something in the world, and a message pops up - menu mode only lasts until you hit a button.

 

I would run this script in gamemode, and use the OnActivate block to enable the Showmessage function, which I would also run in gamemode, guarded by the init section.

 

scn AKSLButtlerArmoryScr

short nButton
short buttonPressed
int listnumF
int myCount
int formrefnumF
ref formref
ref rContainer

int iListCount 
int init
int iIndex 
ref rCurrentContainerREF
ref rCurrentAmmoREF
ref MasterContainerList
ref MyFormList 

Begin OnActivate

set init to 0

End

Begin Gamemode   

   	if init == 0
		showmessage AKSLbutlerArmoryMSG
		set buttonPressed to 1
           	;make sure list is empty
           	Label 10
                   	if ListGetCount MasterContainerList
                   	set rContainer to ListRemoveNthForm MyFormList 0
                   	Goto 10
                   	endif
   	;Build the list of containers
AKSLammo10mmContREF.ListAddReference MasterContainerList	;append to end of list
AKSLammo127mmContREF.ListAddReference MasterContainerList
AKSLammo5ContREF.ListAddReference MasterContainerList
AKSLammo9mmContREF.ListAddReference MasterContainerList
AKSLammo45ContREF.ListAddReference MasterContainerList
AKSLammo556ContREF.ListAddReference MasterContainerList
AKSLammo20gContREF.ListAddReference MasterContainerList
AKSLammo22LRContREF.ListAddReference MasterContainerList
AKSLammo308ContREF.ListAddReference MasterContainerList
AKSLammo357ContREF.ListAddReference MasterContainerList
AKSLammo4070ContREF.ListAddReference MasterContainerList
AKSLammo44ContREF.ListAddReference MasterContainerList
AKSLammo50ContREF.ListAddReference MasterContainerList
AKSLammo12gContREF.ListAddReference MasterContainerList

set iListCount to ListGetCount MasterContainerList	;we are asuming this number = listcount of master ammo list
printc "List Count: %.0f ", iListCount
set iIndex to 0


set init to 1
   	endif


if buttonPressed == 1
   	set nbutton to getbuttonpressed

   	if nbutton > -1
           	set buttonPressed to  0

   	if nButton == 0




Label 20
if iListCount
   	set rCurrentContainerREF to ListRemoveNthForm MasterContainerList 0    	;always remove index 0 - stuff shifts up
	printc "Current Container: %i", rCurrentContainerREF
   	set rCurrentAmmoREF to ListGetNthForm AKSLMasterAmmoList iIndex
   	set iListCount to iListCount - 1
   	set iIndex to iIndex + 1
   	
   	Label 30
    		set formrefnumF to ListGetCount rCurrentAmmoREF
    		set rContainer to rCurrentContainerREF
    		if listnumF <= formrefnumF
                    		set formref to listgetnthform rCurrentAmmoREF listnumF
                    		set myCount to player.getitemcount formref
                    		player.removeitem formref myCount
                    		rContainer.additem formref myCount
                    		set listnumF to listnumF + 1
                    		goto 30
                           	set listnumF to 0
   	Goto 20
endif
   	elseif nButton == 1
	return
   	endif
endif
endif
endif
END

Link to comment
Share on other sites

Thank you for all your work, but my problem seems to be a more basic one. Perhaps I messed up something with the containers, I don't know.

If I run the script, nothing happens. Console tells me: "List Count: 0", so I presume none of my containers are added to the "mastercontainerlist".

 

After playing around with the scripts and starting FNV for about 30 or 40 times this night without the slightest success, I beginn to realize that this project is just above my skills.

 

EDIT: Forget my whining, I got it working :D Although a different approach:

 

scn AKSLButtlerArmoryScr

short nButton
short buttonPressed
int ammot
int listnumF
int myCount
int formrefnumF
ref rcontlist
ref formref
ref rContainer

Begin OnActivate
               showmessage AKSLbutlerArmoryMSG
               set buttonPressed to 1
End
Begin Gamemode
               set ammot to 1
if buttonPressed == 1
       set nbutton to getbuttonpressed
       if nbutton > -1
               set buttonPressed to  0
       if nButton == 0


               
               Label 1
               if ammot == 1
                       set rcontlist to AmmoList10mm
                       set formrefnumF to ListGetCount rcontlist 
                       set rContainer to AKSLammo10mmContREF
                       
               elseif ammot == 2
                       set rcontlist to AmmoList9mm
                       set formrefnumF to ListGetCount rcontlist 
                       set rContainer to AKSLammo9mmContREF

...


               elseif ammot == 13
                       set rcontlist to AmmoList20Ga
                       set formrefnumF to ListGetCount rcontlist 
                       set rContainer to AKSLammo20gContREF

               elseif ammot == 14
                       set rcontlist to AmmoList556mm
                       set formrefnumF to ListGetCount rcontlist 
                       set rContainer to AKSLammo556ContREF

               else
					goto 3
               endif

               Label 2
               if listnumF <= formrefnumF
                       set formref to listgetnthform rcontlist listnumF
                       set myCount to player.getitemcount formref
                       player.removeitem formref myCount
                       rContainer.additem formref myCount
                       set listnumF to listnumF + 1
                       goto 2
               endif
               set listnumF to 0

               set ammot to ammot + 1
                       printc "ammot: %.0f ", ammot
               goto 1
		
		Label 3
               return

 elseif nButton == 1
       return
       endif
endif
endif
endif
END

Edited by Neograf
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...