Automation Via TES3CMD?

2 posts / 0 new
Last post
FiftyTifty's picture
FiftyTifty
Joined:
2020-07-08 03:01
Last seen:
4 years 3 weeks ago

--
Edit: Of course, I should post the solution. Thanks to users on the Discord, Greatness7 especially, it was much easier to get working scripts. Here's the script which will modify the levels of NPCs with a level below 20, with a bit of randomization so the levels will be changed to a number between 16-24 inclusive.

 
# run via [tes3cmd modify -program IncreaseLevels.pl]

 

my $input = open_for_input('levelled_TR_Mainland.esp');
my $output = open_for_output('levelled_TR_Mainland_1.esp');

 

while (my $record = TES3::Record->new_from_input($input)) {

 

    if ($record->rectype eq 'NPC_') {

 

        my $id = $record->decode->id;

 

        #my $levelTemp = 1;
        my $levelFromNPC = 1;
        $levelFromNPC = $record->get('NPDT''level');
                
        if ($levelFromNPC eq 'nil')
        {
            $levelFromNPC = 1;
        }
                
        my $classFromNPC = $record->get('CNAM''class');

 

        print "$levelFromNPC\n";
        print "Variable is: " . int($levelFromNPC) . "\n";

 

        my $iRandModifierChanceFirst = 0;
        my $iRandModifierChanceSecond = 0;
        my $iRandModifierFirst = 0;
        my $iRandModifierSecond = 0;

 

        srand;
        $iRandModifierChanceFirst = int(rand(2));
        srand;
        #25% chance to modify NPC after first modification
        $iRandModifierChanceSecond = int(rand(4));
        srand;
        #Change level with random number between -2 and 2
        $iRandModifierFirst = int(int(rand(5)) - 2);
        #Repeat
        srand;
        $iRandModifierSecond = int(int(rand(5)) - 2);
        

 

        if ((int($levelFromNPC) < 20) && (int($levelFromNPC) > 0)) {

 

            $levelFromNPC = 20;

 

            #50% chance to modify NPC once
            print "Set to level 20!\n";
            print "$iRandModifierChanceFirst\n";

 

            if ($iRandModifierChanceFirst == 1) {

 

                print "First modifier!\n";
                $levelFromNPC = int(int($levelFromNPC) + int($iRandModifierFirst));
                #$levelTemp = int(int($levelTemp) + int($iRandModifierFirst));

 

                if ($iRandModifierChanceSecond == 3) {

 

                    print "Second modifier!\n";
                    $levelFromNPC = int((int($levelFromNPC) + $iRandModifierSecond));
                    #$levelTemp = int((int($levelFromNPC) + $iRandModifierSecond))
                }            

 

            }

 

            if ($levelFromNPC eq 'nil')
            {
                $levelFromNPC = 20;
            }

 

            $record->set({t=>'NPDT', f=>'level'}, $levelFromNPC);

 

        }

 

        print "$id$classFromNPC$levelFromNPC\n";

 

        $record->encode;

 

    }

 

    $record->write_rec($output);
}

 

exit;

As you can see, this makes much more sense than the example scripts that were kicking around.
---

Now that TES3MP is due an update any day now, I've turned to modding Morrowind, with plenty of experience with the newer Elder Scrolls and Fallout games. Cut my teeth on making TES5Edit scripts in Delphi to automate inhumane amounts of work. But there is a problem; there's no real documentation nor any meaningful amount of well-commented example Perl scripts. Since Tamriel Rebuilt is a must-have, I'd like to automate changes to both the base Morrowind game, as well as this mod.

The closest I've found to a well documented example, was this: http://abitoftaste.altervista.org/morrowind/index.php?option=content&task=view&id=81&catid=45&Itemid=10&-Morrowind-modding-for-smarties-part-9-tes3cmd-to-the-people

But I need a wee bit more info for that. Figured this forum would be the best place to ask, since it's one of the oldest still-alive communities for morrowind mod development.

What I'm aiming to do, is raise the level of all NPCs to 20, adjusting their stats depending on their class, and have some classes give an even higher level boost also dependent on their class. But, sadly, no documentation. This is what I've got so far:

sub main {

 

    my($npcToChange) = @_;
    my $iCurrentLevel = 0;
    my $iNewLevel = 20;

 

    if ($npcToChange->rectype eq 'NPC_'){

 

        

 

    }

 

}

Yeah it's not much, since I'm already at a roadblock. I now want to check against the current NPC's level. Using this part of a script as reference:
 

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; 
               }
            }

How do I find the names of the flags and data, that TES3CMD has given them? is_interior is a flag that's not present in the Construction set, so I'm left being very ignorant.

Rot's picture
Rot
Quest Developer
Joined:
2014-03-16 17:45
Last seen:
1 year 10 months ago

Help for this was found on the modding discord server