lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I am trying to collect a range of Data from a string, that holds Data Values
example.. 
 assert(Table.Ammo.Signature == 'AMMO')
 assert(Table.Ammo.['Data Size'] == 194)

If anyone has any input on how to help me, i would appreciate it alot

Ammo = [[
  AMMO - Ammunition [0200FF03] <DLC1SoulCairnKeeperArrow> "Dragonbone Arrow"
    Record Header
      Signature: AMMO
      Data Size: 194
      Record Flags
      FormID: AMMO - Ammunition [0200FF03] <DLC1SoulCairnKeeperArrow>
"Dragonbone Arrow"
      Version Control Info 1: 1D 71 55 00
      Form Version: 43
      Version Control Info 2: 04 00
    EDID - Editor ID: DLC1SoulCairnKeeperArrow
    OBND - Object Bounds
      X1: -2
      Y1: -58
      Z1: -2
      X2: 1
      Y2: 0
      Z2: 2
    FULL - Name: Dragonbone Arrow
    Model
      MODL - Model Filename: DLC01\Weapons\Dragonbone\Arrow.nif
      MODT - Texture Files Hashes: 02 00 00 00 00 00 00 00 00 00 00 00
    YNAM - Sound - Pick Up: SNDR - Sound Descriptor [0003E7B7] <ITMArrowsUpSD>
    ZNAM - Sound - Drop: SNDR - Sound Descriptor [0003E877] <ITMArrowsDownSD>
    DESC - Description
    KSIZ - Keyword Count: 2
    KWDA - Keywords
      Keyword #0: KYWD - Keyword [000917E7] <VendorItemArrow>
      Keyword #1: KYWD - Keyword [0006BBD5] <ArmorMaterialDragonplate>
    DATA - Data
      Projectile: PROJ - Projectile [020176F3] <ArrowDragonboneProjectile>
"Dragonbone Arrow"
      Flags: Non-Playable, Non-Bolt
      Damage: 14.000000
      Value: 4
]]

Anyone know how i can achieve this? I tried using this below
function StringLines( s, delim )
        local pos = 1
        local last = false
        return function()
                local starts, ends = string.find( s, '\n', pos, true )
                if starts then
                        if string.sub( s, starts - 1, starts - 1 ) == '\r' then
                                starts = starts - 1
                        end
                        local retStr = string.sub( s, pos, starts - 1 )
                        pos = ends + 1
                        return retStr
                elseif last then
                        return nil
                else
                        last = true
                        return s:sub( pos )
                end
        end
end

function ConvertToTable(data)
        KeywordPatterns = {
                "%s*AMMO - Ammunition [(%d+)] <([%w%C]+)>",
                "%s*Signature:%s*(%a+)",
                "%s*Data Size:%s*(%d+)"
        }

        local function PatternToTable(data)
                for a,b in pairs(KeywordPatterns) do
                        if data:find(b) then
                                print('found')
                                return select(2,data:find(b))
                        end
                end
        end

        for k,v in StringLines(data) do
                PatternToTable(data)
        end
end

ConvertToTable(Ammo)