1
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 lines
2.6 KiB (Stored with Git LFS)

{
Create patch plugin with "No Respawn" flag on references.
}
unit FindRespawningItems;
var
plugin: IInterface;
bSkipSection: bool;
sFormType: string;
function Initialize: Integer;
begin
if not InputQuery('Filter By Form', 'WEAP, ARMO, etc.', sFormType) then
Exit;
if sFormType = '' then
Exit;
end;
function HasScript(e: IInterface; aScript: string): Boolean;
var
i: integer;
begin
if Name(e) = 'scriptName' then begin
Result := SameText(GetEditValue(e), aScript);
bSkipSection := True;
end else
for i := 0 to Pred(ElementCount(e)) do begin
Result := HasScript(ElementByIndex(e, i), aScript);
if bSkipSection then begin
bSkipSection := False;
Exit;
end;
if Result then Exit;
end;
end;
function Process(e: IInterface): Integer;
var
r: IInterface;
sFormID: string;
begin
// process only references
if Signature(e) <> 'REFR' then
Exit;
// only master references
if not IsMaster(e) then
Exit;
// but work with the current winning override
e := WinningOverride(e);
// references of activator only
if Signature(BaseRecord(e)) <> sFormType then
Exit;
if GetElementEditValues(e, 'Record Header\Record Flags\No Respawn') = '1' then
exit;
// create a new plugin if not created yet or use the last loaded
if not Assigned(plugin) then begin
if MessageDlg('Create a new plugin [YES] or append to the last loaded one [NO]?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
plugin := AddNewFile
else
plugin := FileByIndex(Pred(FileCount));
if not Assigned(plugin) then begin
Result := 1;
Exit;
end;
end;
// add masters before copying as override for parent CELL
AddRequiredElementMasters(LinksTo(ElementByIndex(e, 0)), plugin, False);
// and REFR itself
AddRequiredElementMasters(e, plugin, False);
try
// winning cell override
r := WinningOverride(LinksTo(ElementByName(e, 'Cell')));
if GetFile(r) <> plugin then begin
AddRequiredElementMasters(r, plugin, False);
wbCopyElementToFile(r, plugin, False, True);
end;
// copy reference as override
r := wbCopyElementToFile(e, plugin, False, True);
// set No Respawn flag (bit 30)
SetElementNativeValues(r, 'Record Header\Record Flags', GetElementNativeValues(r, 'Record Header\Record Flags') or (1 shl 30));
except
on Ex: Exception do begin
AddMessage('Failed to copy: ' + FullPath(e));
AddMessage(' reason: ' + Ex.Message);
end;
end;
end;
function Finalize: integer;
begin
if Assigned(plugin) then
SortMasters(plugin);
end;
end.