Jump to content

Checking for keyword


Recommended Posts

Two methods:

With SKSE:

HasKeywordString

 

Without SKSE:

 

 

Bool ModAisPresent = false
 
Event OnInit()
  RegisterForSingleUpdate(0.25) 
  ; register for update to bypass the OnInit event sometimes running twice
EndEvent
 
Event OnUpdate()
  MaintCheck() 
  ; put code in a function so that it can be called via OnPlayerLoadGame event 
  ; this check is necessary at each game load in case the player adds or removes the third party mod
EndEvent
 
Function MaintCheck()
  ; check if mod is present and set a local variable accordingly
  If Game.GetFormFromFile(0x0078abcd, "ModAPlugin.esp") != None
    ModAisPresent = true
  Else
    ModAisPresent = false
  EndIf
EndFunction

Bool Function CheckObjectForKeyword(Form TheObject,Keyword TheKeyword)
  If TheObject.HasKeyword(TheKeyword)
    Return True
  Else
    Return False
  EndIf
EndFunction  

; inside other function or event
If ModAisPresent == true
  Form ModAObject = Game.GetFormFromFile(0x0078abcd, "ModAPlugin.esp")
  Keyword ModAKeyword = Game.GetFormFromFile(0x00123456, "ModAPlugin.esp") as Keyword
  If CheckObjectForKeyword(ModAObject,ModAKeyword) == true    
    ;do something
  Else
    ;do nothing or something else
  EndIf
Else
  ;do nothing or something else
EndIf

GetFormFromFile

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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