Guest User

Untitled

a guest
Aug 4th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.30 KB | None | 0 0
  1. {
  2.   Count References in persistent cells
  3. }
  4. unit userscript;
  5.  
  6. var
  7.   total: cardinal;
  8.   sl1, sl2: TwbFastStringList;
  9.  
  10. function Initialize: integer;
  11. var
  12.   i, j, k, l, count: integer;
  13.   e, c, g, wrlds, wrld, wrldgrup, block: IInterface;
  14.   s: string;
  15.   b: bool;
  16. begin
  17.   sl1 := TwbFastStringList.Create;
  18.   sl2 := TwbFastStringList.Create;
  19.   for i := 0 to Pred(FileCount) do begin
  20.     wrlds := GroupBySignature(FileByIndex(i), 'WRLD');
  21.     if not Assigned(wrlds) then
  22.       Continue;
  23.      for j := 0 to Pred(ElementCount(wrlds)) do begin
  24.       wrld := ElementByIndex(wrlds, j);
  25.       if ElementType(wrld) <> etMainRecord then
  26.         Continue;
  27.       wrldgrup := ChildGroup(wrld);
  28.       for j := 0 to Pred(ElementCount(wrldgrup)) do begin
  29.         e := ElementByIndex(wrldgrup, j);
  30.         if GetIsPersistent(e) then begin
  31.           b := False;
  32.           count := 0;
  33.           g := ElementByIndex(ChildGroup(e), 0);
  34.           s := EditorID(LinksTo(ElementByPath(LinksTo(ElementByPath(e, 'Worldspace')), 'Parent\WNAM')));
  35.           if s = '' then begin
  36.             s := EditorID(LinksTo(ElementByPath(e, 'Worldspace')));
  37.             b := True;
  38.           end;
  39.           for l := 0 to Pred(ElementCount(g)) do begin
  40.             c := ElementByIndex(g, l);
  41.             if Assigned(c) and IsMaster(c) then
  42.               inc(count);
  43.           end;
  44.           if (GetElementNativeValues(LinksTo(ElementByPath(e, 'Worldspace')), 'Parent\PNAM\Flags') and $40 = $40) then
  45.             AddMessage(Format('%d'#9'%s for %s in %s (f)', [count, GetFileName(GetFile(g)), s, EditorID(LinksTo(ElementByPath(e, 'Worldspace')))]))
  46.           else
  47.             AddMessage(Format('%d'#9'%s for %s in %s', [count, GetFileName(GetFile(g)), s, EditorID(LinksTo(ElementByPath(e, 'Worldspace')))]));
  48.           if sl1.IndexOf(s) = -1 then
  49.             sl1.AddObject(s, count)
  50.           else begin
  51.             i := Integer(sl1.Objects[sl1.IndexOf(s)]);
  52.             i := i + count;
  53.             sl1.Objects[sl1.IndexOf(s)] := i;
  54.           end;
  55.           if b or (GetElementNativeValues(LinksTo(ElementByPath(e, 'Worldspace')), 'Parent\PNAM\Flags') and $40 = $40) then begin
  56.             if sl2.IndexOf(s) = -1 then
  57.               sl2.AddObject(s, count)
  58.             else begin
  59.               i := Integer(sl2.Objects[sl2.IndexOf(s)]);
  60.               i := i + count;
  61.               sl2.Objects[sl2.IndexOf(s)] := i;
  62.             end;
  63.           end;
  64.           total := total + count;
  65.         end;
  66.       end;
  67.     end;
  68.   end;
  69. end;
  70.  
  71. function Finalize: integer;
  72. var
  73.   i: integer;
  74. begin
  75.   Result := 0;
  76.  
  77.   AddMessage('');
  78.   AddMessage('==============================');
  79.   AddMessage('Total for each parent world including child worlds with Use Sky Cell flag');
  80.  
  81.   for i := 0 to Pred(sl2.Count) do begin
  82.     AddMessage(sl2[i] + #9 + IntToStr(Integer(sl2.Objects[i])));
  83.   end;
  84.  
  85.   AddMessage('');
  86.   AddMessage('==============================');
  87.   AddMessage('Total for each parent world including all child worlds');
  88.  
  89.   for i := 0 to Pred(sl1.Count) do begin
  90.     AddMessage(sl1[i] + #9 + IntToStr(Integer(sl1.Objects[i])));
  91.   end;
  92.  
  93.   if total > 0 then
  94.     AddMessage('');
  95.     AddMessage('==============================');
  96.     AddMessage(Format('%d'#9'%s', [total, 'Grand Total']));
  97.  
  98.   AddMessage('');
  99.  
  100.   sl1.Free;
  101.   sl2.Free;
  102. end;
  103.  
  104. end.
Add Comment
Please, Sign In to add comment