Difference between revisions of "NVC Tutorial"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Speedo
(Created)
 
Tag: Manual revert
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:
*Save some basic info about each item: FormID and count of that item in the inventory
*Save some basic info about each item: FormID and count of that item in the inventory
*Save some basic stats for the item in a child container "<name>\Stats": OBSE item type, gold value and weight
*Save some basic stats for the item in a child container "<name>\Stats": OBSE item type, gold value and weight
*Once all data has been assembled, output the container as both text and XML.


==The Script==
==The Script==
To use this script, simply save it as a spell effect, create a spell which uses it and then add that spell to the player.
To use this script, simply save it as a spell effect, create a spell which uses it and then add that spell to the player.
Note that this script requires Pluggy; its string functions are used to retrieve the item's name and to name the output file.


<pre>
<pre>
Line 16: Line 15:


int con
int con
int key
string_var tempStr
int loc


int tempInt
int tempInt
Line 28: Line 26:
   if (IsContainer || IsActor)
   if (IsContainer || IsActor)
     set con to nvcNew
     set con to nvcNew
     set key to CreateString -1 0 1 1
     set tempStr to sv_Construct "%e"
    set loc to CreateString -1 0 1 1
     set index to 0
     set index to 0
      
      
Line 44: Line 41:
       set tempRef to GetInventoryObject index
       set tempRef to GetInventoryObject index
        
        
       StringGetName tempRef loc
       sv_Set "%n" tempRef tempStr
        
        
       if (nvcChildExists con 0 1 loc == 0)    
       if (nvcChildExists con 0 tempStr == 0)
         SetString key "FormID"
         nvcSetRef tempRef con "FormID" 0 0 tempStr
        nvcSetRef tempRef con 0 0 1 key loc
          
          
         set tempInt to GetItemCount tempRef
         set tempInt to GetItemCount tempRef
         SetString key "Count"
         nvcSetInt tempInt con "Count" 0 0 tempStr
        nvcSetInt tempInt con 0 0 1 key loc
          
          
         SetString key "\Stats"
         sv_Set "%z\Stats" tempStr tempStr
        StringCat loc key
          
          
         set tempInt to GetObjectType tempRef
         set tempInt to GetObjectType tempRef
         SetString key "Type"
         nvcSetInt tempInt con "Type" 0 0 tempStr
        nvcSetInt tempInt con 0 0 1 key loc
          
          
         set tempFloat to GetWeight tempRef
         set tempFloat to GetWeight tempRef
         SetString key "Weight"
         nvcSetFloat tempFloat con "Weight" 0 0 tempStr
        nvcSetFloat tempFloat con 0 0 1 key loc
          
          
         set tempInt to GetFullGoldValue tempRef
         set tempInt to GetFullGoldValue tempRef
         SetString key "Value"
         nvcSetInt tempInt con "Value" 0 0 tempStr
        nvcSetInt tempInt con 0 0 1 key loc
       endif
       endif
          
          
Line 76: Line 67:
        
        
     set tempRef to GetSelf
     set tempRef to GetSelf
     StringGetName tempRef key
     sv_Set "%n Inventory.txt" tempRef tempStr
    SetString loc " Inventory.txt"
     nvcPrintToFile con 0 -1 tempStr
    StringCat key loc
   
     nvcPrintToFile con 0 -1 1 key
    sv_Replace ".txt|.xml" tempStr
    nvcSaveToXml con 0 tempStr
      
      
     nvcDel con
     nvcDel con
     DestroyString key
     set tempStr to sv_Destruct
    DestroyString loc
      
      
   else
   else
Line 91: Line 82:


==Sample Output==
==Sample Output==
Output from a Legion Soldier:
Output from a Goblin:


===Text File Output===
<pre>
<pre>
Container 6
Container 5
Owner 02
Owner 01
Protected
Protected
Item Count = 13 <int>
Item Count = 4 <int>
Base FormID = 000700C6 <ref>
Base FormID = 00084B29 <ref>
FormID = 000700F3 <ref>
FormID = FF00080F <ref>
Flax Tunic\
Iron Arrow\
   Count = 1 <int>
   Count = 5 <int>
   FormID = 0002C0FA <ref>
   FormID = 00017829 <ref>
  Stats\
    Type = 22 <int>
    Value = 1 <int>
    Weight = 1.0000000 <float>
Gold\
  Count = 3 <int>
  FormID = 0000000F <ref>
   Stats\
   Stats\
     Type = 27 <int>
     Type = 34 <int>
     Value = 1 <int>
     Value = 1 <int>
     Weight = 0.0000000 <float>
     Weight = 0.1000000 <float>
Laced Leather Pants\
Iron Bow\
   Count = 1 <int>
   Count = 1 <int>
   FormID = 000229AB <ref>
   FormID = 00025231 <ref>
   Stats\
   Stats\
     Type = 22 <int>
     Type = 33 <int>
     Value = 1 <int>
     Value = 11 <int>
     Weight = 1.0000000 <float>
     Weight = 8.0000000 <float>
Legion Boots\
Lockpick\
   Count = 1 <int>
   Count = 1 <int>
   FormID = 00028ADE <ref>
   FormID = 0000000A <ref>
   Stats\
   Stats\
     Type = 20 <int>
     Type = 27 <int>
     Value = 50 <int>
     Value = 3 <int>
     Weight = 10.5000000 <float>
     Weight = 0.0000000 <float>
Legion Cuirass\
Rusty Iron Mace\
  Count = 1 <int>
  FormID = 00028ADF <ref>
  Stats\
    Type = 20 <int>
    Value = 180 <int>
    Weight = 35.0000000 <float>
Legion Gauntlets\
  Count = 1 <int>
  FormID = 00028AE0 <ref>
  Stats\
    Type = 20 <int>
    Value = 50 <int>
    Weight = 7.0000000 <float>
Legion Greaves\
   Count = 1 <int>
   Count = 1 <int>
   FormID = 00028AE1 <ref>
   FormID = 00090614 <ref>
  Stats\
    Type = 20 <int>
    Value = 95 <int>
    Weight = 21.0000000 <float>
Legion Helmet\
  Count = 1 <int>
  FormID = 00028AE2 <ref>
  Stats\
    Type = 20 <int>
    Value = 50 <int>
    Weight = 7.0000000 <float>
Legion Shield\
  Count = 1 <int>
  FormID = 000352D3 <ref>
  Stats\
    Type = 20 <int>
    Value = 95 <int>
    Weight = 14.0000000 <float>
Mutton\
  Count = 4 <int>
  FormID = 00033686 <ref>
  Stats\
    Type = 25 <int>
    Value = 2 <int>
    Weight = 2.0000000 <float>
Sack Cloth Sandals\
  Count = 1 <int>
  FormID = 0002731A <ref>
  Stats\
    Type = 22 <int>
    Value = 1 <int>
    Weight = 2.0000000 <float>
Silver Longsword\
  Count = 1 <int>
  FormID = 0002521F <ref>
   Stats\
   Stats\
     Type = 33 <int>
     Type = 33 <int>
     Value = 125 <int>
     Value = 6 <int>
     Weight = 28.0000000 <float>
     Weight = 15.0000000 <float>
Torch\
</pre>
  Count = 1 <int>
 
  FormID = 0002CF9F <ref>
 
  Stats\
===XML File Output===
     Type = 26 <int>
<pre>
     Value = 0 <int>
<?xml version="1.0" ?>
     Weight = 0.0000000 <float>
<container version="1" />
<int>
    <value name="Item Count" data="4" />
</int>
<ref>
    <value name="Base FormID" data="00084B29" esp="Oblivion.esm" />
    <value name="FormID" data="00000000" esp="&lt;none&gt;" />
</ref>
<child name="Iron Arrow">
    <int>
        <value name="Count" data="5" />
    </int>
    <ref>
        <value name="FormID" data="00017829" esp="Oblivion.esm" />
    </ref>
    <child name="Stats">
        <int>
            <value name="Type" data="34" />
            <value name="Value" data="1" />
        </int>
        <float>
            <value name="Weight" data="0.100000" />
        </float>
    </child>
</child>
<child name="Iron Bow">
    <int>
        <value name="Count" data="1" />
    </int>
    <ref>
        <value name="FormID" data="00025231" esp="Oblivion.esm" />
    </ref>
    <child name="Stats">
        <int>
            <value name="Type" data="33" />
            <value name="Value" data="11" />
        </int>
        <float>
            <value name="Weight" data="8.000000" />
        </float>
    </child>
</child>
<child name="Lockpick">
     <int>
        <value name="Count" data="1" />
    </int>
     <ref>
        <value name="FormID" data="0000000A" esp="Oblivion.esm" />
    </ref>
    <child name="Stats">
        <int>
            <value name="Type" data="27" />
            <value name="Value" data="3" />
        </int>
        <float>
            <value name="Weight" data="0.000000" />
        </float>
    </child>
</child>
<child name="Rusty Iron Mace">
    <int>
        <value name="Count" data="1" />
    </int>
     <ref>
        <value name="FormID" data="00090614" esp="Oblivion.esm" />
    </ref>
    <child name="Stats">
        <int>
            <value name="Type" data="33" />
            <value name="Value" data="6" />
        </int>
        <float>
            <value name="Weight" data="15.000000" />
        </float>
    </child>
</child>
</pre>
</pre>


[[Category:NVC]]
[[Category:NVC]]

Latest revision as of 12:22, 21 December 2023

This tutorial shows a simple example taking advantage of NVC's capabilities to create a spell script which can dump some basic info about a in-game container or actor's inventory contents to a text file for examination out of game.

Goals[edit | edit source]

  • Save some basic info about the object: FormID, Base FormID, total item count
  • Information about each item should be saved in a seperate child container with the name of that item
  • Save some basic info about each item: FormID and count of that item in the inventory
  • Save some basic stats for the item in a child container "<name>\Stats": OBSE item type, gold value and weight
  • Once all data has been assembled, output the container as both text and XML.

The Script[edit | edit source]

To use this script, simply save it as a spell effect, create a spell which uses it and then add that spell to the player.

scn nvcExampleSpellScript

int con
string_var tempStr

int tempInt
float tempFloat
ref tempRef

int index

begin ScriptEffectStart
  if (IsContainer || IsActor)
    set con to nvcNew
    set tempStr to sv_Construct "%e"
    set index to 0
    
    set tempRef to GetSelf
    nvcSetRef tempRef con "FormID"
    
    set tempRef to GetBaseObject
    nvcSetRef tempRef con "Base FormID"
    
    set tempInt to GetNumItems
    nvcSetInt tempInt con "Item Count"
    
    label 0
      set tempRef to GetInventoryObject index
      
      sv_Set "%n" tempRef tempStr
      
      if (nvcChildExists con 0 tempStr == 0)
        nvcSetRef tempRef con "FormID" 0 0 tempStr
        
        set tempInt to GetItemCount tempRef
        nvcSetInt tempInt con "Count" 0 0 tempStr
        
        sv_Set "%z\Stats" tempStr tempStr
        
        set tempInt to GetObjectType tempRef
        nvcSetInt tempInt con "Type" 0 0 tempStr
        
        set tempFloat to GetWeight tempRef
        nvcSetFloat tempFloat con "Weight" 0 0 tempStr
        
        set tempInt to GetFullGoldValue tempRef
        nvcSetInt tempInt con "Value" 0 0 tempStr
      endif
        
      set index to index + 1
      if (index < GetNumItems)
        goto 0
      endif
      
    set tempRef to GetSelf
    sv_Set "%n Inventory.txt" tempRef tempStr
    nvcPrintToFile con 0 -1 tempStr
    
    sv_Replace ".txt|.xml" tempStr
    nvcSaveToXml con 0 tempStr
    
    nvcDel con
    set tempStr to sv_Destruct
    
  else
    PrintC "Object is not a container"
  endif
end

Sample Output[edit | edit source]

Output from a Goblin:

Text File Output[edit | edit source]

Container 5
Owner 01
Protected
Item Count = 4 <int>
Base FormID = 00084B29 <ref>
FormID = FF00080F <ref>
Iron Arrow\
  Count = 5 <int>
  FormID = 00017829 <ref>
  Stats\
    Type = 34 <int>
    Value = 1 <int>
    Weight = 0.1000000 <float>
Iron Bow\
  Count = 1 <int>
  FormID = 00025231 <ref>
  Stats\
    Type = 33 <int>
    Value = 11 <int>
    Weight = 8.0000000 <float>
Lockpick\
  Count = 1 <int>
  FormID = 0000000A <ref>
  Stats\
    Type = 27 <int>
    Value = 3 <int>
    Weight = 0.0000000 <float>
Rusty Iron Mace\
  Count = 1 <int>
  FormID = 00090614 <ref>
  Stats\
    Type = 33 <int>
    Value = 6 <int>
    Weight = 15.0000000 <float>


XML File Output[edit | edit source]

<?xml version="1.0" ?>
<container version="1" />
<int>
    <value name="Item Count" data="4" />
</int>
<ref>
    <value name="Base FormID" data="00084B29" esp="Oblivion.esm" />
    <value name="FormID" data="00000000" esp="<none>" />
</ref>
<child name="Iron Arrow">
    <int>
        <value name="Count" data="5" />
    </int>
    <ref>
        <value name="FormID" data="00017829" esp="Oblivion.esm" />
    </ref>
    <child name="Stats">
        <int>
            <value name="Type" data="34" />
            <value name="Value" data="1" />
        </int>
        <float>
            <value name="Weight" data="0.100000" />
        </float>
    </child>
</child>
<child name="Iron Bow">
    <int>
        <value name="Count" data="1" />
    </int>
    <ref>
        <value name="FormID" data="00025231" esp="Oblivion.esm" />
    </ref>
    <child name="Stats">
        <int>
            <value name="Type" data="33" />
            <value name="Value" data="11" />
        </int>
        <float>
            <value name="Weight" data="8.000000" />
        </float>
    </child>
</child>
<child name="Lockpick">
    <int>
        <value name="Count" data="1" />
    </int>
    <ref>
        <value name="FormID" data="0000000A" esp="Oblivion.esm" />
    </ref>
    <child name="Stats">
        <int>
            <value name="Type" data="27" />
            <value name="Value" data="3" />
        </int>
        <float>
            <value name="Weight" data="0.000000" />
        </float>
    </child>
</child>
<child name="Rusty Iron Mace">
    <int>
        <value name="Count" data="1" />
    </int>
    <ref>
        <value name="FormID" data="00090614" esp="Oblivion.esm" />
    </ref>
    <child name="Stats">
        <int>
            <value name="Type" data="33" />
            <value name="Value" data="6" />
        </int>
        <float>
            <value name="Weight" data="15.000000" />
        </float>
    </child>
</child>