Summary


The point of this tutorial is to show you the basics of Papyrus and how to use it without going so far into detail that it just doesn't make sense. It removes the bullshit, and adds the functionality so you can get real results out of what you're writing.

We're going to start with the basic 'Hello World' script but this will ensure that it works in-game.

Go into Creation Kit. In your ObjectWindow search for 'EmptyTrigger' under the 'WorldObjects' branch.

Here's how your window should look if you search properly and find the object.

Image

Go ahead and drag / drop the 'DefaultEmptyTrigger' into your render window.

Image

There we go, now we have an invisible box. This invisible box is going to trigger a script that we are going to write. The box will not show up in-game but we know it's there because we can see in the Creation Kit.

Right-Click your trigger in the render window. Go to edit, and go to the scripts tab. We're going to hit 'add'.

Image

You should get a box that pops up. We're going to select '[New Script]'.

Image

Hit okay, and you're going to see a rather strange box.

Image

The image above about sums it up.
Name your script something unique with Basic Characters like 'Stuyk_TutorialScript'

If you do it right, your Reference box should look like so:

Image

Right-Click the script and select 'Edit Source'

Image

This is how you edit scripts.

NEVER EDIT DEFAULT SCRIPTS



Now we have our basic text-editor built into the CK. This is where we are going to write our code.

Image

So let's talk about the first line of code.

Code: Select all

Scriptname Stuyk_TutorialScript extends ObjectReference


This is calling the script we named 'Stuyk_TutorialScript'. And it's an extension to the ObjectReference we placed in-game. An object reference can be a lot of things. Often it's used for activators, triggers, switches, etc.

Not much else to say about that. Now that we have our script let's make our trigger do something.

We want it to active when the player enters the trigger.
So here's a massive list of all the events that Fallout 4 Papyrus supports.
http://www.creationkit.com/fallout4/index.php?title=Category:Events

However, we're going to be using OnTriggerEnter
http://www.creationkit.com/fallout4/index.php?title=OnTriggerEnter_-_ObjectReference

Looks like this:

Code: Select all

Event OnTriggerEnter(ObjectReference akActionRef)


It's implemented like this:

Code: Select all

Scriptname Stuyk_TutorialScript extends ObjectReference

Event OnTriggerEnter(ObjectReference akActionRef)

EndEvent


Now this trigger box, whenever it's touched. It's going to activate the OnTriggerEvent. Which means if I walk my ass into that box, it's going to go into that Event and look for something to do. This is where we want it to display a message to the player.

We'll use debug.notification to do this.
http://www.creationkit.com/fallout4/index.php?title=Notification_-_Debug

Implemented like so:

Code: Select all

Scriptname Stuyk_TutorialScript extends ObjectReference

Event OnTriggerEnter(ObjectReference akActionRef)
    Debug.Notification("Hello World")
    ; This is a comment. You can write comments like this.
    ; You can add additional features to our Trigger by writing under the above debug notification.
EndEvent


So, when the player enters the trigger. The script is called and it plays the message. "Hello World".
Only when the player enters the trigger though.

So here's how it would be played out by a numbered order:

Code: Select all

0. Scriptname Stuyk_TutorialScript extends ObjectReference

1. Event OnTriggerEnter(ObjectReference akActionRef)
2.   Debug.Notification("Hello World")
3.  ; This is a comment. You can write comments like this.
4.  ; You can add additional features to our Trigger by writing under the above debug notification.
5. EndEvent


So it starts at 1. It realizes the script has an event or events.
Then it goes to 2, telling the trigger that it needs to send this debug notification.
Then it goes to 3 and 4 and ignores them because they are comments.
Then it goes to 5, telling the script that the trigger has been entered and it needs to kill the event so it is no longer running.

The event can be entered again to trigger the message multiple times.

So when you're done. Make sure you compile your script and save your plugin.

Image



Congratulations, you've literally written your first script.