Mattiewagg Posted June 17, 2014 Author Posted June 17, 2014 On 6/17/2014 at 8:34 PM, IsharaMeradin said: I know this is not the comments section of your blog. It is simply easier for me to use the formatting I am familiar with here at the Nexus.May I point out some problems with the following taken from your blog: Reveal hidden contents Quote Adding Items to a Container Via ScriptThis 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. Step 1) Open your script (or create it) with your editor of choice (or the built-in CK editor). Step 2) Add two properties - one pointing to your container, and one pointing to the item you want to add. For this script, we'll be using the example of Gold001 and a container called MyContainer. 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 opened. Be sure to add an Activate function to make sure the container runs the code and opens normally.) Step 3) Type in the following: Scriptname Yourscriptname Extends ObjectReference ObjectReference Property MyContainer Auto MiscObject Property Gold001 Auto; this points to gold, which is a misc object, but the object you want to ;add may be different Event onActivate(Actor AkActionRef) If akActionRef == Game.GetPlayer() MyContainer.AddItem(Gold001, 100) MyContainer.Activate(Game.GetPlayer()) EndIf EndEvent Step 4) Save your script and attach it to your container, making sure all the properties are pointing towards something. Step 5) Click the Edit Properties button by right clicking on your script and selecting it. Step 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. Step 7) Open up your script, and change the script to this: Scriptname Yourscriptname Extends ObjectReference ObjectReference Property MyContainer Auto MiscObject Property Gold001 Auto; this points to gold, which is a misc object, but the object you want to ;add may be different Quest Property MyQuest Auto Event onActivate(Actor AkActionRef) If akActionRef == Game.GetPlayer() && MyQuest.GetStage() == 30 MyContainer.AddItem(Gold001, 100) MyContainer.Activate(Game.GetPlayer()) 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. To make the container activate-able in the second, modified script, you have to add Else statement. This means that if one or more of the above conditions is not met, then you should do the thing within the Else statement. I would add this, below MyContainer.Activate(GameGetPlayer()) Else MyContainer.Activate(Game.GetPlayer()) This allows the player to activate it no matter what, but the item will only be added on stage 30. It's generally a good idea to put this in. Your example uses the OnActivate event which means that the player has activated the object. Yet within the OnActivate event you script the object to be activated by the player. That will cause the OnActivate event to run again. Not what you want to have happen.Now if you used a different event (maybe even a different object) and wanted the container to be opened at that point then you would use that line. This is the basics of how a bag of holding works. Equip one item and it causes the container to be activated. But rarely do you want to activate the same container within that container's activation sequence. You may very well end up with a loop that cannot be exited. For a script that will add an item when a container is activated by the player, this is all you need: Reveal hidden contents Scriptname SomeScript Extends ObjectReference MiscObject Property Gold001 Auto Event OnActivate(ObjectReference akActiavtor) If akActivator == Game.GetPlayer() Self.AddItem(Gold001,100) EndIf EndEvent For a script that will add an item only when a quest is at a certain stage and the container is activated by the player this is all you need: Reveal hidden contents Scriptname SomeScript Extends ObjectReference MiscObject Property Gold001 Auto Quest Property MyQuest Auto Event OnActivate(ObjectReference akActiavtor) If akActivator == Game.GetPlayer() && MyQuest.GetStage() == 30 Self.AddItem(Gold001,100) EndIf EndEvent Note that you do not need to make a property for the object that the script is attached to. It automatically can be referred to as Self. There is no else stage needed to allow the player to activate the container for normal use. If the quest stage check fails, it will still open, it just won't add the item in question. Thanks. I'll fix those things.
Mattiewagg Posted June 17, 2014 Author Posted June 17, 2014 Fixed. I originally had the script that was correct (though I was using a property pointing towards the container) before I looked at the tutorial, and my Oblivion modding self kicked in. It's still weird to adjust, but Papyrus is definitely more flexible than TESScript.
IsharaMeradin Posted June 17, 2014 Posted June 17, 2014 Quote To make the container activate-able in the second, modified script, you have to add Else statement. This means that if one or more of the above conditions is not met, then you should do the thing within the Else statement. I would a commented out line, since the OnActivate() event already activates the item, and I want it to continue doing that. This allows the script to compile with a "blank" line. Else ;activate This allows the player to activate it no matter what, but the item will only be added on stage 30. It's generally a good idea to put this in.Please at least mention that this portion is unnecessary when using the OnActivate event of the container in question. The container has already been activated before it does any of the adding. It may be necessary when called on other events and you want to pass the processing on. Think of it this way:Container is activated.If it is the player, it displays the container menu.Then it checks the IF statements from top down.When an IF statement is true, it performs that action.When an IF statement is false, it does not perform that action.In this scenario, the container has already opened so a failed IF statement simply does not add the gold. All an Else does in this scenario is take up space. Reveal hidden contents Scriptname SomeScript Extends ObjectReference MiscObject Property Gold001 Auto Quest Property MyQuest Auto Event OnActivate(ObjectReference akActiavtor) If akActivator == Game.GetPlayer() && MyQuest.GetStage() == 30 Self.AddItem(Gold001,100) EndIf EndEvent The above behaves the same as the belowScriptname SomeScript Extends ObjectReference MiscObject Property Gold001 Auto Quest Property MyQuest Auto Event OnActivate(ObjectReference akActiavtor) If akActivator == Game.GetPlayer() If MyQuest.GetStage() == 30 Self.AddItem(Gold001,100) EndIf EndIf EndEvent The above behaves the same as the belowScriptname SomeScript Extends ObjectReference MiscObject Property Gold001 Auto Quest Property MyQuest Auto Event OnActivate(ObjectReference akActiavtor) If akActivator == Game.GetPlayer() If MyQuest.GetStage() == 30 Self.AddItem(Gold001,100) Else ;do not add gold EndIf Else ;was not player who activated EndIf EndEvent An empty else is automatically assumed by Papyrus. You only need the Else when you actually have something else you want done.
Mattiewagg Posted June 17, 2014 Author Posted June 17, 2014 On 6/17/2014 at 9:19 PM, IsharaMeradin said: Quote To make the container activate-able in the second, modified script, you have to add Else statement. This means that if one or more of the above conditions is not met, then you should do the thing within the Else statement. I would a commented out line, since the OnActivate() event already activates the item, and I want it to continue doing that. This allows the script to compile with a "blank" line. Else ;activate This allows the player to activate it no matter what, but the item will only be added on stage 30. It's generally a good idea to put this in.Please at least mention that this portion is unnecessary when using the OnActivate event of the container in question. The container has already been activated before it does any of the adding. It may be necessary when called on other events and you want to pass the processing on. Fixed again. Sometimes I think I'm an idiot. Thanks.
asdecker Posted June 18, 2014 Posted June 18, 2014 The Skyrim CK tutorials were really helpful. Especially the making a quest ones. Thanks.
Mattiewagg Posted June 18, 2014 Author Posted June 18, 2014 On 6/18/2014 at 7:48 PM, asdecker said: The Skyrim CK tutorials were really helpful. Especially the making a quest ones. Thanks.Good. :D
Mattiewagg Posted June 21, 2014 Author Posted June 21, 2014 I'll probably put this in the main post, too, but I'm moving my blog/tutorial site to a different location on Weebly. The old site will still be there, but I won't be updating it anymore. Once I've moved over fully, I'll update the old site to say so. I'll be moving over all the content from my old blog to the new site, so none of it will be lost. Once the new site is up, I'll update this post. Thanks for reading.
Mattiewagg Posted June 22, 2014 Author Posted June 22, 2014 I moved over the blog to a new site. You can find it here.
Mattiewagg Posted June 23, 2014 Author Posted June 23, 2014 Mostly finished the new site layout. If you've got any suggestions to make it more readable/better, then feel free to post here.
Mattiewagg Posted June 23, 2014 Author Posted June 23, 2014 Finally moved all the old posts over to the new site. It's fully updated now. The old site URL no longer works. It redirects to the new site.
Recommended Posts