Skip to content

Commit bf1b9a0

Browse files
committed
Default PetFramework scripts to be edited
1 parent f5d2b63 commit bf1b9a0

File tree

2 files changed

+228
-0
lines changed

2 files changed

+228
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Scriptname PetFramework_ParentQuestScript extends Quest
2+
{Get/Set functions for pet count and limit checks. All other shared controls are in PetFramework_PetScript.}
3+
;rvogel 9/2017
4+
5+
GlobalVariable Property PetFramework_MaxPets Auto ;Max number of pets who can follow at once, default is 2
6+
7+
;RefAliases to fill from DLC at runtime
8+
9+
ReferenceAlias Property DLC2SeverinManorEnableMarker Auto
10+
ReferenceAlias Property HomeMarkerDLC2SeverinManor Auto
11+
12+
ReferenceAlias Property BYOH01DoorLakeviewManor Auto
13+
ReferenceAlias Property BYOH02DoorWindstadManor Auto
14+
ReferenceAlias Property BYOH03DoorHeljarchenHall Auto
15+
16+
ReferenceAlias Property HomeMarkerLakeviewManor Auto
17+
ReferenceAlias Property HomeMarkerWindstadManor Auto
18+
ReferenceAlias Property HomeMarkerHeljarchenHall Auto
19+
20+
Faction Property PetFramework_PetFaction Auto
21+
Faction Property PlayerFaction Auto
22+
23+
Faction Property CWSonsFaction Auto
24+
Faction Property CWImperialFaction Auto
25+
26+
Int Property CurrentPetCount = 0 Auto Hidden ;Current count of pets, this is manipulated by pet ESPs/ESLs using the functions below
27+
28+
Event OnInit()
29+
debug.trace("Setting pet and player relationship to ally")
30+
PetFramework_PetFaction.SetAlly(PlayerFaction)
31+
32+
;Prevent CW actors from becoming hostile to pets
33+
PetFramework_PetFaction.SetAlly(CWSonsFaction)
34+
PetFramework_PetFaction.SetAlly(CWImperialFaction)
35+
EndEvent
36+
37+
Int Function GetCurrentPetCount()
38+
{Called by 'child' pet ESPs/ESLs to get current count and limit}
39+
Return CurrentPetCount
40+
EndFunction
41+
42+
Int Function GetMaxPets()
43+
{Called by 'child' pet ESPs/ESLs to get max pets}
44+
Return PetFramework_MaxPets.GetValue() as Int
45+
EndFunction
46+
47+
Function IncrementPetCount()
48+
{Called by 'child' pet ESPs/ESLs to update active pet count}
49+
CurrentPetCount += 1
50+
EndFunction
51+
52+
Function DecrementPetCount()
53+
{Called by 'child' pet ESPs/ESLs to update active pet count}
54+
If(CurrentPetCount > 0)
55+
CurrentPetCount -= 1
56+
EndIf
57+
EndFunction
58+
59+
Bool Function HasMaxPets()
60+
{Called to check if the player has the maximum pets allowed}
61+
62+
If(GetCurrentPetCount() == GetMaxPets())
63+
Return True
64+
Else
65+
Return False
66+
EndIf
67+
68+
EndFunction
69+
70+
71+
Function FillRefAliasesFromDLC()
72+
{Called from first stage of quest to fill aliases from DLC that are unreachable by Update.esm}
73+
74+
;Dragonborn Refs (Marker and Chest used to check ownership)
75+
ObjectReference DLC2SeverinManorEnableRef = (Game.GetFormFromFile(0x040396D0, "dragonborn.esm") as ObjectReference)
76+
ObjectReference DLC2SeverinManorMarkerRef = (Game.GetFormFromFile(0x0403BD35, "dragonborn.esm") as ObjectReference)
77+
78+
;Hearthfire Refs (Doors)
79+
ObjectReference DoorLakeviewManorRef = (Game.GetFormFromFile(0x03003221, "hearthfires.esm") as ObjectReference)
80+
ObjectReference DoorWindstadManorRef = (Game.GetFormFromFile(0x0300B852, "hearthfires.esm") as ObjectReference)
81+
ObjectReference DoorHeljarchenHallRef = (Game.GetFormFromFile(0x03010DDF, "hearthfires.esm") as ObjectReference)
82+
83+
;Hearthfire Refs (Markers)
84+
ObjectReference MarkerLakeviewManorRef = (Game.GetFormFromFile(0x0300309B, "hearthfires.esm") as ObjectReference)
85+
ObjectReference MarkerWindstadManorRef = (Game.GetFormFromFile(0x0301205C, "hearthfires.esm") as ObjectReference)
86+
ObjectReference MarkerHeljarchenHallRef = (Game.GetFormFromFile(0x03016E05, "hearthfires.esm") as ObjectReference)
87+
88+
;Fill the refs
89+
DLC2SeverinManorEnableMarker.ForceRefTo(DLC2SeverinManorEnableRef)
90+
HomeMarkerDLC2SeverinManor.ForceRefTo(DLC2SeverinManorMarkerRef)
91+
92+
BYOH01DoorLakeviewManor.ForceRefTo(DoorLakeviewManorRef)
93+
BYOH02DoorWindstadManor.ForceRefTo(DoorWindstadManorRef)
94+
BYOH03DoorHeljarchenHall.ForceRefTo(DoorHeljarchenHallRef)
95+
96+
HomeMarkerLakeviewManor.ForceRefTo(MarkerLakeviewManorRef)
97+
HomeMarkerWindstadManor.ForceRefTo(MarkerWindstadManorRef)
98+
HomeMarkerHeljarchenHall.ForceRefTo(MarkerHeljarchenHallRef)
99+
100+
EndFunction
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Scriptname PetFramework_PetQuest extends Quest Conditional
2+
{Manages the pet's home location, commands, etc. Some functions are called from the pet actor script.}
3+
4+
PetFramework_ParentQuestScript Property PetFramework_ParentQuest Auto
5+
Message Property PetFramework_PetDismissMessage Auto
6+
Message Property PetFramework_PetMaxReachedMessage Auto
7+
Faction Property PetFramework_PetFollowingFaction Auto
8+
Faction Property PlayerFaction Auto
9+
Faction Property PetFramework_PetFaction Auto
10+
ReferenceAlias Property PetHomeMarker Auto
11+
ReferenceAlias Property PetRefAlias Auto
12+
ReferenceAlias Property PetDynamicHomeMarker Auto
13+
Bool Property MovingTogglePackageOn = False Auto Conditional Hidden ;Hearthfire adoption/move trick - turn on a temporary package
14+
15+
Function MakePetAvailableToPlayer()
16+
{Called when the quest meets the criteria for the pet to be available, i.e. purchase, rescue, whatever scenario. Without this the pet cannot be talked to or recruited.}
17+
PetRefAlias.GetActorReference().SetFactionRank(PetFramework_PetFaction, 1)
18+
;PetRefAlias.GetActorReference().AddToFaction(PlayerFaction)
19+
EndFunction
20+
21+
Function MakePetUnavailableToPlayer()
22+
{If for some reason we want to make the pet unavailable to player, i.e. sell it someone else, etc. this function will do that}
23+
PetRefAlias.GetActorReference().SetFactionRank(PetFramework_PetFaction, 0)
24+
;PetRefAlias.GetActorReference().RemoveFromFaction(PlayerFaction)
25+
EndFunction
26+
27+
Function FollowPlayer(Bool snapIntoInteraction = False)
28+
{Called when the player recruits the pet via dialogue.}
29+
30+
If(PetFramework_ParentQuest.HasMaxPets())
31+
PetFramework_PetMaxReachedMessage.Show()
32+
Else
33+
34+
debug.trace("Pet Framework: " + PetRefAlias.GetActorReference() + " setting to following player")
35+
debug.trace("Pet Framework: " + PetRefAlias.GetActorReference() + " PetFollowingFactionRank: " + PetRefAlias.GetActorReference().GetFactionRank(PetFramework_PetFollowingFaction))
36+
37+
;If the pet was waiting for the player, clear the actor value (no need to check just run it)
38+
WaitForPlayer(False)
39+
40+
;Set the rank to 1, which will enable dialogue commands, etc. (used by shared pet framework)
41+
PetRefAlias.GetActorReference().SetFactionRank(PetFramework_PetFollowingFaction, 1)
42+
43+
debug.trace("Pet Framework: " + PetRefAlias.GetActorReference() + " PetFollowingFactionRank: " + PetRefAlias.GetActorReference().GetFactionRank(PetFramework_PetFollowingFaction))
44+
45+
;Some animals have very long idles they get 'stuck' which feels like recruiting them didn't do anything
46+
If(snapIntoInteraction)
47+
PetRefAlias.GetReference().Disable()
48+
PetRefAlias.GetReference().Enable()
49+
EndIf
50+
51+
PetFramework_ParentQuest.IncrementPetCount()
52+
debug.trace("Pet Count: " + PetFramework_ParentQuest.GetCurrentPetCount())
53+
54+
;Re-evaluate the package stack based on our new conditions
55+
PetRefAlias.GetActorReference().EvaluatePackage()
56+
57+
EndIf
58+
59+
EndFunction
60+
61+
Function WaitForPlayer(Bool doWait = True)
62+
{True/False: Pet will wait for the player or continue to follow.}
63+
64+
DEBUG.TRACE("WaitForPlayer called with value: " + doWait)
65+
66+
If(doWait == True)
67+
debug.trace("PetFramework Setting pet to wait for player")
68+
PetRefAlias.GetActorReference().SetAV("WaitingForPlayer", 1)
69+
Else
70+
debug.trace("PetFramework Setting pet to stop waiting for player")
71+
PetRefAlias.GetActorReference().SetAV("WaitingForPlayer", 0)
72+
EndIf
73+
74+
;Re-evaluate the package stack based on our new conditions
75+
PetRefAlias.GetActorReference().EvaluatePackage()
76+
77+
EndFunction
78+
79+
Function SetHomeToCurrentLocation()
80+
{Makes the "Home" of the pet right where they stand, so they will dismiss and sandbox the area (house mods, camping, etc.)}
81+
82+
;Move the xmarker to where the pet is standing
83+
PetDynamicHomeMarker.GetReference().MoveTo(PetRefAlias.GetReference())
84+
PetDynamicHomeMarker.GetReference().SetAngle(0,0,0)
85+
86+
;Set the home idle marker to the dynamic marker
87+
SetNewHome(PetDynamicHomeMarker, True)
88+
89+
EndFunction
90+
91+
Function SetNewHome(ReferenceAlias newLocation, Bool dismiss = True, Bool doWarp = False)
92+
93+
debug.trace("Set New Home called from actor proxy")
94+
95+
;Clear the waiting flag
96+
WaitForPlayer(False)
97+
98+
;Turn on the temporary package while we change the ref alias data for their idle package - trick from Hearthfire adoption
99+
MovingTogglePackageOn = True ;"Hold"AI package looks at this quest var
100+
PetRefAlias.GetActorReference().EvaluatePackage()
101+
102+
;Set the ref alias to be the pet's new home
103+
PetHomeMarker.ForceRefTo(newLocation.GetReference())
104+
105+
;Remove them from current following faction so they actually go to their new home
106+
If(dismiss)
107+
PetRefAlias.GetActorReference().SetFactionRank(PetFramework_PetFollowingFaction, 0)
108+
EndIf
109+
110+
Utility.Wait(0.1)
111+
112+
MovingTogglePackageOn = False
113+
PetRefAlias.GetActorReference().EvaluatePackage()
114+
115+
If(doWarp)
116+
Utility.Wait(0.01)
117+
PetRefAlias.GetReference().MoveTo(newLocation.GetReference(), 0,0,0,False)
118+
EndIf
119+
120+
PetFramework_PetDismissMessage.Show()
121+
PetFramework_ParentQuest.DecrementPetCount()
122+
123+
debug.trace("Pet Count: " + PetFramework_ParentQuest.GetCurrentPetCount())
124+
125+
EndFunction
126+
127+
128+

0 commit comments

Comments
 (0)