I have an ability on the player with a magic effect that does nothing except carry a script. The script is intended to detect when a location change occurs (vanilla detects this without registering for any events), then determine a bit about what location was entered based on the keywords attached. I'd like my mod to execute commands only if it is a city/town that I'm entering.
The script looks like:
Scriptname checkLoc Extends ActiveMagicEffect
Keyword Property LocTypeTown Auto
Keyword Property LocTypeCity Auto
Keyword Property LocTypeHabitationHasInn Auto
Keyword Property LocTypeDwelling Auto
Event OnLocationChange(Location akOldLoc, Location akNewLoc)
Utility.Wait(1)
If akNewLoc.HasKeyword(LocTypeTown)
Debug.MessageBox("Town entered")
ElseIf akNewLoc.HasKeyword(LocTypeCity)
Debug.MessageBox("City entered")
ElseIf akNewLoc.HasKeyword(LocTypeHabitationHasInn)
Debug.MessageBox("Habitation with Inn entered")
ElseIf akNewLoc.HasKeyword(LocTypeDwelling)
Debug.MessageBox("Dwelling entered")
Else
Debug.MessageBox("New Loc "+ akNewLoc+ " does not fit any keywords")
EndIf
EndEvent
All properties have been fitted inside the CK where the script is attached to the magic effect. The Utility.Wait(1) was just thrown in there to see if the game needed a little time to get its facts straight (it didn't help).
Testing this on the WhiterunLocation (Form ID: 00018A56), it gives me the last messagebox that says nothing fits (When actually LocTypeCity and LocTypeHabitationHasInn both apply). I also ran to Riverwood to see if it'd identify the town, but it also said nothing fits. Even going in houses/interiors that should be dwellings also say nothing fits.
Is there a special way to detect keywords on locations or does HasKeyword not work on locations? Maybe there is another, easier, way to detect whether we've just entered a town or city? I also tried referencing the PlayerRef property, fitting the PlayerRef property in CK, and calling PlayerRef.GetCurrentLocation() to test for the keywords, but that failed to even call a location. It always returned "None".
Its odd, because the HasKeyword CK webpage includes an example that detects the keyword on a location:
https://www.creationkit.com/index.php?title=HasKeyword_-_Form
Any help would be appreciated. I'm stumped.