Jump to content

Call on variables in other scripts


YourUnequal

Recommended Posts

Well, you take a one hand weapon, like a dagger, so the animations are correct, and use NifSkope to strip away the blade mesh, and pop in an enlarged, flattened ring mesh, which covers the knucles.

 

Easy enough, make the weapon in the CK, and test it out as a damage dealing bladed weapon, and Yeah! the Animations play, the weapon does damage, and the victim is outraged, attacks back, and kills the player. But, test successful.

 

Now, we don't really WANT the enemy to strike back, we want them stunned clueless that your actually attacking them!

 

Quirk#1: So, in the CK, edit the Weapon: In the Flags section, check box on the "Non-Hostile" Flag. It is NOT enough to set the damage to zero in the Game Data fields!

 

Now, you might think, oh look, the weapon ck record can accept a script, and there is an OnHit Event, easy peasy, this is where I can place my Animation Triggers! WRONG!

 

Quirk#2: The OnHit of the Weapon is simply unrealable. It takes into account the hit or miss mechanics, and its duration, it persistence is variable and too short to get any script to reliable fire the needed event!

 

So... Here is the Work Around, in several steps.

 

In the CK, create an Enchantment for the weapon, and link it to the weapon by the "Enchanting" field. Then create a Magic Effect, and link it to the Enchantment. The Trick is to put the majority of the script in the Magic Effect as a script, and NOT on the weapon itself!

 

The Magic Effect Script is still limited in persistence, but it does not have the Hit/Miss mechanics getting in the way of the event firing, which will initiate our animations!

 

But! That doesn't mean the ME script has persistence to remember which of the two companions is going to be assisting. So, you have to use the Brass Knuckles in several passes, and Store the selected Action outside of the ME Script, to be retrieved on another pass through the ME script later on!

 

So, you need an external mechanism for storing an Actor Ref.

 

If it were just a selected action, like bind the wrists, but leave the ankles free, to be able to "Walk" the hostage... easy, just create and property link a Global Variable, Simply store the info as a Global Short Integer Code, 0-no bindings, 1-Arms, 2-Legs and Arms, 3-Legs, Arms and Hood over the head!

 

But, globals can't hold actor refs., so to get persistence of the selected actor references at run time, you need to store the Actor in a different way.

 

-

Edited by VanKrill
Link to comment
Share on other sites

So, How to hold an Actor Ref, a pointer to an actor or target, on one pass of a weapon ME script, and use on a later pass through the same ME script?

 

Well, the Work Around is to use A Quest with an Actor ReferenceAlias, and a SCRIPT attached to that Quest as the referencealias scripting handle!

 

On the first pass through the BrassKnuckles Magic Effect script, you will select which of two companions will assist, and store that actor reference in the Quest, and access it though the script! That last statement "Acces it though the script" is KEY and the big confusion stumbling block! Much HAIR GONE!

 

The details of how to get it to work, step by step:

 

So, in the CK, create a new QUEST. Call it something like Highwayman_Controller_Quest.

 

Go to the "Quest Aliases" tab, and create a new reference alias. The dirty little details: Flags Optional and Stores Text! And field "Force into Alias when filled", and select your referencealias by name. Don't fill out anything else! Do NOT radio button specific reference, and select some actor you've been using for eariler testing, that will MUCK UP Everything!

 

Now, go to the Quest "Scripts" tab, and create a new "extends Quest" script. In this quest, create reference aliases to your various actors with "ReferenceAlias Property A0_alias Auto "

 

So, A0 is our Assistant Campanion, and A1 is our road traveling victim. Compile, Save and exit,

 

Quirk#4, Note, you haven't yet used either referencealias in a fuction. You can't yet, the CK won't see it, and it gives you an error when you attempt to compile, making you think you got the syntax wrong... you didn't. For now, just Compile, Save and exit.

 

Now that your back to the Quest, staring at your incomplete Script attached in the Quest-Script tab, to to Properties, highlight the referencealias, use the edit value button off to the right, select your Quest, and then your reference alias actor A0 or A1, in turn.

 

Exit the Properties window, Hit OK on the Quest to save it.

 

Quirk#5, Save the Mod in the Ck. Exit the CK. Restart the CK, and reload the Mod! If you don't, the next steps won't complie right, and you'll think you have the Syntax Wrong, and your hair will be gone!

 

Okay, I've to got get to work now... More Quirks to finish the proces later.

Edited by VanKrill
Link to comment
Share on other sites

Okay, back home to my notes now...

 

So, we were up to the point of restarting the ck, after adding the Reference Alias to the Quest Script.

 

So, now you need to create the Set() assessor function.

 

For those accustomer to sane Object Oriented Languages like C# or C++, Papyrus is... not so symetrical. There are includes, but not *.H files, or strictly speaking *.dll files, with the exception of what comes with SKSE.

 

So, access to the Assessor Functions is not done symetrically, nor defined in the same script *.psc files. It is spread out.

 

The SET the ReferenceAlias Function is defined in the script attached to the Quest, compiled and saved, but it is Called in the Magic Effect Script, where the value of the spell akTarget is known.

 

In the quest script:

; ------------------------------------------------------------------------------------------------------------------------------------------------

Scriptname Highwayman_Controler_Script extends Quest Conditional
{This is a collection of Highwayman reference aliases and their support functions.

This is attached to Quest Highwayman_Controller_Quest.}

 

 

ReferenceAlias Property A0_alias Auto

ReferenceAlias Property A1_alias Auto

 

 

Function SetA0Alias(actor ActorA0)

A0_alias.clear() ; This is the Golden Nugget!!! Why I took the time to reverse engineer this code!!!
A0_alias.ForceRefTo(ActorA0) ;

EndFunction


; ------------------------------------------------------------------------------------------------------------------------------------------------
Function SetA1Alias(actor ActorA1)

A1_alias.clear()
A1_alias.ForceRefTo(ActorA1) ;

EndFunction
; ------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

And then later, in the Magic Effect Script:

 

; ------------------------------------------------------------------------------------------------------------------------------------------------

Scriptname Highwayman_BrassKuckles_Script extends activemagiceffect
{Placed on Magic Effect, Selects which two actors, and stores their reference alias for
later use. Initiates the start of the Animation.}

 

Highwayman_Controler_Script Property Controller Auto

 

function OnEffectStart(actor akTarget, actor akCaster)

; ... a bunch of choice of this pass through the ME action selection

 

if (Choice == 0)
if (akTarget)
Controller.SetA0Alias(akTarget)
endif

elseif (Choice == 1)
; 1 Set Actor 1
if (akTarget)
Controller.SetA1Alias(akTarget)
endif

; ------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

Now, there is another Quirk#6 in the above code which might have gone un-noticed, and will cause major hair loss!

 

The property, which set the handle, called "Controller", which is used to access the functions in the Quest Script, is NOT the name of the Quest, but rather it is the name of the Script attached to the Quest! This is very important. If you use the Quest name, you'll get a vague error, and no hint about what is wrong.

 

The property is targeted at the script, not the quest. Type, like type int, or float, of the property, is the name of the script which is attached to the quest!

 

Highwayman_Controler_Script Property Controller Auto

 

The type is "Highwayman_Controler_Script". It is a Property, and it is Named Controller, and it setup to be Auto filled.

 

This takes care of storing the Actor information, aka akTarget, from the Magic Effect script, to the persistent store of info, out in the Quest Script.

 

But, it takes a different mechanism, which is NOT symetrical, as we see in OBL like C#, to retrieve the info.

 

 

The following code is in the Magic Effect Script, or possibly any other script, which needs to use the spell selected actor information.

 

; ------------------------------------------------------------------------------------------------------------------------------------------------

ReferenceAlias Property A0 Auto ;

; Setup the Animation Actors
actor[] HWMActors = new actor[2] ; HWM is Highwayman, just to make it unique.
HWMActors[0] = A0.GetActorRef() ;

 

; ------------------------------------------------------------------------------------------------------------------------------------------------

 

So, what would be a Get() assessor function in C#, is an inherent subfuction of the ReferenceAlias Class. You need only create and fill a property, and evoke the function.

 

There are a BUNCH of functions to the ReferenceAlias Class:

 

http://www.creationkit.com/index.php?title=ReferenceAlias_Script

 

This is simply the one you use to retrieve an actor value to fill an actor array, in preparation to start an animation.

 

 

 

 

So.... there you go... accessing the Actor Variable from a Magic Effect Script, in another script, via the temporary, but persistent, storage container, of a ReferenceAlias in a Quest!

 

Simple!

 

:smile:

 

 

P.S. Now that I hashed it out the hard way, reverse engineering another mod's scripts...

 

https://forums.nexusmods.com/index.php?/topic/3000679-accessing-another-scripts-property-values-at-runtime/

 

No Hair, No Mind, No Sanety!

 

 

-

Edited by VanKrill
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...