Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Count References in persistent cells
- }
- unit userscript;
- var
- total: cardinal;
- sl1, sl2: TwbFastStringList;
- function Initialize: integer;
- var
- i, j, k, l, count: integer;
- e, c, g, wrlds, wrld, wrldgrup, block: IInterface;
- s: string;
- b: bool;
- begin
- sl1 := TwbFastStringList.Create;
- sl2 := TwbFastStringList.Create;
- for i := 0 to Pred(FileCount) do begin
- wrlds := GroupBySignature(FileByIndex(i), 'WRLD');
- if not Assigned(wrlds) then
- Continue;
- for j := 0 to Pred(ElementCount(wrlds)) do begin
- wrld := ElementByIndex(wrlds, j);
- if ElementType(wrld) <> etMainRecord then
- Continue;
- wrldgrup := ChildGroup(wrld);
- for j := 0 to Pred(ElementCount(wrldgrup)) do begin
- e := ElementByIndex(wrldgrup, j);
- if GetIsPersistent(e) then begin
- b := False;
- count := 0;
- g := ElementByIndex(ChildGroup(e), 0);
- s := EditorID(LinksTo(ElementByPath(LinksTo(ElementByPath(e, 'Worldspace')), 'Parent\WNAM')));
- if s = '' then begin
- s := EditorID(LinksTo(ElementByPath(e, 'Worldspace')));
- b := True;
- end;
- for l := 0 to Pred(ElementCount(g)) do begin
- c := ElementByIndex(g, l);
- if Assigned(c) and IsMaster(c) then
- inc(count);
- end;
- if (GetElementNativeValues(LinksTo(ElementByPath(e, 'Worldspace')), 'Parent\PNAM\Flags') and $40 = $40) then
- AddMessage(Format('%d'#9'%s for %s in %s (f)', [count, GetFileName(GetFile(g)), s, EditorID(LinksTo(ElementByPath(e, 'Worldspace')))]))
- else
- AddMessage(Format('%d'#9'%s for %s in %s', [count, GetFileName(GetFile(g)), s, EditorID(LinksTo(ElementByPath(e, 'Worldspace')))]));
- if sl1.IndexOf(s) = -1 then
- sl1.AddObject(s, count)
- else begin
- i := Integer(sl1.Objects[sl1.IndexOf(s)]);
- i := i + count;
- sl1.Objects[sl1.IndexOf(s)] := i;
- end;
- if b or (GetElementNativeValues(LinksTo(ElementByPath(e, 'Worldspace')), 'Parent\PNAM\Flags') and $40 = $40) then begin
- if sl2.IndexOf(s) = -1 then
- sl2.AddObject(s, count)
- else begin
- i := Integer(sl2.Objects[sl2.IndexOf(s)]);
- i := i + count;
- sl2.Objects[sl2.IndexOf(s)] := i;
- end;
- end;
- total := total + count;
- end;
- end;
- end;
- end;
- end;
- function Finalize: integer;
- var
- i: integer;
- begin
- Result := 0;
- AddMessage('');
- AddMessage('==============================');
- AddMessage('Total for each parent world including child worlds with Use Sky Cell flag');
- for i := 0 to Pred(sl2.Count) do begin
- AddMessage(sl2[i] + #9 + IntToStr(Integer(sl2.Objects[i])));
- end;
- AddMessage('');
- AddMessage('==============================');
- AddMessage('Total for each parent world including all child worlds');
- for i := 0 to Pred(sl1.Count) do begin
- AddMessage(sl1[i] + #9 + IntToStr(Integer(sl1.Objects[i])));
- end;
- if total > 0 then
- AddMessage('');
- AddMessage('==============================');
- AddMessage(Format('%d'#9'%s', [total, 'Grand Total']));
- AddMessage('');
- sl1.Free;
- sl2.Free;
- end;
- end.
Add Comment
Please, Sign In to add comment