unit GreatScript ;

interface

implementation

//uses xEditAPI, Classes, SysUtils, StrUtils, Windows;

// Called before processing

// You can remove it if script doesn't require initialization code

// CrFeralGhoul1A "Feral Ghoul" [CREA:0009FAFA]

var

NewFile : IwbFile ;

CopiedPart : IwbElement ;

FlagList : IwbElement ;

procedure SetFlag ( elem : IInterface ; flagName : string ; flagValue : boolean ) ;

var

sl : TStringList ;

i : Integer ;

f , f2 : Cardinal ;

begin

sl : = TStringList . Create ;

sl . Text : = FlagValues ( elem ) ;

f : = GetNativeValue ( elem ) ;

for i : = 0 to Pred ( sl . Count ) do

if SameText ( sl [ i ] , flagName ) then

begin

if flagValue then

f2 : = f or ( 1 shl i )

else

f2 : = f and not ( 1 shl i ) ;

if f <> f2 then

SetNativeValue ( elem , f2 ) ;

Break ;

end ;

sl . Free ;

end ;

function Initialize : Integer ;

begin

NewFile : = AddNewFileName ( 'InsectRemoveMe.esp' ) ;

AddMasterIfMissing ( NewFile , 'FalloutNV.esm' ) ;

Add ( NewFile , 'CREA' , true ) ;

Result : = 0 ;

end ;

// called for every record selected in xEdit

function Process ( e : IInterface ) : Integer ;

begin

Result : = 0 ;

if signature ( e ) = 'CREA' then

begin

if GetElementEditValues ( e , 'DATA\Type' ) = 'Mutated Insect' then

begin

AddMessage ( 'Processing: ' + FullPath ( e ) ) ;

CopiedPart : = wbCopyElementToFile ( e , NewFile , False , true ) ;

if not Assigned ( CopiedPart ) then

begin

AddMessage ( 'Can' 't copy base record as new' ) ;

Result : = 1 ;

Exit ;

end ;

SetElementEditValues ( CopiedPart , 'TPLT' ,

'CrFeralGhoul1A "Feral Ghoul" [CREA:0009FAFA]' ) ;

SetFlag ( ElementByPath ( CopiedPart , 'ACBS - Configuration\Template Flags' ) ,

'Use Model/Animation' , true ) ;

end ;

end ;

// comment this out if you don't want those messages

// processing code goes here

end ;

// Called after processing

// You can remove it if script doesn't require finalization code

function Finalize : Integer ;

begin

Result : = 0 ;

end ;