Jump to content

[LE] Script issue with game's 'Favorite' and 'OnEquipped' not firing.


maxarturo

Recommended Posts

My personal opinion, use a "dummy quest" as you call them for this specific situation. At the very least, use an already existing quest that lasts for the life of your mod (i.e. an MCM quest).

 

A rough untested example:

 

 

FormList Property GearList auto
FormList Property PerkList auto

Event OnMenuClose(String MenuName)
  If MenuName != "FavortiesMenu"                                  ; if not favorites menu stop and return
    RETURN
  Else                                                            ; if favorites menu, continue
    Actor PlayerRef = Game.GetPlayer()                            ; store locally - helps with speed
    CheckGearApplyPerks(PlayerRef.GetEquippedObject(0),PlayerRef) ; call local function with left hand object
    CheckGearApplyPerks(PlayerRef.GetEquippedObject(1),PlayerRef) ; call local function with right hand object
  EndIf
EndEvent

Function CheckGearApplyPerks(Form Gear, Actor Dude)
  Int index = GearList.Find(Gear)                   ; locate gear index number
  If index = -1                                     ; valid entry not found, stop and return
    RETURN
  Else                                              ; otherwise continue
    Perk myPerk = PerkList.GetAt(index) as Perk     ; get matching perk
    If Dude.HasPerk(myPerk)                         ; perk already applied, stop and return
      RETURN
    Else                                            ; otherwise continue
      Dude.AddPerk(myPerk)                          ; apply perk
    EndIf
  EndIf
EndFunction

 

 

 

If you really must put it on each object's script, then utilize GetEquippedObject instead of GetEquippedWeapon / GetEquippedShield. I'm just afraid that multiple objects in the player's inventory and / or surrounding area might all try to call OnMenuClose at the same time. Should that be the case, it could get messy pretty fast depending upon how you write the code and how many objects are running the event. Obviously that should be something which is tested for before committing to the individual object script route.

Link to comment
Share on other sites

Thanks IsharaMeradin for your suggestion.


I'll test your recommended logic along side with 3 logics i have in mind and i'll start first with the 'Dummy Quest' just to get it out of the way since it's common logic and it was also propose by dylbill as a possible solution.


But, i'll start this test runs with prejudice... i think i know why the 'Automatic Equip' does not get registered as 'Object Equipped', and if this is the case... then there is NO workaround it !!...


" I'm just afraid that multiple objects in the player's inventory and / or surrounding area might all try to call OnMenuClose at the same time"

Yeah... this does indeed occurs !!.

I encounter this issue yesterday with some of my experiments but i didn't pay too much attention to it, since my initial goal was to find a way to detect the 'Automatic Equip' issue.

Plus this can easily be resolve with a 'Bool' or with a 'Global' or with both for fail safe.


* And there were also some other hilarious issues, like after equipping/unequipping multiple objects multiple times while in 'Favorite Menu', the equipment that it is actually chosen to be use and while using the ability of that equipment, it would fire ALL the previous equipped/unequipped abilities simultaneously making the test cell look like New Year's Eve fireworks !!...


I'll post my results later tonight...


Thank you both very much for your assistance !.

Edited by maxarturo
Link to comment
Share on other sites

 

* And there were also some other hilarious issues, like after equipping/unequipping multiple objects multiple times while in 'Favorite Menu', the equipment that it is actually chosen to be use and while using the ability of that equipment, it would fire ALL the previous equipped/unequipped abilities simultaneously making the test cell look like New Year's Eve fireworks !!...

That could be resolved by checking that the favorites menu and the inventory menu are not open prior to triggering the equip / unequip abilities. And for those times that those menus are open, have those menus registered and when closed apply the appropriate perks for the currently equipped gear (which is already what you're looking at doing to bypass a "bug" with the favorites menu).

 

Playing Devil's Advocate for a moment...

What about situations where the favorite item is given a hot key? If said item causes a swap from a 2h to 1h & shield with a key press without going into the favorites menu, does one of the items not get registered in that scenario as well? What about when using SkyUI's modifications to the favorite system?

 

*****************

Thought outside the box...

A similar approach to catch the items not caught with the OnEquipped event. Instead of checking for a specific menu, we register for a single update (the timer doesn't run while the game is paused and so it will be triggered shortly after inventory and / or favorites menu is closed). We do apply the perk when the item is equipped but the update will check both hands and make sure that the correct perks are applied for both of them.

 

This approach is done on the object's script. It may be the solution that fits your desires.

Not tested:

 

 

FormList Property GearList auto  ; list of gear in the system
FormList Property PerkList auto  ; list of perks associated with the gear at matching index values
Int Property myIndex auto        ; known index of item holding script and its matching perk
Actor PlayerRef
 
Event OnEquipped(Actor akActor)
  If akActor == Game.GetPlayer()          ; make sure player is the one equipping the object
    PlayerRef = akActor                   ; stored for use in the update event and local function
    Perk MyPerk = PerkList.GetAt(myIndex) ; get our perk
    akActor.AddPerk(MyPerk)               ; apply perk
    RegisterForSingleUpdate(2.5)          ; wait 2.5 seconds - timer does not run while game is paused, event will run as soon as possible
  EndIf
EndEvent
  
Event OnUnequipped(Actor akActor)
  If akActor == Game.GetPlayer()          ; make sure player is the one un-equipping the object
    PlayerRef = akActor                   ; stored for use in the update event and local function
    Perk MyPerk = PerkList.GetAt(myIndex) ; get our perk
    akActor.RemovePerk(MyPerk)            ; remove perk
    RegisterForSingleUpdate(2.5)          ; wait 2.5 seconds - timer does not run while game is paused, event will run as soon as possible
  EndIf
EndEvent

Event OnUpdate()
    CheckGearApplyPerks(PlayerRef.GetEquippedObject(0),PlayerRef) ; call local function with left hand object
    CheckGearApplyPerks(PlayerRef.GetEquippedObject(1),PlayerRef) ; call local function with right hand object
  EndIf
EndEvent

Function CheckGearApplyPerks(Form Gear, Actor Dude)
  Int index = GearList.Find(Gear)                   ; locate gear index number
  If index = -1                                     ; valid entry not found, stop and return
    RETURN
  Else                                              ; otherwise continue
    Perk myPerk = PerkList.GetAt(index) as Perk     ; get matching perk
    If Dude.HasPerk(myPerk)                         ; perk already applied, stop and return
      RETURN
    Else                                            ; otherwise continue
      Dude.AddPerk(myPerk)                          ; apply perk
    EndIf
  EndIf
EndFunction

 

 

 

Link to comment
Share on other sites

Ok then, this is definitely a 'Game's Nasty Bug'...!! or an omission of the game's company, i tried all approaches / logics / function / events / set ups (and the suggested by you guys proposals) and none of them can catch the "Automatically Equipped Equipment".


So i'll have to suffice myself with adding a "Known Issue" in the mod's description page informing of the game's "Automatically Equipped Equipment" bug, and write a more detailed explanation as a "Modder's Note" in the "Equipment's Manual" that comes along with the equipments.


As for 'HotKeys' and 'SkyUI' everything works as intended, no problems.


So, i revert everything to the way it was before the experimentations started and to the condition that everything worked flawlessly.


Thank you both very much and sorry for making you both waste your time in this...

Edited by maxarturo
Link to comment
Share on other sites

Only workaround then that I can think of is to suggest that players manually un-equip and re-equip the gear if their weapon swap via favorites equips two items. And in that case, it may be best to skip the favorites and just equip directly from inventory.

Link to comment
Share on other sites

maxarturo wrote: "So, I revert everything to the way it was before the experimentations started and to the condition that everything worked flawlessly."

Did you mean next with perk conditions?

    Equal to 1.0 GetEquipped() <item>
    Run on -> Subject
    Dragonborn.esm [PERK:020250E7] DLC2AcolyteMaskAugmentFire "Ahzidal's Rage"

Idea out of the box: If you have various perks for your items (weapons or shields) use one perk script and refer for each perk to another fragment. (create a script "PRKF_maxItemsPerkScript_All.psc")

 

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
;NEXT FRAGMENT INDEX 10
Scriptname PRKF_maxItemsPerkScript_All extends Perk Hidden
; https://forums.nexusmods.com/index.php?/topic/8454163-script-issue-with-games-favorite-and-onequipped-not-firing/

;BEGIN FRAGMENT Fragment_0
Function Fragment_0(ObjectReference akTargetRef, Actor akActor)
;BEGIN CODE
    Debug.Trace("maxPERK: f_0 " +akTargetRef)        ; Perk0
;END CODE
EndFunction

;BEGIN FRAGMENT Fragment_1
Function Fragment_0(ObjectReference akTargetRef, Actor akActor)
;BEGIN CODE
    Debug.Trace("maxPERK: f_1 " +akTargetRef)        ; Perk1
;END CODE
EndFunction
;END FRAGMENT

 


samples for perk fragment scripts
PRKF_doomTowerPerk_000E7326 doomTowerPerk "Tower" [PERK:000E7326]
PRKF_VampireFeedBeds_000CF02C VampireFeed "Thirst for Blood" [PERK:000CF02C]

Edited by ReDragon2013
Link to comment
Share on other sites

Hey, I just tried using the reference alias method I suggested originally, and it works like a charm. I did the sequence that you described in the original post, with this script attached:

 
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
    
    Debug.MessageBox(akBaseObject.GetName() + " Equipped")
    
EndEvent
 

When equiping the sword again, after the greatsword, both sword and shield were equipped, and both got message boxes. Using a reference alias seems like the best option.

Edited by dylbill
Link to comment
Share on other sites

 

When equiping the sword again, after the greatsword, both sword and shield were equipped, and both got message boxes. Using a reference alias seems like the best option.

 

Have you tested if the OnUnEquipped() event is firing under the same conditions?

 

When you equip the two handed weapon does the OnUnEquipped() event fire?

 

When you equip the two handed sword and then look in the menu, are the little arrows still pointing at the shield and sword?

 

I suspect if you tested this with two one handed swords the event would fire when equipped from the favorites menu.

Link to comment
Share on other sites

Only workaround then that I can think of is to suggest that players manually un-equip and re-equip the gear if their weapon swap via favorites equips two items. And in that case, it may be best to skip the favorites and just equip directly from inventory.

Yeap, althought i'll give it one more try once my brain can multi task once again, i'm so tired that i can barely concentrate and although that the last 2 days i've slept for around 24 hours nothing has really change...

 

Thank you.

Link to comment
Share on other sites

maxarturo wrote: "So, I revert everything to the way it was before the experimentations started and to the condition that everything worked flawlessly."

Did you mean next with perk conditions?

    Equal to 1.0 GetEquipped() <item>
    Run on -> Subject
    Dragonborn.esm [PERK:020250E7] DLC2AcolyteMaskAugmentFire "Ahzidal's Rage"

Idea out of the box: If you have various perks for your items (weapons or shields) use one perk script and refer for each perk to another fragment. (create a script "PRKF_maxItemsPerkScript_All.psc")

 

 

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
;NEXT FRAGMENT INDEX 10
Scriptname PRKF_maxItemsPerkScript_All extends Perk Hidden
; https://forums.nexusmods.com/index.php?/topic/8454163-script-issue-with-games-favorite-and-onequipped-not-firing/

;BEGIN FRAGMENT Fragment_0
Function Fragment_0(ObjectReference akTargetRef, Actor akActor)
;BEGIN CODE
    Debug.Trace("maxPERK: f_0 " +akTargetRef)        ; Perk0
;END CODE
EndFunction

;BEGIN FRAGMENT Fragment_1
Function Fragment_0(ObjectReference akTargetRef, Actor akActor)
;BEGIN CODE
    Debug.Trace("maxPERK: f_1 " +akTargetRef)        ; Perk1
;END CODE
EndFunction
;END FRAGMENT

 

 

samples for perk fragment scripts

PRKF_doomTowerPerk_000E7326 doomTowerPerk "Tower" [PERK:000E7326]

PRKF_VampireFeedBeds_000CF02C VampireFeed "Thirst for Blood" [PERK:000CF02C]

I don't know if i really get you, but i'll come back to this later.
Thanks ReDragon.
Link to comment
Share on other sites

  • Recently Browsing   0 members

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