Author Topic: Finding Where a Script is Used in a Placeable  (Read 790 times)

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Finding Where a Script is Used in a Placeable
« on: February 19, 2015, 08:33:56 pm »


               

Its there a tool that I can use to browse (or possibly use Leto to search) the scripts attached to placeables and return the area associated with that placeable?  I'm searching specifically for some onspawn scripts that are tied to some CEP placeables and I'd rather not have to open each area and open the properties of every placeable to identify if it uses the script.


 


Thanks!



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Finding Where a Script is Used in a Placeable
« Reply #1 on: February 19, 2015, 10:06:17 pm »


               Easily done with Moneo:


http://forum.bioware...ne-your-module/


Well worth the learning curve, as it saves so much time in many other situations, too.
               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Finding Where a Script is Used in a Placeable
« Reply #2 on: February 20, 2015, 09:15:59 pm »


               

Yeah, I figured it was going to involve finally having to dive into this.  Been meaning to get to it, but putting it off as it was more a 'nice to know' rather than supporting any active development I'm doing.


 


But now since I have a need...


 


My first question:


The scripts for the placeables are contained in the area's .git resource.  The area's name/tag are stored in the .are resource.  How do I hook into the .ARE as I loop through placeables in the .GIT to identify what area they're in?


 


Below is the moneo script I have so far.  It gets me the placeable info, but I need to tie in the area name.


 




%mod = 'MODNAME.mod';


for (%mod['*.git']) {
  for (/{'Placeable List'}) {
        print /~/TemplateResRef, ";", /~/OnHeartbeat,";";
  }  
}


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Finding Where a Script is Used in a Placeable
« Reply #3 on: February 21, 2015, 10:32:02 am »


               

I haven't tested this, but the gist is



%mod = 'MODNAME.mod';
$area = $_;
for (%mod['*.git']) {
  for (/{'Placeable List'}) {
        print $area,/~/TemplateResRef, ";", /~/OnHeartbeat,";", "\n";
  } 
}

I've put in \n to print each instance on a new line, which you might not want!

 

$_ returns the current instance of the loop variable. This will be the name of the .git file. Hopefully that's good enough. EDIT : If you have to have the area name see post below. , I'm not certain how to do it, though you could try
$area = $_;

for (%mod[$area + '.are']) {$areaname = /name;}


 

If you're only looking for one script, you could make the print conditional, e.g.

 



if  (/~/OnHeartbeat eq '++name of script here+++') {print $area,/~/TemplateResRef, ";","\n";}


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Finding Where a Script is Used in a Placeable
« Reply #4 on: February 22, 2015, 11:08:33 am »


               

If you have to have the area name, I'm not certain how to do it, though you could try



$area = $_;
for (%mod[$area + '.are']) {$areaname = /name;}


Edit : forget this!

I tested this, and several other methods, but none of them seem to work. Perhaps Moneo only works with one file list at a time?


Maybe you could use Moneo to list placeables by area resref, then area names by area resref (cycling through the .are files), then join the two files in a spreadsheet, to make a list of placeables by area name.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Finding Where a Script is Used in a Placeable
« Reply #5 on: February 22, 2015, 02:03:19 pm »


               Correction : here is a script that does exactly what you need, I think:
 
# Find all placeables with a given script by area

%mod = 'c:\NeverwinterNights\nwn\modules\Dark Energy.mod' or die;

for (%mod['*.git'])
  {
    $area = substr($_, 0, -4);
    %are = %mod[$area + '.are'];
    $areaname = /Name;
    close (%are);       
    for (/{'Placeable List'})
      {
        if (/~/OnHeartbeat ne '')
     {print $area, ";", $areaname, ";", /~/TemplateResRef, ";", /~/OnHeartbeat,";", "\n";}
      }  
  }
The trick is to open the .are file as a new handle, work with its fields, then close it, so that Moneo reverts to working with the current .git file. That way, it's always clear which file Moneo is working with.
               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Finding Where a Script is Used in a Placeable
« Reply #6 on: February 22, 2015, 07:16:44 pm »


               

Brilliant, Proleric!  Worked like a charm.  Exactly what I was needing and I would never had figured that out.  I had intended to add a conditional to just look for instances where the script was in place, so thanks for adding that.


 


It's not so different than nw script, though there are enough differences and syntax changes to make it non-intuitive.  Over time and use, I'll get used to it enough, though.


 


Thanks again.