Jump to content

Papyrus scripting: exchange data between scripts and MCM


petrX1

Recommended Posts

Hi everyone and happy new year!

 

I've tried to make a modification that gives ability to remove helm and equip sunglasses in dialog.

 

I know there is a modification that provides helm removement in dialog (https://www.nexusmods.com/fallout4/mods/24480), but without sunglasses equipping

 

I found the way to edit scripts, but there is some strange problem.

 

My script data consists of two parts:

 

1) EquipSunglassesEffect

ScriptName Deal_with_it:EquipSunglassesEffect extends ActiveMagicEffect
Deal_with_it:EquipSunglassesMCM Property MainScript Auto Const
Event OnEffectStart(Actor To, Actor From)
...
Event OnEffectFinish(Actor To, Actor From)
...

This script attached in ESP to the

  • MAGIC EFFECT dw_HeadGear_EffectRemove,
  • Magic Effect uses in SPELL dw_HeadGear_SpellRemove,
  • there is QUEST dw_HeadGear_QuestRemove that has Alias spell linked to the SPELL dw_HeadGear_SpellRemove,

and it works

 

BUT....

2) I wanna make MCM menu for my mod and choose sunglasses from inventory to equip.

For this purpose i did another one SCRIPT

ScriptName Deal_with_it:EquipSunglassesMCM extends Quest
Armor Property SunglassesItem Auto
Event OnQuestInit()
...
Function AddEquippedItemsButton()
self.SunglassesItem=Game.GetPlayer().GetWornItem(17).Item as Armor
this function is attached to MCM button and i want it to save equipped sunglasses in property SunglassesItem
...
Function ClearItemsButton()
...
And then i want to get this value in previous function EquipSunglassesEffect
self.Sunglasses=self.MainScript.SunglassesItem
But is doesn't works(.
When dialog is begining, helm removing occurs, but sunglasses doesn't equip.
I suppose that self.Sunglasses is None in all cases.
if (self.Sunglasses!=None)
To.EquipItem(self.Sunglasses, abSilent=True)
endif
I've tried to make Properties in ESP
(Properties - Properties Sorted-property name:SunglassesItem... etc) but it doesn't work.
The only variant that works - whith direct searching of specific sunglasses item 0x000E628A in players inventory.
Customisation of sunglasses item is an impossible without script changes.
What am i doing wrong? Mod is in attachment.
How make a different scripts in mod to exchange their own property values?
Thanks in advance for help.

 

 

 

 

 

 

Link to comment
Share on other sites

Not strictly what you are asking for, but as I do everything you are trying to do in my "PA Improvements" mod I thought I would pass on a few useful things...

 

- It is simpler (and more immersive) to allow the user to equip what they want to wear (before the Helm is equipped) and re-equip that when they take the helm off (no complex MCM work).

- (assuming you have F4SE which you seem to) you can simply detect all the 'headgear' items they are wearing by using (Math.LogicalAnd(Armor.GetSlotMask(), 0xFFF8) == 0)

- You then just re-equip all such items when you detect the Helm removal.

- Having a 'fixed' item of headgear is also bad because users can change their headgear at any time (via pipboy inventory) - having to go back through the MCM is very un-immersive

- One Gotcha (if you want to detect headgear by what is removed when the Helm is equipped) is if this is a PA Helm then the PA code has a bad habit of removing bits of armor as well.

- a second Gotcha is be VERY careful that the headgear does NOT have any armor slots as well (which is why I recommend the slotmask method) as equipping this will remove other bits of armor in strange ways. An example is the radiation suit.

 

This does not need any MCM and will work the way users would expect.

 

Directly concerning your issue - when in the MCM the game is in a 'strange' state so I would not trust most of the script functions (particularly ones that use F4SE and look at the Player's state).

 

Edited: I re-read your post and noticed you assume F4SE which simplified my responce.

 

Edit2: Have you considered using a holotape to trigger the "addEquippedItemButton" script instead of MCM? This will work much more reliably as it is in-game.

Edit3: Or even better a script attached to 'detectGlasses' item in your inventory (no need to open a holotape/MCM if they change their glasses).

Edited by PJMail
Link to comment
Share on other sites

PJMail, thanks for your respond.

 

I scheduled some tests by compiling in debug mode instead of release, and i began to recieve debug messages (Debug.MessageBox(...))

1) MCM properly runs scripts,

so property SunglassesItem in Deal_with_it:EquipSunglassesMCM

is properly setted

2) The second one script have a property

Deal_with_it:EquipSunglassesMCM Property MainScript Auto Const
and when it runs, self.MainScript==None

 

 

So i suppose the problem is more general:

how to set variable in one script:

ScriptName FOLDER:SCRIPT_ONE 
int Property A

function SETA()
  A=5
endfunction

and recieve this value in the second script

ScriptName FOLDER:SCRIPT_TWO

FOLDER:SCRIPT_ONE ScriptONE_OBJECT Auto Const

function GetA()
   int A_value = self.ScriptONE_OBJECT.A
endfunction

I thought that i have to make corresponding property in esp file in script properties

ScriptONE_OBJECT

 

but something goes wrong and one script object doesn't see another script object.

 

 

Edited by petrX1
Link to comment
Share on other sites

  • Recently Browsing   0 members

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