Jump to content

Access variable from other script


Recommended Posts

Aha! To answer (possibly) my own question, I think it's the following:

The creation kit will let you attach spells and such from other esps, but when you save your dependent mod the linkage is lost:

 

https://www.creationkit.com/fallout4/index.php?title=Data_File

 

https://cs.elderscrolls.com/index.php?title=De-Isolation_Tutorial

 

so. the trick is to use wryebash or xedit or similar to make the esp with the 'goodies' a 'master' with the esm flag _before_ loading in the creation kit (there are other methods). Then when saving the new mod the references to the master esp stay, then before playing or releasing, remove the esm flag from the 'master' esp. I had thought that using xedit to make an esp a master would do this, but that is not the same as attaching the esm flag.

 

So far I'm doing good:)

 

diziet

Link to comment
Share on other sites

  • 2 months later...

Hey diziet, to access properties from other esp's, even scripts, you can use the GetFormFromFile function: https://www.creationkit.com/index.php?title=GetFormFromFile_-_Game . The downside of this though, is if the form ID's change from what's expected in your script, the property won't be filled. Form ID's can change when converting an esp to esl flagged for instance. But, as you're accessing your own esp's properties, you can just tell users not to do that.

 

Example to access another script from another esp:

MyScriptOnMagicEffect MagicEffectScript = ((Game.GetFormFromFile(<formID>, "SomeEsp.esp") As MagicEffect) as MyScriptOnMagicEffect)

Edit: I actually don't think that instance will work because a script on a magicEffect extends ActiveMagicEffect which aren't the same thing. It would work for other things like Quests though. Also you could just use your spell property like such:

Spell Myspell = (Game.GetFormFromFile(<formID>, "SomeEsp.esp") As Spell)
Edited by dylbill
Link to comment
Share on other sites

To return to earlier in this thread, I thought i had understood what to do and indeed had it working, where a quest script (mcm menu) set some values that were accessed from another script attached to a trigger.

 

in that case the quest script was in one esp and the trigger in another. It worked, it still works, I use those scripts a lot.

 

But now I cannot get the same to work with two scripts destined to be attached to different triggers in the same esp. The problem is that when I attach one script (the one that declares the other as a property) I cannot set the property...

 

Here are the scripts:

 

 

scriptname dz_test_entry Extends ObjectReference
;set variable

string property text auto
Event OnTriggerEnter(ObjectReference triggerRef)
text = "It works"
EndEvent

Event OnTriggerLeave(ObjectReference triggerRef)
EndEvent

 

 

 

and:

 

 

 

scriptname dz_test_leave Extends ObjectReference
dz_test_entry Property script Auto
Event OnTriggerEnter(ObjectReference triggerRef)
EndEvent

Event OnTriggerLeave(ObjectReference triggerRef)
debug.messagebox(" " +script.text)
EndEvent

 

 

 

when I attach the second script to a trigger box and then select properties, when I try to manually fill the property of type 'dz_test_entry', the dialogue insists on making me choose a cell and a location!

 

 

 

When I attach the old script that declares a quest script as a property, I can fill it fine, even though the esp with that quest script is not even loaded in the CK.

These scripts are just me testing that I had learnt from before how to do this, but clearly I'm missing something.

I am tired so maybe it's trivial but I cannot see the problem.

 

diziet

Link to comment
Share on other sites

That's, strange, to say the least that you can fill properties from other esp's. Are you using them as a dependency? To fill your script property, you have to choose the object reference that your other script is on. Or, you can fill it with a function:

 

 

 

Scriptname dz_test_leave Extends ObjectReference

dz_test_entry Property script Auto
ObjectReference Property dz_test_entry_ObjectRef Auto ;This is the object reference your other script is on.

Event OnInit()
    script = dz_test_entry_ObjectRef as dz_test_entry
EndEvent

Event OnTriggerEnter(ObjectReference triggerRef)
EndEvent

Event OnTriggerLeave(ObjectReference triggerRef)
    debug.messagebox(" " +script.text)
EndEvent

 

 

 

Link to comment
Share on other sites

If I understand your question correctly, yes. The input fields will change depending upon the script being extended by the target script. Personally, I have only ever utilized quest scripts, alias scripts and objectreference scripts in this manner.

Link to comment
Share on other sites

Ok, I have the two scripts attached and now I have filled the properties, (this leads to a second problem but thats for later) right now my actual scripts for undressing are not filling the arrays for spells and armor, I'm wondering if this is because I've declared the arrays as properties wrongly; here are the two scripts:

 

 

 

scriptname dz_player_only_enter_skse Extends ObjectReference
;;we set the arrays and variables as properties so that they can be accessed from other scripts such as dz_player_only_leave_skse

Actor Property PlayerRef Auto                   ;this allows us to use the fast PlayerRef reference
Form[] Property Fight   Auto          ;[0] Weapon equippedleft, [1] Weapon equippedright, [2] Armor  player_shield, [3] Ammo   player_ammo
Armor[] Property Armor_1  Auto          ;for armour slots 30 to 49 incl.

Armor[] Property Armor_2  Auto          ;for armour slots 52 to 61 incl.
Spell[] Property Spell_1  Auto          ;this array will hold all equipped spells
Bool  Property disrobed  Auto                   ;to track player naked
;define variable for camera state

int  Property iCameraState Auto          ;this will store the view mode, 0 = first person
; -- Events -- 3
Event OnInit()

;===========

    Armor_1 = new Armor[20]

    Armor_2 = new Armor[10]

    Spell_1 = new Spell[4]

    Fight   = new Form[5]

EndEvent
;in this script the combat checks are in the events, in my mcm scripts the combat checks are in the player undress functions

Event OnTriggerEnter(ObjectReference triggerRef)     ;this is triggered when entering the trigger box

If (triggerRef as Actor)          ;is the trigger an actor?

Else

  Return                 ;if not exit the function

EndIf



If triggerRef == PlayerRef && !PlayerRef.isincombat()   ;checks to see if the trigger is the player and also not in combat

  dz_undress_player_F()          ;if so call the function to undress the player

  return              ;we are done, exit the function

EndIf

EndEvent
Event OnTriggerLeave(ObjectReference triggerRef)

EndEvent

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

Ammo Function GetEquippedAmmo(Actor aRef)

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

; returns the ammo equipped by the passed in actor, otherwise it returns NONE

int i

If ( aRef )              ;is the actor valid?

        i = aRef.GetNumItems()          ;skse function

    EndIf
While i > 0

        i -= 1

        Form AM = aRef.GetNthForm(i)        ;skse function

        If AM as Ammo && aRef.IsEquipped(AM)

            Return AM as Ammo

        EndIf

    EndWhile

        Return None                   ;no ammunition

EndFunction
Form Function GetEquippedTorch(Actor aRef)

If aRef.GetEquippedItemType(0) == 11

  Form TCH = aRef.GetEquippedObject(0)      ;skse function

  Return TCH

EndIf

EndFunction
Function dz_undress_player_F()          ;define the function to undress the player

If (SKSE.GetVersion() > 0)
;If Game.IsCamSwitchControlsEnabled()       ;switch cam is possible for player

  iCameraState = Game.GetCameraState()      ;skse function

  If ( iCameraState == 0)

  ; change to third person       

                Game.ForceThirdPerson()                 ;3rd Person

        Else

        EndIf

    ;EndIf

Else

Game.ForceThirdPerson()                    ;3rd Person

EndIf
If ( disrobed )

Return                  ;if the player is already undressed exit the function

EndIf

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

disrobed = True                       ;set the player is undressed variable
; get weapons

Fight[0] = PlayerRef.GetEquippedWeapon(True) as Form      ;store equippedleft in Fight array

    Fight[1] = PlayerRef.GetEquippedWeapon(False) as Form     ;store equippedright in Fight array
; get shield

    Fight[2] = PlayerRef.GetEquippedShield() as Form          ;store player_shield in Fight array


If (SKSE.GetVersion() > 0)

; get ammo

    Fight[3] = GetEquippedAmmo(PlayerRef) as Form             ;store player ammo in Fight array using custom function



;get torch

Fight[4] = GetEquippedTorch(PlayerRef) as Form             ;store player torch in Fight array using custom function

EndIf
int i ;for filling arrays below

    i = spell_1.Length            ;fill the spell_1 array - [0] Left hand, [1] Right hand, [2] Other, [3] Instant

    While (i)

  debug.messagebox("i = "+i)

        i = i - 1

        spell_1[i] = PlayerRef.GetEquippedSpell(i)

  debug.messagebox("Spell = "+spell_1[i])

    EndWhile
; fill the first armour array

    i = armor_1.length

    While (i)

  ;debug.messagebox("i = "+(i + 31))

        i = i - 1

        armor_1[i] = PlayerRef.GetEquippedArmorInSlot(i + 31)

  ;debug.messagebox("Armour = "+armor_1[i])

    EndWhile
; fill the second armour array

    i = armor_2.length

    While (i)

        i = i - 1

        armor_2[i] = PlayerRef.GetEquippedArmorInSlot(i + 53)

    EndWhile
    PlayerRef.UnEquipAll()                 ;undress the player player

EndFunction

 

 

 

 

 

scriptname dz_player_only_leave_skse Extends ObjectReference
Actor Property PlayerRef Auto                   ;this allows us to use the fast PlayerRef reference
;;we require access to the stored variables from dz_player_only_enter_skse scriptnamedz_player_only_enter_skse Property dz_ent Auto
Event OnTriggerEnter(ObjectReference triggerRef)EndEvent
Event OnTriggerLeave(ObjectReference triggerRef)     ;this is triggered when exiting the trigger box;debug.messagebox("camera is "+dz_ent.iCameraState)If (triggerRef as Actor)Else  Return                 ;if not exit the functionEndIfIf triggerRef == PlayerRef          ;checks to see if the trigger is the player  debug.messagebox("Dressing the Player")  dz_redress_player_F()          ;if so call the function to re-dress the playerEndIfEndEvent
Function dz_redress_player_F()          ;define the function to re-dress the playerIf (SKSE.GetVersion() > 0);return to first person if necessary;If Game.IsCamSwitchControlsEnabled()         ; switch cam is possible for player        If ( dz_ent.iCameraState == 0 )         ; skse function   ; change to third person if not already   Game.ForceFirstPerson()                  ; 1st Person        Endif    ;EndIfEndIf
If ( dz_ent.disrobed == true )            ;is the player undresseddebug.messagebox("disrobed = "+dz_ent.disrobed)Elsedebug.messagebox("disrobed = "+dz_ent.disrobed)    Return                  ;the player is not undressed, exit the functionEndIf;---------------------
; https://www.creationkit.com/index.php?title=EquipItemEx_-_Actor
int i                ;for using arrays belowarmor ARIf (SKSE.GetVersion() > 0);re-equip the first armour arrayi = dz_ent.armor_1.LengthWhile (i)  i = i - 1  AR = dz_ent.armor_1[i]  If ( AR )   PlayerRef.EquipItemEx(AR, 0, False, True)         ;skse function  EndIfEndWhile;re-equip the second armour arrayi = dz_ent.armor_2.LengthWhile (i)  i = i - 1  AR = dz_ent.armor_2[i]  If ( AR )   PlayerRef.EquipItemEx(AR, 0, False, True)         ;skse function  EndIfEndWhile
;re-equip weaponsIf ( dz_ent.Fight[0] as Weapon )              ;equippedLeft  PlayerRef.EquipItemEx(dz_ent.Fight[0],  2, False, True)     ;skse functionEndIf
If ( dz_ent.Fight[1] as Weapon )              ;equippedRight  PlayerRef.EquipItemEx(dz_ent.Fight[1], 1, False, True)      ;skse functionEndIf
;re-equip shieldIf ( dz_ent.Fight[2] as Armor )               ;player_shield  PlayerRef.EquipItemEx(dz_ent.Fight[2], 0, False, True)      ;skse functionEndIf
;re-equip ammoIf ( dz_ent.Fight[3] as Ammo)                  ;player_ammo  PlayerRef.EquipItemEx(dz_ent.Fight[3], 0, False, True)      ;skse functionEndIf
Else                ;do not use skse functions;re-equip the first armour arrayi = dz_ent.armor_1.Lengthdebug.messagebox("Armor1 Length = "+dz_ent.armor_1.length)While (i)  i = i - 1  AR = dz_ent.armor_1[i]  debug.messagebox("Armour = "+dz_ent.armor_1[i])  If ( AR )   PlayerRef.EquipItem(AR, False, True)     ;vanilla function  EndIfEndWhile;re-equip the second armour arrayi = dz_ent.armor_2.LengthWhile (i)  i = i - 1  AR = dz_ent.armor_2[i]  If ( AR )   PlayerRef.EquipItem(AR, False, True)     ;vanilla function  EndIfEndWhile
;re-equip weaponsIf ( dz_ent.Fight[0] as Weapon )        ; equippedLeft  PlayerRef.EquipItem(dz_ent.Fight[0], False, True)         ;vanilla functionEndIf
If ( dz_ent.Fight[1] as Weapon )        ; equippedRight  PlayerRef.EquipItem(dz_ent.Fight[1], False, True)     ;vanilla function;EndIf
;re-equip shieldIf ( dz_ent.Fight[2] as Armor )        ; player_shield  PlayerRef.EquipItem(dz_ent.Fight[2], False, True)     ;vanilla functionEndIf
;re-equip ammo             ;this function can't be used without skse;If ( Fight[3] as Ammo)            ; player_ammo  ;PlayerRef.EquipItem(Fight[3], 0, False, True)     ;EndIfEndIf
;re-equip spellsi = dz_ent.spell_1.LengthWhile (i)  i = i - 1  spell sp = dz_ent.spell_1[i]  If ( sp )     PlayerRef.EquipSpell(sp, i)  EndIfEndWhile
dz_ent.disrobed = False           ;store the dressed state of the playerEndFunction

 

 

 

I think maybe the issue is this?

 

 

should I be filling those array properties somehow?

 

diziet

Link to comment
Share on other sites

You selected the spell array property, the right hand side changes to a list view. Use the Add button to add a new entry to the list, then you can drag-n-drop whatever object you need at that index.

 

Something to remember with regards to the property window, the input fields on the right will always change depending upon the type of property selected. Use those fields and buttons to obtain the correct object(s) for the selected property.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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