Jump to content

OnInit probblem


Tasheni

Recommended Posts

I run into a new issue (whatelse :frantics:) I was never aware of. My scripting knowledge is very limited and here I'm not sure what the OnInit function really does. I know that OnInit fires twice, tested that with a messagebox. The script is about follower mounting, when player mounts his horse or whatever:

scriptName _RubyPlayerMountMonitorScript extends ReferenceAlias

;-- Properties --------------------------------------
actor property Ruby auto
visualeffect property Effect auto
faction property CurrentFollowerFaction auto
actor property PlayerRef auto
actor property Assan auto

;-- Variables ---------------------------------------
actor Player

;-- Functions ---------------------------------------

; Skipped compiler generated GotoState

; Skipped compiler generated GetState

function FollowerMount(actor myFollower, actor myHorse, String asEventName, Float afTime)

    form EquippedItemLeft = PlayerRef.GetEquippedObject(0)
    form EquippedItemRight = PlayerRef.GetEquippedObject(1)
    if myFollower.IsInFaction(CurrentFollowerFaction) == 1 as Bool
        if myFollower.GetActorValue("WaitingForPlayer") == 0 as Float
            if EquippedItemLeft as Bool || EquippedItemRight as Bool
                if asEventName == "tailHorseMount"
                    debug.SendAnimationEvent(Ruby as objectreference, "IdleForceDefaultState")
                    myFollower.OnAnimationEvent(none, "tailHorseMount")
                    Effect.play(myHorse as objectreference, 0.300000, none)
                    myHorse.MoveTo(myFollower as objectreference, 50.0000 * math.sin(myFollower.GetAngleZ() + 90.0000), 50.0000 * math.cos(myFollower.GetAngleZ() + 90.0000), 0.000000, true)
                    utility.Wait(0.100000)
                    myFollower.SetAnimationVariableBool("bIsRiding", 1 as Bool)
                    myFollower.EvaluatePackage()
                endIf
                if asEventName == "tailHorseDismount"
                    Bool dismountInitiated = myFollower.Dismount()
                    myFollower.SetAnimationVariableBool("bIsRiding", 0 as Bool)
                    myFollower.EvaluatePackage()
                endIf
            else
                return
            endIf
        endIf
    endIf
endFunction

function OnInit()
;    Debug.Messagebox("Script running")
    utility.Wait(5.00000)
    Player = game.GetPlayer()
    self.RegisterForAnimationEvent(PlayerRef as objectreference, "tailHorseMount")
    self.RegisterForAnimationEvent(PlayerRef as objectreference, "tailHorseDismount")
endFunction

function OnAnimationEvent(objectreference akSource, String asEventName)

    if akSource == PlayerRef as objectreference
        self.FollowerMount(Ruby, Assan, asEventName, 0.300000)
    else
        return
    endIf
endFunction

This script is attached to the alias of my follower Ruby in a script started quest. It works very good. With Alternate Start from Arthmoor activated. With only vanilla Skyrim it works very good. Until I open racemenu with the console and change my character. After closing racemenu, script is no longer working.

I tested without MO. I tested without changing character, saved the game, shut down, load the game and the save and script runs fine. So it must have to do with racemenu (not the mod racemenu! I don't use). I tested on a start enabled quest. Same result, script stops working. What happens here and what can I do to make that work?

And a second problem occurs: I wrote my playerhorse now follows fine again, but that is only partially true, like I just now discovered. It works fine if I use Alternate Start. When I use only vanilla Skyrim, the NPC walks away as soon as I tell her to wait. The horse stays, like she should. A script changes the wait globalvariable to 1, package stack is evaluated for horse and npc and the stay package has the wait globalvariable set as condition as well as a quest stage set. There is no package everywhere that could fire in this quest stage. Why does it work with Alternate Start? And not with vanilla?

It's really tiring. Your suggestions are much appreciated.

Update: Playerhorse now behaves correctly. CK didn't save my property and I overlooked it.

Link to comment
Share on other sites

Did a workaround to fix it: Created an own quest for the player mounting monitor script with the aliases of my followers. Each follower has the mounting script attached. Created a dialogue topic that stops and starts this quest, if necessary.

But I really would like to know, why OnInit stops working, when using racemenu. Don't know if any script with an OnInit event or function is affected by this.

Link to comment
Share on other sites

Update: OnInit stops working when player changes the race. If player only changes eye color or hair, it works fine. Tested with and without alternate start mods. Tested with start enabled quest and script started quest. IsharaMeradin wrote on nexus:

Quote

That is weird to say the least.  I wonder if it isn't the OnInit failing but rather the animation registrations.  While the reference ID for the player doesn't change, the appearance and all that jazz does change with a race change.  I suspect that the animation registrations are getting lost and need to be reapplied. Shoot, I wonder how it would have behaved with werewolf and vampire, those are technically race changes too.  Might explain some of the bug reports I've seen...

This might be important for mod creators.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...