This tutorial covers a few ways to achieve certain functions in the CK. I've focused on issues that are relatively common, or ones that are usually left unanswered, especially ones that I struggled with myself. You can view this as a list of smaller tutorials on fairly small subjects. I'll expand this post as I find more problems on the Skyrim Nexus Forums (modding only).
The included tutorials are on the following subjects: Making An NPC Attack in Dialogue, How to Change Attack Speed for a Weapon, Creating a New Combat Style, Making a One-Time Event Via Script, and Adding Items to a Container Via Script. You can find a tutorial on creating compatibility patches elsewhere.
We use the terms CK, mod, branch, topic, info and response. The CK is the Creation Kit, the tool used to modify Skyrim. A mod is a modification to the game, a branch is a collection of topics; a topic is a collection of infos; an info is a collection of responses put together for a single circumstance. A response is a single line of dialogue.
Now that that's out of the way, let's start.
Making NPC's Attack in Dialogue
This tutorial can teach you how to use dialogue to initiate combat with the player, or other NPC's. A good example of this the encounter with the Old Orc. (Skip to step 4 if you just want the code to paste in)
1) Open up your quest in the Character-->Quest tab. (I'm assuming you already have a quest made. If you don't, make one now.)
2) Go to the Dialogue Views tab, or the Player Dialogue tab, whichever you prefer.
3) Find the info you want to cause the speaker to attack the player in.
4) In the Papyrus Fragment box under the End section, type in the following code:
AkSpeaker.StartCombat(Game.GetPlayer())
5) Click the Compile button. No errors should appear, if you typed that in correctly. If they do, try step again.
6) Save and exit the CK. Test it. If it the NPC doesn't attack you, repeat the steps.
Explanation:
For those who don't understand Papyrus Fragments, they're essentially little snippets of code. They're part of a bigger script, but you can edit each part of the larger script within these Papyrus Fragments. They're a fragment of the script, that's been pre-placed for you. In our example, we placed the Papyrus Fragment at the End. That means that the code will run once the NPC finishes speaking. If we placed it in the Begin section, it would run accordingly.
AkSpeaker is a reference to the NPC speaking. Like all Ak references, it finds the object it's pointing to, and performs whatever action is past the period on that obejct. StartCombat forces the NPC to start combat with the reference in the parentheses. In our case, we called Game.GetPlayer, which is a function used to find the reference of the player. You could also define a property and replace Game.GetPlayer with it, if you wanted the NPC to initiate combat with a different Actor. For our script, this will work well, though.
Note that the NPC will flee from the player at a low health if their confidence (found under AI Data, in their NPC editor) is set higher.
Adding Items to a Container Via Script
This tutorial will teach you how to add items to a container via script, and how to do it at a certain stage of a quest. Skip to step 3 for the script, or step 5 for the script with quest stages. Thanks to IshaeaMeradin for some help fixing a few issues here.
1) Open your script (or create it) with your editor of choice (or the built-in CK editor).
2) Add one properties, pointing to the item you want to add. For this script, we'll be using the example of Gold001. As Ishara pointed out on the Forums, we don't need a property for the container, since we're attaching the script to the container. We can use Self instead. We will be using the event onActivate, but you may use a different one for your own script. (OnActivate will add the item when the container is activated, and unlike in Oblivion, will automatically open your container unless you add extra code to say otherwise.)
3) Type in the following:
Scriptname Yourscriptname Extends ObjectReference
MiscObject Property Gold001 Auto; this should be a property for the item to add to the container
Event onActivate(Actor AkActionRef)
If akActionRef == Game.GetPlayer()
Self.AddItem(Gold001, 100)
EndIf
EndEvent
4) Save your script and attach it to your container, making sure all the properties are pointing towards something.
To only add on a certain stage:
5) Click the Edit Properties button by right clicking on your script and selecting it.
6) Add a property, which we'll call MyQuest, and attach it to your quest (the one that has a stage that will allow the item to be added to the container). Be sure to flag it auto at the end, like our other properties. For our example, we will pretend that stage 30 is the one that adds the item to the container, but it could be any stage.
7) Open up your script, and change the script to this:
Scriptname Yourscriptname Extends ObjectReference
MiscObject Property Gold001 Auto; this should be a property for the item to add to the container
Quest Property MyQuest Auto
Event onActivate(Actor AkActionRef)
If akActionRef == Game.GetPlayer() && MyQuest.GetStage() == 30
Self.AddItem(Gold001, 100)
EndIf
EndEvent
Explanation:
For the usual item adding, it's fairly simple. If the person who opened the container (the reference that performed an action on the object the script is attached to - akActionRef) is the player, then add your pre-defined item to the chest. Then, make the player activate the chest as usual.
The item-adding on quest stage, the script does the same thing as above, with an added if statement. If the AkActionRef is the player and your quest is at stage 30, then the item will add, and the player will activate the chest.
Changing the Attack Speed of a Weapon
This tutorial will teach you how to change the attack speed of a weapon, from incredibly slow to lightning-fast, or anywhere in between. Note: Must be done individually, for each weapon you want to modify.
1) Open up the CK. Load up your mod as the active file, and its masters, if you're editing a weapon in that mod. Otherwise, just check the boxes next to Skyrim.esm and Update.esm.
2) Find the weapon you want to modify. It should be under Items>Weapons. You can use the object window filter to find it. We're going to look for the steel warhammer, so search "Steel" in the object window filter and scroll until you find it (that is, the steel warhammer). Then double click it to "open" it.
3) Make sure you're in the Game Data tab for the weapon. This will be below the value and name section. If you're not in the Game Data tab, click it to go to it.
4) Where it says weapon speed, modify it however you like. I'll set mine to 8.00, so I can tell the difference.
5) Save your plugin. (File>Save or the floppy disk icon next to the folder on the main toolbar.) Name it whatever you want. I'll name mine 'Steel Warhammer - Speed Edition'. Close the CK.
6) Load up your game. Go to Data Files, and check the box next to Steel Warhammer - Speed Edition.esp, as well as its masters. (Skyrim.esm and Update.esm for us. The masters are the names you checked when you loaded your plugin into the CK.)
7) Go get the Steel Warhammer. Swing it around. It's super-fast. You're done! Repeat steps 2-5 for every weapon you want to modify.
Explanation:
It's pretty simple. You're modifying the weapon speed - how fast the weapon swings/shoots/stabs. Increase the value to be faster. Decrease to be slower. Default is usually 1.0 for swords, and somewhere between 0.6-0.8 for two handed weapons.
Creating a New Combat Style
This tutorial will teach you how to create a new combat style that you can apply to any NPC in the game. A combat style determines how the NPC will fight, and what style of combat they will prefer.
1) Open up the CK. Check the boxes next to Skyrim.esm and Update.esm. If you have your own mod you want to add a combat style to, set that as the active file. Click OK and let the CK load. Save your mod with the floppy disk icon next to the folder icon. Name it something. Mine is 'Combat Styles of Awesome'.
2) Go to Miscellaneous>CombatStyle and right click in the right-hand side of the Object Window. Select New.
3) A prompt should pop up. Give your combat style an ID. I'll name mine 'csCSoA01' (CombatStyleCombatStylesofAwesome01). A bit redundant, maybe, but following the proper naming conventions is always good.
4) Now, begin editing your combat style. Refer here to see what all the values mean.
5) Close and exit the prompt by pressing OK. Save your plugin with the same icon as before, and exit the CK. You're done. Now, you can apply the combat style to an NPC in the dropdown menu in the AI tab of their editor. (Not the AI Packages, but the other one - AI Behaviour, I believe.)
If you so wish, you can change combat style through dialogue with scripting. The function is SetCombatStyle, but requires SKSE to be used. However, it does not persist across save games - so be sure to use OnPlayerLoadGame.
Using SKSE Functions
This is also how you use functions from any other mod/resource like SkyUILib, SkyUI, or FISS.
This tutorial will teach you how to use functions or events from SKSE in your scripts.
1) Go to the SKSE site, skse.silverlock.org.
2) Download the 7z Archive version of the latest SKSE (you can choose beta or the latest, I usually use beta but if you don't want to have access to functions from it, that's fine).
3) Extract the contents of the archive to your Skyrim folder (the one containing TESV.exe and such), saying Yes to All if it asks you to replace anything.
4) Now, in order to use functions from SKSE in your script, you... Use them like you would any other function or event. In order for them to work, the user must have SKSE of the version you used or higher. They can have the 7z or Installer version installed.
Explanation:
In order to use functions and events, these functions and events are defined in SOURCE scripts - PSC files found under Skyrim/Data/Scripts/Source. Installer SKSE only includes the PEX files; the 7z version includes the source files. Only someone modifying/making scripts needs the source files, users can just have the PEX files for things to work smoothly.