×
Меню
Индекс

MSFD Detecting use of scrolls or books

 
This is a surprisingly difficult task, as OnActivate and OnPCEquip are both needed AND don't work quite as expected.
Kir has found a solution as shown in this script for invoking a letter of credit:
 
Begin BankLetter10
 
short button
short messageOn
short invoke
short gone
short goneway
short testdist
short PCSkipEquip
short OnPCEquip
 
set PCSkipEquip to 1
; disable if used  (a 1 use item)
if ( gone == 1 )
     if ( goneway == 1 )      ; activated as external item
          Disable
     else                         ; equipped from inventory
          startscript BankLetter10Remove
     endif
     set gone to 0
     return
endif
 
if ( OnActivate == 1 )
     Set messageOn to 2
     set goneway to 1
endif
 
If ( OnPCEquip == 1)
     Set messageOn to 2
     Set OnPCEquip to 0    
     set goneway to 2
endif
 
if ( messageOn == 0 )
     return
endif
 
if ( messageOn == 2 )
     MessageBox "Do you want to invoke the Letter of Credit?" "Yes" "No"
     Set messageOn to 1
     return
endif
 
if ( messageOn == 1 )
     set button to GetButtonPressed
     if ( button == 0 )
          Set invoke to 1
          Set messageOn to 0
;          return
     endif
     if ( button == 1 )
          Activate
          Set messageOn to 0
          return
     endif
endif
 
if ( invoke == 1 )
     PlaySound "Item Gold Up"
     Player->AddItem, Gold_001, 10000
     set gone to 1
     set invoke to 0
endif         
 
End
 
Erstam posted a script with even better features, that also revealed an interesting glitch with the scripting variables OnPCEquip / SkipEquip:
"Inspired by the BankLetter script in MSFD 7, I have found a way to run custom script code on books and scrolls when either "equipped" from the player's inventory or activated from the game world, while the book/scroll is displayed as normally. Surprisingly, it's the PCSkipEquip variable that is set to 1 when the book is dropped on the player's portrait, rather than the OnPCEquip variable. This is the code I used:"
 
 
Begin activateBook
 
short OnPCEquip
short PCSkipEquip
short doOnce
short actionFlag
 
if ( actionFlag == 1 )
     if ( doOnce == 0 )
          ; insert your custom code here
          set doOnce to 1
     endif
     set actionFlag to 0
endif
 
; PCSkipEquip is set to 1 every time the book is equipped from your inventory
if ( PCSkipEquip == 1 )
     set PCSkipEquip to 0
     set actionFlag to 1
     return
endif
 
; these lines are important, otherwise the book can't be picked up from the ground
if ( MenuMode == 1 )
     return
endif
 
; for activating the book when it is placed in the game world
if ( OnActivate == 1 )
     set actionFlag to 1
     Activate
endif
 
End
 
It should work without the doOnce condition, in case you want the action to take place every time you equip the book, but I haven't tested it yet.