Difference between revisions of "NVC Tutorial"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
Tag: Manual revert
 
Line 20: Line 20:
float tempFloat
float tempFloat
ref tempRef
ref tempRef
S
 
int index
int index



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>