Creation kit (Start scripting)
To start writing papyrus scripts and compile them you need to have a the corrects scripts in the right folders. If this isn't the case ck will trow errors at you when you try to compile. When with the LE creation kit, make sure all the pex files are in the Data\Scripts folder and that the psc files are in the Data\Scripts\Source folder.
For the SE creation kit the pex files have to be in the Data\Scripts folder and the psc files have to be in the Data\Source\Scripts folder.
I know this is stupid and confusing but somebody mixed up the locations. Unless you write a line of code to change the path in the ini this is where your scripts have to be. When I tried to compile for the first time I had a lot of errors regarding modified scripts or with faulty code in them. I solved this by making a collection of clean framework files that contain the correct scripts. I also manually removed entire functions with faulty code. I thought, if they are not working properly then why do I need them anyway right? Using these (dummy files) works for me to compile the scripts. I will put them in atachement for you. I do not guarantee that your game will run properly with these scripts. It is possible these scripts will cause some minor bugs. What they shouldn't do is crash your game. I run with these scripts and have had 0 crashes so far (I think it caused some minor bugs though). I suggest you save your scripts somewhere safe before overwriting them with these. Once you are done with your mod you can overwrite my scripts with your old ones. Then you have your own scripts and your original game. Hopefully you are now able to compile scripts.
The first thing you should know about scripts is that there are a couple of different script setups. You can have scripts underneath the quest, scripts tab. Right click on the script and press edit to look at the script (psc source). When you go for this option your scripts should look somewhat like this
The actual script is written between the ;BEGIN CODE and the ;END CODE (red), in this case "Alias_Fight.GetReference().Delete()" (yellow). You can define properties underneath the whole like the second yellow circle. When you open the script for the dialogue it will look somewhat similar like the image below. Here you can once again see the same structure. If you want to change this script you should only touch the code in the yellow circles. Evertyhing else should not be touched as it will break the script. Between the ;BEGIN CODE and the ;END CODE you can add as many lines as you want. The same goes for after the ;END FRAGMENT CODE. If you want you can even write full funtions after this line.
The most easy way to add scripts is by far ataching it to a triggerbox. Create a triggerbox, right click it press "edit" -> "edit base" add a new script at papyrus script. Give the script a unique name that you will be able to find back later. The reason why this is the easiest way is because when you attach a script to an object you get a blak script page instead of one filled with clutter.
You can also attach the script to other objects but you won't be able to use the "Event OnTriggerEnter(ObjectReference TriggerRef". Once you have this page you can start writing your papyrus scripts. To have a script running you need to start it with an event. When this even is played the script underneath the event will start to run. All possible events to start running scripts can be found in the link: https://ck.uesp.net/wiki/Category:Events
In order for a script to do things it needs something to work with. The things that you can work with in your script are called functions and properties. Properties have many possible categories. This image shows the possible properties that you can use in your script. You can find it by pressing the "Properties" button.
Let's start with writing a simple script. Place a triggerbox. Add a script with a unique script name. Start editing the source. In this image ou can see a simple script that will show a message when npc's or the player runs throught them. The code is given underneath. Code in skyrim is a big pile of if's and what should happen when the coditions are met. If->then. For every "If" you need an "EndIf". You should never change the lines that contain your scriptname like in the image or fragement codes when you are editing quests and message code.
Event OnTriggerEnter(ObjectReference MyUniqueRef)
If MyUniqueRef== Game.GetPlayer()
Debug.Notification("Player ran through the trigger box")
ElseIf MyUniqueRef != Game.GetPlayer()
Debug.Notification("NPC ran through the trigger box")
Else; this is just an alternative that will run on evey alternative that isn't the player
Debug.Notification("NPC ran through the trigger box")
EndIfS
EndEvent
Keep in mind that the debug function is only for editing purpose. The correct way to show messages in game is by adding a message property and type the function .Show().
Event OnTriggerEnter(ObjectReference MyUniqueRef)
If MyUniqueRef== Game.GetPlayer()
MyMessage1.Show()
ElseIf MyUniqueRef != Game.GetPlayer()
MyMessage2.Show()
Else; this is just an alternative that will run on evey alternative that isn't the player
MyMessage3.Show()
EndIf
EndEvent
Message Property MyMessage1 Auto
Message Property MyMessage2 Auto
Message Property MyMessage3 Auto
If you created the messages in the object window with the same name you should be able to auto fill the properties. Like in the image
After that the blue cross should turn into a yellow stick. This means that the script has some properties assigned to it. Assigned properties are connected to other game elements such as messages, objects, npc's, doors, xmarkers etc. Every propertie that isn't assigned to an ingame propertie will have to be defined in the script itself or will return empty.
There are many different possibilities, many small scripts can be combined together in a bigger script. This script will remove 500000 gold from you (if you have it) and enable a castle for you to live in once you walk through the triggerbox. If you don't have it the script will mock you for being (poor).
Event OnTriggerEnter(ObjectReference MyUniqueRef)
If (MyUniqueRef== Game.GetPlayer()) && (Game.GetPlayer().GetItemCount(Gold001)>=500000)
Game.GetPlayer().Removeitem(gold001,500000)
Castle.Enable()
Else
HomelessMessage.Show(); Message, we don't allow homeless in here go work!
EndIf
EndEvent
MiscObject Property Gold001 Auto
ObjectReference Property Castle Auto
Message Property HomelessMessage Auto
Bools are properties that contain false or true information. Int values are properties that contain numeric value. When the script finishes running it will keep all the data regarding bools but it will forget all values that are numeric. It is important to keep in mind if you want your data to be stored or to be forgotten. Bools and ints are usually defined in the script, as far as I know I have never set actual properties for them that refer to ingame properties. Following script contains a counter. In this script only "MyMessge" would have to be filled. All the ohter properties are defined in the script itself.
Event OnTriggerEnter(ObjectReference MyUniqueRef)
If MyUniqueRef == Game.GetPlayer()
Debug.Notification(Game.GetPlayer() +" entered the box")
MyFunction()
EndIf
EndEvent
Function MyFunction()
If CountingNumber <12
CountingNumber = CountingNumber+1
Else
MyMessage.Show() ; we counted to 12, can we stop now?
If Counting1 == False
Counting1 = True
CountingNumber=0
MyFunction() ; No you can not!
Else
Counting1=False ; (Reset counting) Sure, you can stop now!
EndIf
EndIf
EndFunction
Bool Property Counting1 = False Auto
Bool Property Counting2 Auto
Int Property CountingNumber Auto
Message Property MyMessage Auto
You can find many more scripts that are already written in the creation kit wiki. Like this one. https://ck.uesp.net/wiki/OnDeath_-_Actor
Event OnDeath(Actor akKiller)
if (akKiller == Game.GetPlayer())
Debug.Trace("We were killed by the player!")
endIf
endEvent
If you want to assign an ai package by alias and not by attaching it directly tot he npc you need to make a ReferenceAlias propertie. This properties as to point toward an ai alias package that was made in a ques under quest aliases. The alias can be assigned with the code line "MyAliasName.ForceRefTo(MyObjectReference as actor)" given that the "MyAliasName" and the "MyObjectReference" are either defined in the script or are pointing at a propertie. ("MyAliasName.ForceRefTo(MyActor)" works too)
Edited by DarkBlade13
0 Comments
Recommended Comments
There are no comments to display.