Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script Optimizations #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions scripts/vanilla/Actor.psc
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ endFunction

; also DEPRECATED
Function ModFavorPointsWithGlobal(GlobalVariable FavorPointsGlobal)
ModFavorPoints(FavorPointsGlobal.GetValueInt())
ModFavorPoints(FavorPointsGlobal.GetValue() as int)
endFunction

;this function will make an actor a friend of the player if allowed
Function MakePlayerFriend()
ActorBase myBase = GetActorBase()
ActorBase myBase = GetBaseObject() as ActorBase
if myBase.IsUnique()
if GetRelationshipRank(Game.GetPlayer())== 0
Actor plyr = game.GetPlayer()
if GetRelationshipRank(plyr) == 0
; debug.trace(self + " MakePlayerFriend called on neutral actor - changed to FRIEND.")
SetRelationshipRank(Game.GetPlayer(), 1)
SetRelationshipRank(plyr, 1)
else
; debug.trace(self + " MakePlayerFriend called on non-neutral actor - NO EFFECT.")
endif
Expand Down
17 changes: 9 additions & 8 deletions scripts/vanilla/ObjectReference.psc
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ bool FUNCTION rampRumble(float power = 0.5, float duration = 0.25, float falloff
; debug.traceStack(self + " called rampRumble() but parameter 'power' was invalid. Must be a non-zero float less than 1.0",1)
; throw the warning, but don't return false - value gets clamped anyway
endif
float playerDist = game.getplayer().getDistance(self)
Actor plyr = game.GetPlayer()
float playerDist = (plyr).getDistance(self)
; ignore if the player is too far away
if playerDist < falloff
float intensity = (1 - (playerDist / falloff))
float intensity = (1.0 - (playerDist / falloff))
; ramp actual intensity down based on parameter value
intensity = intensity*power
if intensity > 1.0
; clamp to prevent invalid values
; debug.traceStack(self + " called for too much controller/camera shake. Clamped to 1.0", 0)
intensity = 1.0
elseif intensity <= 0
elseif intensity <= 0.0
; clamp to prevent invalid values
; debug.traceStack(self + " called for too little controller/camera shake", 0)
intensity = 0
intensity = 0.0
return false
endif
game.shakeCamera(game.getPlayer(), intensity)
game.shakeCamera(plyr, intensity)
game.shakeController(intensity, intensity, duration)
return true
else
Expand All @@ -48,7 +49,7 @@ bool Function IsNearPlayer()
else
; both in an exterior -- no means of testing
; worldspace at the moment, so this will do.
if (player.GetDistance(self) > 3000)
if (player.GetDistance(self) > 3000.0)
; pretty darned far away -- safe
return false
else
Expand Down Expand Up @@ -86,7 +87,7 @@ function MoveToWhenUnloaded(ObjectReference akTarget, float afXOffset = 0.0, flo
while self.GetCurrentLocation().IsLoaded() || akTarget.GetCurrentLocation().IsLoaded()
;do nothing
; debug.trace(self + "MoveToWhenUnloaded() waiting for current location and target location to be unloaded before moving. If called by a quest stage fragment, this may cause that quest stage to not complete until this function finishes (and if it's a startup stage, the quest will not report itself as running until the stage finishes.).", 1)
Utility.Wait(5) ;when this function is threaded we can increase this wait time... I set it lower for testing purposes so it reevaluates faster when I need to purge cell buffers in the Civil War when calling moveto on the player between Civil War campaigns
Utility.Wait(5.0) ;when this function is threaded we can increase this wait time... I set it lower for testing purposes so it reevaluates faster when I need to purge cell buffers in the Civil War when calling moveto on the player between Civil War campaigns
EndWhile
self.MoveTo(akTarget, afXOffset, afYOffset, afZOffset)
EndFunction
Expand All @@ -97,7 +98,7 @@ Function DeleteWhenAble()
While GetParentCell() && GetParentCell().IsAttached()
;do nothing
; debug.trace(self + "DeleteWhenAble() waiting for current location to be unloaded before deleting. If called by a quest stage fragment, this may cause that quest stage to not complete until this function finishes (and if it's a startup stage, the quest will not report itself as running until the stage finishes.).", 1)
Utility.Wait(5) ;when this function is threaded we can increase this wait time... I set it lower for testing purposes so it reevaluates faster when I need to purge cell buffers in the Civil War when calling moveto on the player between Civil War campaigns
Utility.Wait(5.0) ;when this function is threaded we can increase this wait time... I set it lower for testing purposes so it reevaluates faster when I need to purge cell buffers in the Civil War when calling moveto on the player between Civil War campaigns
EndWhile
Delete()
EndFunction
Expand Down
2 changes: 1 addition & 1 deletion scripts/vanilla/Quest.psc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool Function ModObjectiveGlobal(float afModValue, GlobalVariable aModGlobal, in
UpdateCurrentInstanceGlobal(aModGlobal)
if aiObjectiveID >= 0
; display/complete objectives automatically
if afTargetValue > -1
if afTargetValue > -1.0
if (abCountingUp && aModGlobal.value >= afTargetValue) || (!abCountingUp && aModGlobal.value <= afTargetValue)
if (abCompleteObjective)
; complete objective
Expand Down
16 changes: 9 additions & 7 deletions scripts/vanilla/ReferenceAlias.psc
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ endFunction

; Convenience fucntion
Actor Function GetActorRef()
return GetActorReference()
return GetReference() as Actor
endFunction


; Convenience function - jduvall
bool Function TryToAddToFaction(Faction FactionToAddTo)
Actor ActorRef = GetActorReference()
Actor ActorRef = GetReference() as Actor

if ActorRef
ActorRef.AddToFaction(FactionToAddTo)
if (!ActorRef.IsInFaction(FactionToAddTo))
ActorRef.SetFactionRank(FactionToAddTo, 0)
endif
Return True
EndIf

Expand All @@ -62,7 +64,7 @@ EndFunction

; Convenience function - jduvall
bool Function TryToRemoveFromFaction(Faction FactionToRemoveFrom)
Actor ActorRef = GetActorReference()
Actor ActorRef = GetReference() as Actor

if ActorRef
ActorRef.RemoveFromFaction(FactionToRemoveFrom)
Expand All @@ -74,7 +76,7 @@ EndFunction

; Convenience function - jduvall
bool Function TryToStopCombat()
Actor ActorRef = GetActorReference()
Actor ActorRef = GetReference() as Actor

if ActorRef
ActorRef.StopCombat()
Expand Down Expand Up @@ -134,7 +136,7 @@ EndFunction

; Convenience function - jduvall
bool Function TryToEvaluatePackage()
Actor ActorRef = GetActorReference()
Actor ActorRef = GetReference() as Actor

if ActorRef
ActorRef.EvaluatePackage()
Expand All @@ -146,7 +148,7 @@ EndFunction

; Convenience function - jduvall
bool Function TryToKill()
Actor ActorRef = GetActorReference()
Actor ActorRef = GetReference() as Actor

if ActorRef
ActorRef.Kill()
Expand Down