Jump to content

Retrieving object information via papyrus script


Sataere

Recommended Posts

Disclaimer: I've only just started with the CK and Papyrus so I could well be asking a silly question here.

 

I've created a script and attached it to the "Player" Actor and I'm hooking up the OnLocationChange event, which is firing no problem (see script below).

My question is, how can I get the "Name" from the location object that is being passed to that event? I.e. The "Name" field of the associated Location object as viewed in the Object Window in the CK under WorldData->Location.

Currently, when changing locations, the notification says: "Player just entered [Location <...>]" or something along those lines.

 

Here's hoping somebody can help!

 

Thanks in advance!

 

Scriptname XYZ extends ObjectReference

Import Game
Import Debug

Event OnLocationChange(Location akOldLoc, Location akNewLoc)
If (akNewLoc != None)
	Debug.Notification ("Player just entered " + akNewLoc)
EndIf
EndEvent

Link to comment
Share on other sites

It's not a silly question. Using Text from Locations (or other objects) is possible, but it's not that easy.

Replacement Text is only available through Quests and Aliases. That's a subject that even has some veteran modders scratching their heads at. You might want to put that part on hold and come back to it later.

 

The other thing, don't put too much work into a script that you will have to attach directly to the player. Well not if you plan on releasing it. It's great for learning though if you want to test code snippets. Some people like the structured learning of tutorials, some prefer to dabble :) I've never done a modding tutorial in my life, but I've skimmed through many.

 

What you could do is add a Property (or a few) to the script. You need to assign the actual property in the CK (otherwise MyHouseLocation would have the value of None).

 

Scriptname XYZ extends Actor ; Actor is a special kind of ObjectReference.

;Import Game
Import Debug ; We do not need to prepend Debug to Notification is we import it.

Location Property MyHouseLocation Auto

Event OnLocationChange(Location akOldLoc, Location akNewLoc)
       If (akNewLoc == MyHouseLocation)
               Notification ("Welcome Home.")
       ElseIf (akOldLoc == MyHouseLocation)
               Notification ("Off travelling again.")
       Else
               Notification ("I miss my warm fire.")
       EndIf
EndEvent

 

Edit: Script, comments & reformatting for codebox display

Edited by tunaisafish
Link to comment
Share on other sites

It's not a silly question. Using Text from Locations (or other objects) is possible, but it's not that easy.

Replacement Text is only available through Quests and Aliases. That's a subject that even has some veteran modders scratching their heads at. You might want to put that part on hold and come back to it later.

Excellent, thanks, I'll read into that Replacement Text in the mean time!

 

The other thing, don't put too much work into a script that you will have to attach directly to the player. Well not if you plan on releasing it.

It's great for learning though if you want to test code snippets. Some people like the structured learning of tutorials, some prefer to dabble :) I've never done a modding tutorial in my life, but I've skimmed through many.

 

What you could do is add a Property (or a few) to the script. You need to assign the actual property in the CK (otherwise MyHouseLocation would have the value of None).

 

Scriptname XYZ extends Actor ; Actor is a special kind of ObjectReference.

;Import Game
Import Debug ; We do not need to prepend Debug to Notification is we import it.

Location Property MyHouseLocation Auto

Event OnLocationChange(Location akOldLoc, Location akNewLoc)
       If (akNewLoc == MyHouseLocation)
               Notification ("Welcome Home.")
       ElseIf (akOldLoc == MyHouseLocation)
               Notification ("Off travelling again.")
       Else
               Notification ("I miss my warm fire.")
       EndIf
EndEvent

 

Edit: Script, comments & reformatting for codebox display

Ah, I wasn't aware this was a faux pas :unsure: Any reason why the script shouldn't run on the Player directly?

 

I probably should have explained my reasons better in the first post:

I want to create the script so that it runs every time the player moves to a new location. The script will pick up the location change and act upon it using the Name of the new location (per my original questions). The reason I didn't go for the Property approach is that I need to pick up every single location in the game and to my untrained eye it seems the only way to do that is to attach the script to every single location manually and set the Property each time? I could be way off here of course.

 

Thanks for the help and also for the tips on the Actor extension and Import - very useful!

Link to comment
Share on other sites

Gotcha :)

 

To be compatible with other mods then you really want to limit editing NPC's directly where you can help it.

Two ways around this, The Quest with an Alias to the player. You can then add scripts and inventory, spells etc to the Alias.

 

The other way if you just want a script, is to use a magic effect ability, although you've got to use some way of adding that though.

(A quest Script or an object that the player interacts with are probably the most common.)

 

For the actual task of Location change, then you don't need to attach a script at all.

Use the OnStoryChangeLocation Event. That can start your quest (with your location Alias in it) for you. But you'd need to stop that quest for the story manager to start it again.

 

Probably a combination of the 2 will work best. Quest starts when you change location after your mod is installed.

That grabs the location and player alias. So now you have your script on the player from the 1st post. (extends AliasReferenceAlias this time though)

Each time the player changes location you'd use Alias_YrLocAlias.ForceRefTo(akNewLoc).

(I think) any messages you show() from then on will be able to use the location text.

 

Edit: Fixed ReferenceAlias. When I typo script names in my editor I can tell right away from the colour.

Edited by tunaisafish
Link to comment
Share on other sites

  • Recently Browsing   0 members

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