Page 1 of 1
Mass-adding items?
Posted: Thu Apr 19, 2012 4:33 am
by BMR
Hiya, was wondering if there was a way to mass-add items in Custom? Like around 100+ items that I have charted out on a spreadsheet. I've been digging around trying to figure it out, is there a cunning to use a combination of unlumping, editing, and relumping to do what I want? Or am I over-complicating things?
Posted: Thu Apr 19, 2012 1:24 pm
by Spoonweaver
There MAY be a way to do what you want but the likely hood of your chart being in the exact right format is very very low. Even if your format was pretty good, and the process of importing it wasn't shaky at best, you'd still have to go through all the items to make sure they came out right which chances are they wouldn't.
You're best bet is to just start entering them in to the editor.
Posted: Thu Apr 19, 2012 2:09 pm
by Bob the Hamster
No, unfortunately there is no way to mass-add items.
Posted: Thu Apr 19, 2012 3:00 pm
by BMR
Hmm, righto then. No way at all to edit the unlumped files in a hex-editor or something then?
Posted: Thu Apr 19, 2012 3:16 pm
by Bob the Hamster
Oh, well, I meant there is no easy built-in way. If you are talking about programming your own tool for editing the .ITM lump, yes that is possible.
The documentation for the ITM lump is here:
http://rpg.hamsterrepublic.com/ohrrpgce/ITM
Also, the nohrio python library already has at least partial support for the ITM lump, so that might be the easiest starting point.
https://gitorious.org/nohrio
Posted: Fri Apr 20, 2012 5:21 pm
by TMC
I had a play around, and found that nohrio's description of the ITM lump was wrong (which was the fault of the wiki page, which didn't mention an unused field. A fix is available from
my nohrio clone
I wrote a script to convert an .itm lump to a .csv file:
Code: Select all
import numpy as np
from nohrio.ohrstring import *
from nohrio.wrappers import OhrData
from nohrio.dtypes import dt
def get_field_decoder(dtype, name):
"""
Depack a (possibly compound) field of a dtype, returning a (header, decoder) tuple
A header is a list of one or more field names.
A decoder takes a data field and returns a list (same length as header) of ints/floats/strings
"""
ty = dtype[name]
if len(ty):
# compound field
if ty.names[0] == 'length':
# it's a string. Assume vstr2, since that's the only one used in ITM
decoder = lambda x: ['"' + get_str16(x) + '"']
header = [name]
else:
# a tuple
decoder = lambda x: x
header = [name + ':' + n for n in ty.names]
elif len(ty.shape):
# array
assert len(ty.shape) == 1
decoder = list
header = [name + ' ' + str(i) for i in range(ty.shape[0])]
else:
# simple integer/float
decoder = lambda x: [x]
header = [name]
return header, decoder
def lump2csv(lump, fields):
headers2, decoders = [], []
for name in fields:
headers, decoder = get_field_decoder(lump.dtype, name)
headers2.extend(headers)
decoders.append(decoder)
ret = [','.join(headers2)]
for item in lump:
stuff = []
for i, name in enumerate(fields):
stuff.extend(decoders[i](item[name]))
ret.append(','.join(str(a) for a in stuff))
return '\n'.join(ret)
itm = np.memmap("viking.itm", dtype = dt['itm'], mode = 'r+')
# If you're interested in ALL data
#fields = dt['itm'].names
# Only interested in some...
fields = (
'name',
'info',
'value',
'attack',
'weaponattack',
'equippable',
# 'teach',
# 'oobuse',
'weaponpic',
'weaponpal',
'bonuses',
# 'equippableby',
# 'bitsets',
'consumability',
# 'own_tag',
# 'in_inventory_tag',
# 'equipped_tag',
# 'equippedby_active_tag',
# 'frame2handle',
# 'frame1handle',
# 'elemdmg'
)
print lump2csv(itm, fields)
General enough to be used for most other lumps too.
If you're interested, I can write the csv to itm direction.
Posted: Sat Apr 21, 2012 1:21 am
by BMR
Sweet. That would be great if you could do the csv to itm as well, if it's not too much trouble. I can read through that code and get a basic idea of how it works, but the programming level just goes way above my head, hehe... Thanks.