Jump to content

[LE] Event OnRead multiple times on a book


Recommended Posts

I need to add or remove a perk any time I read the same book but it works only a once:

Message Property ANV_LearnCraftingRecipesMessage Auto
Message Property ANV_ChoiceForgetCraftingRecipesMessage Auto
Message Property ANV_ForgetCraftingRecipesMessage Auto

Perk Property CraftingPerk Auto

Actor Property PlayerRef Auto

Event OnRead()
	Utility.WaitMenuMode(1.0)
	If (!PlayerRef.HasPerk(CraftingPerk))
		PlayerRef.AddPerk(CraftingPerk)
		ANV_LearnCraftingRecipesMessage.Show()
	Else
		int choice = ANV_ChoiceForgetCraftingRecipesMessage.Show()
		If (choice == 1)
			PlayerRef.RemovePerk(CraftingPerk)
			ANV_ForgetCraftingRecipesMessage.Show()
		EndIf
	EndIf
EndEvent 

Any tips? Thank you.

Link to comment
Share on other sites

anvCraftingPerkScript

 

Scriptname anvCraftingPerkScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/7148211-event-onread-multiple-times-on-a-book/

  Perk PROPERTY CraftingPerk auto
  Bool bHasPerk                                                       ; [default=False]

  Message PROPERTY ANV_LearnCraftingRecipesMessage        auto        ; learn
  Message PROPERTY ANV_ForgetCraftingRecipesMessage       auto        ; forget
  Message PROPERTY ANV_ChoiceForgetCraftingRecipesMessage auto        ; forget by choice


; -- EVENT --

EVENT OnRead()  ; received when this object, if a book, is read, (we assume game mechanic only the player may read a book!)
    Utility.WaitMenuMode(1.0)

    IF ( bHasPerk )
        myF_Action(False)           ; remove, if choiced
    ELSE
        myF_Action(TRUE)            ; add perk
    ENDIF
ENDEVENT


; -- FUNCTION --

;----------------------------
FUNCTION myF_Action(Bool bOK)
;----------------------------
IF ( bOK )
    bHasPerk = TRUE
    Game.GetPlayer().AddPerk(CraftingPerk)
    ANV_LearnCraftingRecipesMessage.Show()

ELSEIF (ANV_ChoiceForgetCraftingRecipesMessage.Show() == 1)        ; make sure 1 is the right option, not 0
    bHasPerk = False
    Game.GetPlayer().RemovePerk(CraftingPerk)
    ANV_ForgetCraftingRecipesMessage.Show()
ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

anvCraftingPerkScript

 

Scriptname anvCraftingPerkScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/7148211-event-onread-multiple-times-on-a-book/

  Perk PROPERTY CraftingPerk auto
  Bool bHasPerk                                                       ; [default=False]

  Message PROPERTY ANV_LearnCraftingRecipesMessage        auto        ; learn
  Message PROPERTY ANV_ForgetCraftingRecipesMessage       auto        ; forget
  Message PROPERTY ANV_ChoiceForgetCraftingRecipesMessage auto        ; forget by choice


; -- EVENT --

EVENT OnRead()  ; received when this object, if a book, is read, (we assume game mechanic only the player may read a book!)
    Utility.WaitMenuMode(1.0)

    IF ( bHasPerk )
        myF_Action(False)           ; remove, if choiced
    ELSE
        myF_Action(TRUE)            ; add perk
    ENDIF
ENDEVENT


; -- FUNCTION --

;----------------------------
FUNCTION myF_Action(Bool bOK)
;----------------------------
IF ( bOK )
    bHasPerk = TRUE
    Game.GetPlayer().AddPerk(CraftingPerk)
    ANV_LearnCraftingRecipesMessage.Show()

ELSEIF (ANV_ChoiceForgetCraftingRecipesMessage.Show() == 1)        ; make sure 1 is the right option, not 0
    bHasPerk = False
    Game.GetPlayer().RemovePerk(CraftingPerk)
    ANV_ForgetCraftingRecipesMessage.Show()
ENDIF
ENDFUNCTION

 

 

 

It worked! So PlayerRef.HasPerk(Perk) returns true even if the perk has been removed from the player?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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