Morrowind modding for smarties, part 9: tes3cmd to the people...

You know I am a big fan of john.moonsugar's work.

I am not nearly as good as programmer, but after some googling for Perl oddities I managed to cook something workable to automate a useful task: making tree patterns less repetitive.

You know, it is the apparently little touch that makes a great mod, and tree placing is usually something not so carefully handled when you have to place many of them, which is common with big landmass mods.

So, armed with tes3cmd (alpha here) I tried to automate the task of adding a little variety to tree positioning, and this is what I've been able to do:

Prerequisites:
- last version of tes3cmd inside your Morrowind\Data Files folder. I suggest you use the executable version (tes3cmd.exe).
- if you are not using the executable version of tes3cmd, you will need also Perl installed and working (I am using Activestate package, mainly for the handy Perl Package Manager provided).

 1. create a randrot.pl text file containing this perl code

# randrot.pl
# save this code to file: "randrot.pl"
# run with command line:
# tes3cmd modify --program-file randrot.pl myplugin.esp

use strict;

sub main {
   my($tr) = @_; # tr = the record
   my $ok = 0;
   my $angle = 0;
   my $delta = 0;
   my $newangle = 0;
   my $subtype = '';
   my $name = '';
   if ($tr->rectype eq 'CELL') { # only interested in CELL records
      if (!$tr->is_interior) {  # that are not interiors
         $ok = 0;
         foreach my $tsr (@{$tr->{SL}}) { # tsr = the sub-record
            $subtype = $tsr->subtype;
            if ( $ok == 0 ) {
               if ($subtype eq 'FRMR') { 
                  $ok = 1; 
               }
            }
            elsif ( $ok == 1 ) {
               if ( ($subtype eq 'NAME') && ($tsr->{name} =~ m/_tree/i) )  {
                  #found id containing "_tree"
                  $name = $tsr->{name};
                  $ok = 2;
               }
               else {
                  $ok = 0;
               }
            }
            elsif ( $ok == 2 ) {
               if ($subtype eq 'DATA') {
                  $angle = $tsr->{z_angle};
                  $delta = rand(41) - 20; # +/- 20 degrees
                  $delta *= 0.0174533; # pi/180, convert to radians
                  $newangle = $angle + $delta;
                  $tsr->{z_angle} = $newangle;
                  print "\n$name\n z_angle: from $angle to $newangle";

                  $angle = $tsr->{x_angle};
                  $delta = rand(17) - 8; # +/- 8 degrees
                  $delta *= 0.0174533;
                  $newangle = $angle + $delta;
                  $tsr->{x_angle} = $newangle;
                  print "\n x_angle: from $angle to $newangle";

                  $angle = $tsr->{y_angle};
                  $delta = rand(17) - 8; # +/- 8 degrees
                  $delta *= 0.0174533;
                  $newangle = $angle + $delta;
                  $tsr->{y_angle} = $newangle;
                  print "\n y_angle: from $angle to $newangle\n";

                  $tr->{_modified_} = 1; # tell tes3cmd we modified the record
                  $ok = 0;
               }
            }
         }
      }
   }
}

2. create a tes3cmd_rotate_trees.bat file containing this batch code:

tes3cmd.exe modify --program-file randrot.pl myplugin.esp > out.txt
pause
out.txt

Obviously replace myplugin.esp with proper mod name, e.g. TR_Mainland.esm.

3. double click tes3cmd_rotate_trees.bat to start it, and see what happens.
Note that tes3cmd automatically makes a backup of your mod (appending a ~1, or ~2 and so on to the mod name), so you can simply revert back if you want. The one thing I recommend is to keep Mash Lock Times on, so mod dates are not changed.

download example code