Hi guys, I dont suppose someone with scripting experience can take a look at the below to see if there are going to be any issues with its execution. It is a script attached to a constant spell effect on the player. The mod I am creating creates similar scripts for all the races. The core boanes of the script (checks, registering when the player is hit etc) I did, however I recieved help for the states and sleeping - so I have no idea if this script has potential to go haywire during normal gameplay.
Thanks in advance!
T
import utility
;/////////////////////////////////////////////////////////////////////////////
/ Properties
/////////////////////////////////////////////////////////////////////////////;
; Specific to this race power
Spell property AutoCastSpellNord auto
; Common to all race powers - these check to see if the player is doing a brawl.
Quest property DGIntimidateQuest auto
Location property WhiterunJorrvaskrLocation auto
;For the purpose of script optimisation this is for checks to ensure the target is a player.
actor property target auto hidden
bool property IsPlayer auto hidden
;These are variables that are part of the cooldown system, to ensure it tracks passage of time through fast travel and resting.
float property PowerReadyAt auto hidden
float property BeganSleepingAt auto hidden
;/////////////////////////////////////////////////////////////////////////////
/ Constants
/////////////////////////////////////////////////////////////////////////////;
; Specific to this race power
float property HPThreshold = 0.4 auto;/readonly/; hidden
; Common to all race powers
float property Cooldown = 3.0 auto;/readonly/; hidden
float property ActivationChance = 0.10 auto;/readonly/; hidden
string property State_Ready = "Ready" autoreadonly hidden
string property State_Cooldown = "Cooldown" autoreadonly hidden
;/////////////////////////////////////////////////////////////////////////////
/ Events
/////////////////////////////////////////////////////////////////////////////;
event oninit()
target = getTargetActor()
isplayer = target == game.getplayer()
endevent
event OnUpdateGameTime()
GoToState(State_Ready)
endevent
;/////////////////////////////////////////////////////////////////////////////
/ States
/////////////////////////////////////////////////////////////////////////////;
auto state Ready
event OnHit(ObjectReference u1, Form u2, Projectile u3, bool u4, bool u5, bool u6, bool u7)
GoToState(State_Cooldown)
; checks required, regardless of which race power this is
if (target.IsDead() || target != isplayer || ActivationChance <= RandomFloat() || \
(DGIntimidateQuest.IsRunning()) || \
(target.GetCurrentLocation() == WhiterunJorrvaskrLocation ))
GoToState(State_Ready)
return
endif
; check power specific requirements aka when at low hp.
if (target.GetActorValuePercentage("health") >= HPThreshold)
GoToState(State_Ready)
return
endif
; passed all guards, therefore power-up
PowerReadyAt = Cooldown
RegisterForSleep()
RegisterForSingleUpdateGameTime(PowerReadyAt)
PowerReadyAt += GetCurrentGameTime()
AutoCastSpellNord.Cast(target)
endevent
endstate
state Cooldown
event OnSleepStart(float startTime, float u1)
UnregisterForUpdateGameTime()
BeganSleepingAt = startTime
endevent
event OnSleepStop(bool u1)
float now = GetCurrentGameTime()
float effectiveTimeSlept = (now - BeganSleepingAt)
if (effectiveTimeSlept + now >= PowerReadyAt)
GoToState(State_Ready)
UnregisterForSleep()
elseif (effectiveTimeSlept > 0.0)
PowerReadyAt -= effectiveTimeSlept
RegisterForSingleUpdateGameTime(PowerReadyAt - now)
endif
endevent
endstate