-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWYN output NPCs.pas
More file actions
185 lines (144 loc) · 5.27 KB
/
WYN output NPCs.pas
File metadata and controls
185 lines (144 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
{
Run on NPCs, it will generate addModEntryToFormlist commands
}
unit userscript;
uses praUtil;
var
doBlacklist: boolean;
flstName, modeName: string;
validRaces: TStringList;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
begin
Result := 0;
doBlacklist := true;
if(doBlacklist) then begin
flstName := 'formBlackList';
modeName := 'blacklist';
end else begin
flstName := 'actorWhiteList';
modeName := 'whitelist';
end;
validRaces := TStringList.create;
validRaces.add('HumanRace');
validRaces.add('HumanChildRace');
validRaces.add('GhoulRace');
validRaces.add('GhoulChildRace');
end;
function getScriptCheckActor(actor: IInterface): IInterface;
var
useScriptTemplate: boolean;
templateActor: IInterface;
begin
Result := actor;
useScriptTemplate := GetElementEditValues(actor, 'ACBS\Use Template Actors\Script') = '1';
if(useScriptTemplate) then begin
// get template, recurse into
templateActor := PathLinksTo(actor, 'TPTA\Script');
if(assigned(templateActor)) then begin
// AddMessage('got '+displayName(templateActor));
Result := getScriptCheckActor(templateActor);
end;
end;
end;
function getFactionCheckActor(actor: IInterface): IInterface;
var
useScriptTemplate: boolean;
templateActor: IInterface;
begin
Result := actor;
useScriptTemplate := GetElementEditValues(actor, 'ACBS\Use Template Actors\Factions') = '1';
if(useScriptTemplate) then begin
// get template, recurse into
templateActor := PathLinksTo(actor, 'TPTA\Factions');
if(assigned(templateActor)) then begin
// AddMessage('got '+displayName(templateActor));
Result := getScriptCheckActor(templateActor);
end;
end;
end;
function checkSettlerScript(actor: IInterface): boolean;
var
useScriptTemplate: boolean;
templateActor: IInterface;
begin
templateActor := getScriptCheckActor(actor);
Result := assigned(templateActor(actor, 'workshopnpcscript'));
end;
function hasFaction(actor: IInterface; factionEdid: string): boolean;
var
factions,curEntry, curFaction: IInterface;
i: integer;
begin
factions := ElementByPath(actor, 'Factions');
for i:=0 to ElementCount(factions) do begin
curEntry := ElementByIndex(factions, i);
curFaction := PathLinksTo(curEntry, 'Faction');
if(EditorID(curFaction) = factionEdid) then begin
Result := true;
exit;
end;
end;
Result := false;
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
var
curFile, script, race, scriptCheckActor, factionsCheckActor: IInterface;
npcName, outputStr: string;
curFormId: cardinal;
begin
Result := 0;
if(Signature(e) <> 'NPC_') then exit;
npcName := DisplayName(e);
if(npcName = '') then exit;
if(doBlacklist) then begin // for whitelist, just do it
if(npcName = 'Settler') then exit;
// condition is:
{
- race is in (HumanChildRace, HumanRace, GhoulChildRace, GhoulRace, PowerArmorRace)
- has the script
- is not hostile to the player (can't check here)
- does NOT have companionactorscript
- is NOT in DomesticAnimalFaction
- is not dead (can't check here)
- is in faction WorkshopNPCFaction
}
scriptCheckActor := getScriptCheckActor(e);
//if(not checkSettlerScript(e)) then exit;
// Add extended script check
script := getScript(scriptCheckActor, 'workshopnpcscript');
if(not assigned(script)) then exit;
//AddMessage('no workshopnpcscript');
script := getScript(scriptCheckActor, 'companionactorscript');
if(assigned(script)) then exit;
//AddMessage('has companionactorscript');
race := pathLinksTo(e, 'RNAM');
if(validRaces.indexOf(EditorID(race)) < 0) then exit;
factionsCheckActor := getFactionCheckActor(e);
if(hasFaction(factionsCheckActor, 'DomesticAnimalFaction')) then exit;
if(not hasFaction(factionsCheckActor, 'WorkshopNPCFaction')) then exit;
end;
e := MasterOrSelf(e);
curFile := GetFile(e);
curFormId := FormID(e);
if(IsFileLight(curFile)) then begin
curFormId := $FFF and curFormId;
end else begin
curFormId := $FFFFFF and curFormId;
end;
outputStr := 'addModEntryToFormlist(0x'+IntToHex(curFormId, 8)+', "' + GetFileName(curFile) + '", '+flstName+', "'+modeName+'")';
outputStr := outputStr + ' ; ' + EditorID(e)+' "'+npcName+'"';// + EditorID(race);
AddMessage(outputStr);
// addModEntryToFormlist(0x0005D858, "RecruitableSettlersFH.esp", formBlackList, "blacklist")
// addModEntryToFormlist(0x0000BE4C, "DLCNukaWorld.esm", actorWhiteList, "whitelist")
end;
// Called after processing
// You can remove it if script doesn't require finalization code
function Finalize: integer;
begin
Result := 0;
validRaces.free();
end;
end.