-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFPFP_BabyScript.psc
461 lines (310 loc) · 13 KB
/
FPFP_BabyScript.psc
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
Scriptname FPFP_BabyScript extends ObjectReference
FPFP_Player_Script FPE ; holds the main quest for getting FPE global variables without needing FPE as an esp master
FPFP_BabyHandlerScript BabyHandler ; holds the handler for interactions and resetting
Group ChildProperties
ActorBase[] property Children_F auto const Mandatory; Stores the female child actor bases
ActorBase[] property Children_M auto const Mandatory; Stores the male child actor bases
{Stores the male and female child actor bases that the baby will grow into.
This can also be fully grown adult actors, if you wish to skip the growing child stage}
Float property GrowthTimeMultiplier = 1.0 Auto Const
{This value will be multiplied into the baby's growth time, so a lower value means faster growth.
This value is passed onto the child actor the baby spawns.}
Bool Property IsWorkshopActor = False Auto Const
{This value determines if the child that the baby will grow up to be can be in a workshop.}
Bool Property Killable = True Auto Const
{This value determines if the baby can be killed from an attack from the player character.
You'd have to be a real monster to kill a baby.}
Sound Property BirthSound Auto Const
{This object determines what the baby noise will be when born.
If set to nothing, then default noises are played.}
EndGroup
Group DoNotEditInCreationKit
Float property BirthDate Auto ; Stores bday. When child actor is created, use the actorvalue to have the child inherit the birthday
{This value is only used via scripts. Do not edit this value.}
ObjectReference Property CribOR Auto; Stores the crib ref
{This value is only used via scripts. Do not edit this value.}
ObjectReference Property ContainerOR Auto; Stores the container we're in. Mainly for persistence so that the baby can properly grow in the inventory
{This value is only used via scripts. Do not edit this value.}
Bool Property IsGrowingUp Auto
{This value is only used via scripts. Do not edit this value.}
EndGroup
Actor Target
Form TheBaby
GlobalVariable property FPFP_Global_Gender_Select Auto Const Mandatory
GlobalVariable property FPFP_Global_Rename_Baby Auto Const Mandatory
String property Babies_Original_Name Auto Const Mandatory
Event OnEquipped(Actor akActor)
Target = akActor
TheBaby = Self
EndEvent
Event OnInit()
Container Bad_Container
If Game.IsPluginInstalled("ESPExplorerFO4.esp")
Bad_Container = Game.GetFormFromFile(0x001742, "ESPExplorerFO4.esp") as Container
Else
Bad_Container = None
EndIf
If Bad_Container && Self.GetContainer().GetBaseObject() == Bad_Container
Trace("On init has failed because of ESPExplorerFO4")
Else
Trace("On init has started")
If IsBoundGameObjectAvailable(); Make sure we are a loaded object so that the papyrus logs don't throw us errors
Trace("On init has determined we aren't NONE")
FPE = FPFP_Player_Script.GetAPI()
BabyHandler = FPFP_Player_Script.GetBabyAPI()
If !FPE || !BabyHandler
Debug.MessageBox("WARNING: FPE API(s) HAVE NOT BEEN PROPERLY SET. QUIT THE GAME AND GO TO THE FAMILY PLANNING ENHANCED THREAD TO REPORT THIS ISSUE WITH YOUR PAPYRUS LOGS READY.")
EndIf
RegisterForHitEvent(Self)
RegisterForCustomEvent(BabyHandler, "FPEBabyUpdateGameTimer")
RegisterForCustomEvent(FPE, "DoUpdate")
RegisterForCustomEvent(FPE, "DoCleaning")
RegisterForCustomEvent(FPE, "DoReset")
BirthDate = Utility.GetCurrentGameTime()
StartTimerGameTime(GetBabyToChildTimeLeft()) ; Start a timer
Trace("On init has finished internal setup of timers and quests")
Else
Trace("ERROR Okay bethesda why was a script run when we don't even have an object bound to us!?")
EndIf
Trace("On init has finished")
Endif
EndEvent
Float Function GetBabyToChildTimeLeft()
Return ((FPE.FPFP_Global_BabyToChild.GetValue() * GetGrowthMultiplier() * FPE.FPFP_Global_Day.GetValue()) - (Utility.GetCurrentGameTime() - BirthDate)) * 24
EndFunction
Event FPFP_BabyHandlerScript.FPEBabyUpdateGameTimer(FPFP_BabyHandlerScript akSender, Var[] akArgs)
CancelTimerGameTime()
float timeLeftToGrow = GetBabyToChildTimeLeft()
If timeLeftToGrow > 0.033
StartTimerGameTime(timeLeftToGrow)
Else
GrowIntoChild()
EndIf
EndEvent
Sound Function GetBabyBirthSound()
If BirthSound
Return BirthSound
EndIf
Return BabyHandler.VOCShaun
EndFunction
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) ; Base functionality, best not to change it
Container Bad_Container
If Game.IsPluginInstalled("ESPExplorerFO4.esp")
Bad_Container = Game.GetFormFromFile(0x001742, "ESPExplorerFO4.esp") as Container
Else
Bad_Container = None
EndIf
If Bad_Container && akNewContainer.GetBaseObject() == Bad_Container
Trace("OnContainerChanged has failed because of ESPExplorerFO4")
Else
Trace("We've been moved to " + akNewContainer + " from " + akOldContainer)
If IsGrowingUp
Trace("It was done while growing up")
Return
EndIf
ContainerOR = akNewContainer ; Whatever the container is, we shove it into the ContainerOR. ; ovh do a no container check that would initiate looking for a crib.
If ContainerOR ; put into a container
If CribOR
BabyHandler.SetCribOwner(CribOR, False)
CribOR = NONE
EndIf
If ContainerOR == FPE.PlayerREF
BabyHandler.ShowBabyInfo(self)
EndIf
ElseIf akOldContainer && akOldContainer As Actor; we were taken out of a valid container
Location CurLo = akOldContainer.GetCurrentLocation()
PlaceSelfAt(akOldContainer)
If CurLo && CurLo.HasKeyword(BabyHandler.KeySettle)
CribOR = BabyHandler.GetCrib()
If CribOR
BabyHandler.SetCribOwner(CribOR)
PlaceSelfAt(CribOR, 52.0)
EndIf
If akOldContainer == FPE.PlayerREF
debug.messagebox("This baby will now be brought up by the people at "+CurLo.GetName())
EndIf
EndIf
EndIf
EndIf
EndEvent
Function PlaceSelfAt(ObjectReference akDestination, float afHeight = 4.0); Dear christ get a good math education folks, it's important in the programming field.
; All these values found via experimentation with the creation kit. Painstankingly found. Very painful.
;/
For angles
At destAZ = 0 || X = -90 | y = -90 | z = 0
At destAZ = 45 || X = -90 | y = -45 | z = 0
At destAZ = 90 || X = -90 | y = 0 | z = 0
At destAZ = 135 || X = -90 | y = 45 | z = 0
At destAZ = 180 || X = 90 | y = 90 | z = 180
At destAZ = 225 || X = 90 | y = 45 | z = 180
At destAZ = 270 || X = 90 | y = 0 | z = 180
At destAZ = 305 || X = 90 | y = -45 | z = 180
/;
float destAZ = UnsignAngle(akDestination.GetAngleZ())
float xAngle
float yAngle
float zAngle
If destAZ < 180 ; If we're within 0 to less than 180
xAngle = -90
yAngle = -90 + destAZ
zAngle = 0
Else ; Otherwise, we're either 180 to less than 360
xAngle = 90
yAngle = 270 - destAZ
zAngle = 180
EndIf
;/
For x and y position
At destAZ = 0 || X = -16 | y = 0
At destAZ = 90 || X = 0 | y = 16
At destAZ = 180 || X = 16 | y = 0
At destAZ = 270 || X = 0 | y = -16
/;
float xChange = akDestination.GetPositionX() + ( -16 * Math.Cos(destAZ) )
float yChange = akDestination.GetPositionY() + ( 16 * Math.Sin(destAZ) )
float zChange = akDestination.GetPositionZ() + afHeight
setPosition(xChange, yChange, zChange)
setAngle(xAngle, yAngle, zAngle)
EndFunction
Float Function UnsignAngle(float afAngle); Take the angle and put it somewhere between 0 and 360 (Inclusive and exclusive respectively)
If afAngle <= -360 || afAngle >= 360 ; If we're, oddly enough, >= 360 or we're <= -360, we take our number and put it within the range of > -360 and < 360
int deltaModulus = (afAngle / 360) as int
afAngle = afAngle - ( 360 * deltaModulus ) ; remove all the extra amount of angle
EndIf
If afAngle < 0 ;Then we check if the angle is negative and make it the positive value
afAngle += 360
EndIf
Return afAngle
EndFunction
Event OnTimerGameTime(int aiTID)
GrowIntoChild()
EndEvent
Float Function GetGrowthMultiplier()
If GrowthTimeMultiplier > 0 ; if the float property was valid
Return GrowthTimeMultiplier ; return it
Else
Return 1.0 ; return a normal number if it was not normal
EndIf
EndFunction
Function GrowIntoChild()
If !IsBoundGameObjectAvailable()
Trace("WARNING No bound object on growth call, shut er down")
StartDelete()
Return
EndIf
If IsGrowingUp
Trace("WARNING We were already grown up! shut er down")
StartDelete()
Return
EndIf
If IsDeleted()
Trace("WARNING We are deleted! shut er down")
StartDelete()
Return
EndIf
UnregisterForAllEvents()
IsGrowingUp = True
Trace("Started to grow")
ObjectReference theChild
If ContainerOR
Drop()
Trace("This is what we are now after we dropped")
EndIf
Disable()
theChild = PlaceAtMe(GetChildBase(), 1, False, False, False) ; were're out in the world
If FPFP_Global_Rename_Baby.GetValue() == 1.0
if Babies_Original_Name != RenameAnything.GetRefName(self)
RenameAnything.SetRefName(theChild, RenameAnything.GetRefName(self))
theChild.AddKeyword(Game.GetFormFromFile(0x0001EA88, "FP_FamilyPlanningEnhanced.esp") as Keyword)
endif
endif
Trace("We placed "+theChild)
theChild.SetValue(BabyHandler.FPFP_AV_BirthDate, BirthDate)
theChild.SetValue(BabyHandler.FPFP_AV_GrowthTimeMult, GetGrowthMultiplier())
If HasKeyword(BabyHandler.FPFP_KW_IsPlayersChild)
theChild.AddKeyword(BabyHandler.FPFP_KW_IsPlayersChild)
EndIf
; for SKK50's Fallout 4-76
If (Game.IsPluginInstalled("SKK476OpenWorld.esp") == TRUE)
theChild.AddKeyword(Game.GetFormFromFile(0x00019bcb, "SKK476OpenWorld.esp") as Keyword)
EndIf
Location currentLocation = theChild.GetCurrentLocation()
Trace("grown in location "+ currentLocation)
If FPE.FPFP_Global_BGNotif.GetValue() == 1.0 && currentLocation
string locName = currentLocation.GetName()
If locName == "Commonwealth"
Debug.Notification("A baby has grown into an child in the Commonwealth")
Else
Debug.Notification("A baby has grown into an child at "+ locName)
EndIf
EndIf
DetermineWorkshop(currentLocation, theChild)
If theChild as FPFP_GrowingChildScript ; init the child now that everything should be set up
(theChild as FPFP_GrowingChildScript).Initialize()
EndIf
StartDelete()
EndFunction
ActorBase Function GetChildBase()
int random_LList = Utility.RandomInt(1, 100)
if (random_LList <= FPFP_Global_Gender_Select.GetValue())
Return Children_F[Utility.RandomInt(0,Children_F.Length-1)]
else
Return Children_M[Utility.RandomInt(0,Children_M.Length-1)]
EndIf
EndFunction
Function DetermineWorkshop(Location akLocation, ObjectReference akChild)
If IsWorkshopActor
If akLocation && akLocation.HasKeyword(BabyHandler.KeySettle)
WorkshopScript theWorkshop = BabyHandler.WorkshopParent.GetWorkshopFromLocation(akLocation)
Debug.Trace("Family Planning Enhanced : A Baby has grown in location with workshop "+ theWorkshop)
BabyHandler.WorkshopParent.AddActorToWorkshopPUBLIC(akChild as WorkshopNPCScript, theWorkshop)
EndIf
EndIf
EndFunction
Event OnHit(ObjectReference akTarget, ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked, string apMaterial)
If Killable && FPE.PlayerRef == (akAggressor as Actor)
EndBaby()
Else
RegisterForHitEvent(Self)
EndIf
EndEvent
Function EndBaby()
PlayImpactEffect(BabyHandler.BloodSprayImpactSetRed, "Skin_Baby_BN_C_Spine"); Place blood decal to show that you're a monster you fuck
BabyHandler.FXExplosionLimb.Play(Self)
Disable()
StartDelete()
Debug.Trace("Family Planning Enhanced: Baby "+ Self +" has been killed! You fucking monster.")
EndFunction
Function StartDelete()
BabyHandler.SetCribOwner(CribOR, False) ; Remove crib ownership
CribOR = NONE
ContainerOR = NONE
UnregisterForAllEvents()
CancelTimerGameTime()
If IsBoundGameObjectAvailable()
Delete()
EndIf
EndFunction
Event FPFP_Player_Script.DoUpdate(FPFP_Player_Script akSender, Var[] akArgs)
;update code
Trace("Doing update")
EndEvent
Event FPFP_Player_Script.DoCleaning(FPFP_Player_Script akSender, Var[] akArgs)
Trace("Doing Cleaning")
If !IsBoundGameObjectAvailable()
Trace("WARNING No bound object on cleaning event handle, shut er down")
StartDelete()
EndIf
If IsGrowingUp
Trace("WARNING We were already grown up on cleaning event handle! shut er down")
StartDelete()
EndIf
EndEvent
Event FPFP_Player_Script.DoReset(FPFP_Player_Script akSender, Var[] akArgs)
Trace("Doing reset")
;delete self
StartDelete()
EndEvent
Function Trace(string theString)
Debug.Trace("FPE BabyScript "+Self+" : " +theString)
EndFunction