kt0's item scripts: BLAM

Users who are viewing this thread

Since Ruthven stole my BLAM on Monday, I've been busy on some new BLAM.

I got tired of dealing with the uber hard to read item tuples so I wrote a pair of scripts to go to and fro.  There's a script that will chug through your item_kinds1.txt file and create a CSV file and a sibling script that will chug through the generated CSV and spit out proper tuples that you can then paste into module_items.py.  For those of you who started out hacking text files like I did, you can now import your item hacks into the module system with relative ease. 

For more BLAMmage:  http://www.mbrepository.com/file.php?id=1156

As a test of effectiveness, I ran both scripts on my mod's data, copied the new tuples into module_items.py, compiled everything, and then diffed the results against the old item_kinds1.txt.  The only issues were a bug (!) in the original tuples for itm_plate_covered_round_shield (missing its type) and places where the original code stuffed a zero in damage type but with a proper damage type. 

Limitations:
- Tableaus are hard to edit in the CSV file because my handling of them is a hack (sorry).
- A handful of itc_ flags are identical (e.x. itc_pike and itc_greatlance) and I'm far too lazy to parse the name of the item to make them match up.  They're functionally equivalent and you can fix them in the CSV if you so desire.
- It's in Ruby which I'm guessing a lot of y'all don't have installed.  I dislike Python, sorry.  If someone wants to port it, feel free.
- Not exactly user-friendly but user-friendlier than dealing with the unformatted disaster that is module_items.py.

If you use these scripts and find bugs, PM me or email me.
 
Wu-long said:
Why do you dislike python and whats the twos difference?

I think you don't get the point of this script, what it does is it takes the items.txt file, and converts it into tuples so you can edit it with python, in case you edited it and don't feel like converting it yourself into python code.

The point of this is to work with python instead of text files.
 
MrRoy said:
Wu-long said:
Why do you dislike python and whats the twos difference?

I think you don't get the point of this script, what it does is it takes the items.txt file, and converts it into tuples so you can edit it with python, in case you edited it and don't feel like converting it yourself into python code.

The point of this is to work with python instead of text files.

lol i dont get it but thanks ;p I see nw
 
Story time with kt0:

Take a look at the tuple data in module_items.py.  What strikes you about it?  What if you wanted to change every single horse?  What if you wanted to change every single sword?  What if you wanted to compare your modified swords to the original axes?  How hard would these things be?  It would be a disaster!

The way the data is arranged in the module files is a usability nightmare; I got that within minutes of trying to twiddle some values.  I'm not going to wade through that mess to make comprehensive changes and I'd really like to pretend I'm a designer and use a proper spreadsheet.  So I wrote the conversion tools.  I wrote them in Ruby because it's my favorite scripting language and I don't get to use it very often.  This is a common thing to do:  translate something from one form that's not usable to another form that is.  And because I still wanted all the source in the module system, I wrote the bit to turn it all back into tuples as well.  It's not like it's rocket science.

When I work on my mod and need to munge item data, it's a heck of a lot more convenient now.  I have CSV files split by type and can answer most comparison type questions trivially.  Is one handed sword d too much better than one handed sword a?  Easy!  It's three lines up in the CSV!  Furthermore, I never have to hand-hack module_items.py for those things which I have CSVs for (all horses, non-artifact equipment, and projectiles) so I never have a syntax error in them, ever.  So for a relatively large subset of the item data (i.e., the stuff most likely to change), I have eliminated an entire class of problems! 

I can hear you now:  "Why would I shell out my hard earned $0.00 for these crappy scripts?  What can they do for me?"  Well, now you can go from txt files to tuples meaning you can do your item hackery with the unofficial item editor and go right to module system-ready entries.  Even text hackers, yes you, can now import all your hard work in item_kinds1.txt to the module system conveniently and easily!  All this for $0.00--factory direct to you! 

And to think, it's all because I was too lazy to hand-hack the original python tuples in module_items.py.

 
Hey kt0,
Your tool looks really cool but I have no idea how to run it.  I downloaded Ruby (push button installer = ruby186-27_rc2.exe) and it seemed to install just fine. 

I then downloaded your script but a little screen just pops and and disapears.  I do not know the Ruby code required to tell it where to look for my itemkinds1.txt file.  I am currently trying to run the items2csv.rb file to convert to the .csv (for Excel). 

I need instructions, I am completely new at this. 
To use items2csv.rb:
- change source_file to point at your item_kinds1.txt file
- change dest_file to point at the file you want to dump the item data to
- run items2csv.rb from a command line

1.) How do I change the source_file to point at your item_kinds1.txt file? 
2.) How do I change dest_file to point to the file I want to dump the item data?  I guess I need to create a blank .csv file on my desktop (for example)
3.) After this is done, do I just type “run items2csv.rb”?

Screen shots would be nice, a picture is worth a thousand words…
Thank you!
 
kt0 - this is pretty kick ass.  I'm psyched to gather up some of the text file mods  that folks have done for SoD and apply them to the real code base.  You've saved us all a ton of work.  :shock:

My hand's killing me this evening, so no go tonight... but soon methinks :cool:
 
Cyclohexane said:
I need instructions, I am completely new at this. 
To use items2csv.rb:
- change source_file to point at your item_kinds1.txt file
- change dest_file to point at the file you want to dump the item data to
- run items2csv.rb from a command line

1.) How do I change the source_file to point at your item_kinds1.txt file? 
2.) How do I change dest_file to point to the file I want to dump the item data?  I guess I need to create a blank .csv file on my desktop (for example)
3.) After this is done, do I just type “run items2csv.rb”?

Screen shots would be nice, a picture is worth a thousand words…
Thank you!
I'll try to walk you through it step by step.  If that doesn't work, I'll start taking screen shots for you.

Make sure you have the module system installed and make sure you know where it lives. 

1) First, you need to edit the two scripts to point at the data you want to work on.  Right click on the files and choose "edit".  If you've got Ruby installed correctly, they should pop open in a Ruby editor (mine open in SciTE), otherwise use notepad or your favorite text editor.

2) Find items2csv.rb.  Near the top of the file you'll find this kind of stuff:
# modify these to fit your particular setup
source_file = "C:/Program Files/Steam/steamapps/common/mount and blade/Modules/KTMOD/item_kinds1.txt"
dest_file = "C:/projects/games/MB_MOD/kt_tools/items.csv"
Those are full paths. The source_fiile is your item_kinds1.txt.  The dest_file is where you want the resultant csv to be written.  You can pop that open in Excel or OpenOffice Calc (what I use) for easier editing if you so desire. 

3) Find csv2tuples.rb.  Near the top of the file you'll find this kind of stuff:
# UNDER NO CIRCUMSTANCES SHOULD dest_file EVER BE YOUR item_modules.py FILE!
source_file = "C:/projects/games/MB_MOD/kt_tools/items.csv"
tableau_src = "C:/projects/games/MB_MOD/ModuleSystem/ID_tableau_materials.py"
dest_file = "C:/projects/games/MB_MOD/kt_tools/tuples.py"
This is the same sort of deal as in 2) except the source_file is the same csv file the other script writes out so the paths should be the same.  The tableau_src file is the ID_tableau_materials.py from the module system.  It needs to point at the one in your particular module system.  The dest_file in this case, is the file you want your tuples to go do.  Avoid the temptation to make this your module_items.py. 

4) If you're in XP, click on the Start menu, choose Run, and then type in cmd.  This will pull up a DOS like window where we'll do fun stuff.

5) Run the first script by typing the red stuff into the cmd window (your path will probably be different than mine):
c:\projects\games\MB_MOD\kt_tools>items2tuples.rb
and hit Enter.  If the script runs correctly, it'll say "Output file left in X" where X is what you set as dest_file.  If there's an error, you've probably got one or more paths entered incorrectly.

6) Run the second script in a similar way:
c:\projects\games\MB_MOD\kt_tools>csv2tuples.rb

If everything completed properly, you'll now have a python file with tuples for your items that you can copy & paste into module_items.py as necessary. 

Hope that helps!
 
kt0 said:
I'll try to walk you through it step by step.  If that doesn't work, I'll start taking screen shots for you.

Thank you,
I am going to add a ton of OSP items to the mod I'm working on and once I get them all added and working properly, I will definately be using your tool.  I'll post the results when I get to it (probably a couple of weeks due to RL). 

 
I got both of your scripts to work and generated each file.  I'm still new so I'm learning the next step.  I have python installed and set the environmental variable and I guess I need to open the module_items.py and paste the newly added items.  I guess I need the newest .py file for the mod I am working on (CLICK HERE and HERE).  Then run the build module to generate the new files? 

Sound about right? 
 
Sounds like you have the right idea.  Before doing any copying and pasting, I'd recommend doing some fresh compiles with the most recent source to get any setup issues ironed out.  Make sure that you can play the newly-compiled module and have all the assets in the right place.  After that you can go about copying & pasting the generated tuples.  Note that your stuff probably goes over the top of some of the existing stuff in module_items.py so you'll want to be careful. 

Generally, I only bother copying and pasting the data I care about and leave markers in the existing code so I paste to the right place in the file.  So, for instance, I've hacked out the arena items, the foods, and the trade goods from my CSV files.  I'd also recomment keeping backups of stuff in case something goes terribly wrong and you need to back out of a change.

If you run into problems, let me know.
 
THANK YOU. Damn, the structure of the module system is a nightmare (and i dont mean that i need to know about programming to use it - i am familiar with multiple programming languages - i just dislike the structure of the source files - it would be half as bad if individual things (i.e. item-types) would be in own files instead of dumping everything into a single file. Its not the "system" itself which i dislike, but the way data is "organized").

Anyways, this will save me a lot of work, for exactly the reasons you mentioned. Now, if only i wouldn't need to have 3 different bloated frameworks installed. I already created a minimalist python distro which requires no installation, being 1,2 MB large instead of the 30mb or more of the usual distro. Guess next up i'm gonna do the same for ruby... from a quick look at your script, it seems the only dependency is CSV.

P.S.: IMO, the setup up your little tool could benefit from this too. You could put your scripts into a folder "kt0 item scripts". Then move the configuration vars out into a third script. Then put a minimalist ruby distro into the same folder. Furthermore, make it so that by default the config vars are blank. Then the script checks if the vars are blank, and if yes, the path for txt would default to "..\item_kinds.txt", the path for csv would default to "..\source\item_kinds.csv" and the path for tuples would default to "..\source\item_tuples.py".

Then, just tell people to dump the scriptfolder into the relevant module folder, and have their mod-source in a "source" subdir of that... et voila: Works out of the box, no config - just unpack into correct folder, and you're ready to go.
 
I've created a 1mb version which works out of the box. No installation. No dependencies. No setup. Anyone want? :smile: 

(actually, UPXed, its now at 0,4mb. It's just the scripts, ruby binary and csv.rb as dep.)
 
I may have some time in the next month to spiff it up some including some fixes I've added locally but never uploaded.  I've been busy with other things and there hasn't exactly been a whole lot of interest in this stuff.
 
To be honest, i'm a bit surprised that interest hasn't been high. After all, this way you can comfortably edit items with the item-editor, and then export them to the modsys. Unfortunatelly, i have a feeling that my interest as well is dimishing - but not because of your script, but because the more i understand the general workings of the modsys, the more i become aware that it is in some aspects very restrictive (for example, it seems that item-modifiers are hardcoded). Still, if you or others are interested in a minimalist no-install ruby and python distro, i'd by happy to upload it somewhere.
 
Well I just started compiling my new items and it worked flawlessly.  The tuples generated were pasted into the module_items.py file with no problems (I tested on the base Native version first).  Everything worked so easily I thought something must be wrong.  I added over 160 items so I could not test everyone but so many were showing up in the vendor and the mod loaded in flawlessly.  I assume there are no problems. 

This is fantastic work and thank you so much for the time saver! 


Now if you could create one that works with the troop editor, then you would be hailed an M&B god....


Seriously, thanks for this tool and working with me to get it going.
 
Back
Top Bottom