Tutorial 9: Scripts
Let's be honest here. No tutorial of a few hundred words is going to teach you to script like a pro. What this little tutorial will do is to introduce you to the basic mechanics of using the script editor. However, even with such limited scope this tutorial still has problems. Anyway, onto the tutorial.
Follow instruction number one only of the OnAcquireItem Script section and then come back here. DO NOT DO INSTRUCTIONS 2 & 3! If you follow those instructions you will get a warning message about overwriting standard assets. Also, it is all too easy to save your new script with the name of the standard script. It is not the end of the world as your new version will only be available in your module but it is a bad habit nonetheless. Instead do this -
In the left-hand pane where the assets that your module uses are listed, right click on the word Scripts. This will bring up a context menu with a single option - New. Click on this and the script editor will launch. Follow instructions 4 and 5 in the tutorial. A word of warning here if you copy the script from the tutorial and paste it into the script editor you will lose the layout of the script (this is down to how it is stored in the pdf file). Each line will be hard against the left edge of the editor window. While it is true that this will not stop the code from being compiled it will make it harder for you to see what the script does. Being harder to see what the code does will also make it harder to find and correct any errors that may arise in your code. So, you may want to use the [Tab] key to correct the layout so it looks more like the code in the tutorial. If you do not want to go to the bother of correcting the layout, I have created a little addendum/appendix with both scripts correctly laid out.
Anyway, back to my instructions. Once you have saved your script and closed the script editor do the following. Open the module properties dialogue and click the Events tab. The very top event in the list here is the one we want - OnAquireItem. Between the drop-down box with the name of the standard script for this event and the [Edit] button there is another button with three dots on it. Click that button. This will open a file open button with a list of all the custom scripts in the module. Select me_acquireitem from this list and press the Open button. Once you do that, the script name in the drop-down box will change to me_acquireitem. Close the properties dialogue and save your module.
In contrast to the previous section, the A Custom "Action Taken" Script section has no problems at all. Well as long as you didn't miss specifying the amount of experience to give in the earlier tutorial on using the Journal editor. If you can't remember, just go and check.
Extra Credit. This final tutorial features the largest Extra Credit section of the entire document. Not only that it is quite detailed in what to do too. So, go ahead, make the conversation and create the first 2 scripts using the script wizard like the tutorial tells you to. Now at this point you may find yourself struggling because you don't quite understand what you are told to do for the third script. So, do this (have some means of recording information handy) -
- Save the conversation and exit the conversation editor.
- Assign the conversation to the miner blueprint.
- Update instances.
- Save the module.
- Open the fern area.
- Paint a waypoint near to Falstadd. This is what we'll be sending the miners to instead of Falstadd himself. It avoids the miners"harassing" Falstadd
- Set its Tag to "NW_Falstadd"
- Close the properties window.
- Reopen the conversation editor with the miner conversation in it.
- Choose the very node of the conversation branch that you are told to use.
- Select the Actions taken tab.
- Press edit.
If you have already created a script here to give the experience to the PC don't worry. We'll leave that piece of code intact and just add some more to it.
If the script that gives gold is elsewhere, again don't worry we're just going to create a new script.
Before we go any further, I'll just give you a quick tour of this editor. At the very bottom of the editor you will see 4 tabs. Currently the help tab is selected. For now, don't alter this. Above this there is a pane that is currently empty. We'll come back to that in a minute. On the right-hand side of the editor there is another pane, most of which is taken up with a list. Above the list there are 4 buttons. Currently the functions button is depressed (no, it’s not very sad, just pushed into the on position) which means that the list is a list of all the functions available to you. Above the buttons there is a textbox marked Filter. This is where it gets interesting. Referring back to the tutorial, you'll see that there are 3 functions that you are told to use. Copy the first one (GetObjectByTag) and paste it into the filter textbox. This makes the list reduce to just one function - GetObjectByTag. Single click on this function in the list. Now the pane that was empty has text in it. This text is actually information about the function GetObjectByTag. Repeat this copy and paste routine for the other 2 functions - AssignCommand and ActionMoveToObject. So now you know what they do, you might actually be able to figure out how to make the required script...
Or more probably not. This is because even the information given by the editor is still not really enough for a new scripter to be able to sensibly use. That being the case -
If you are editing the script that the script wizard created, use this version.
#include "nw_i0_tool"
void main(){
object oFalstadd = GetObjectByTag("NW_Falstadd"); // use the Tag of an object to get a reference to that object
object oFalstadd = GetObjectByTag("NW_Falstadd");
RewardPartyXP(50, GetPCSpeaker()); //created by the script wizard. gives the PC 50 XP
AssignCommand(OBJECT_SELF, ActionMoveToObject(oFalstadd, TRUE)); //tell the owner of the conversation to run to the location of the waypoint.
AssignCommand(OBJECT_SELF, ActionMoveToObject(oFalstadd, TRUE));
}
Whereas if you are creating a brand new script use this one.
void main(){
object oFalstadd = GetObjectByTag("NW_Falstadd"); // use the Tag of an object to get a reference to that object
object oFalstadd = GetObjectByTag("NW_Falstadd");
AssignCommand(OBJECT_SELF, ActionMoveToObject(oFalstadd, TRUE)); //tell the owner of the conversation to run to the location of the waypoint.
AssignCommand(OBJECT_SELF, ActionMoveToObject(oFalstadd, TRUE));
}
Remember, only use one of the scripts, not both.
Save your module again and test it. Assuming that everything worked I still have a comment. Because both versions of that script use the three functions that the tutorial told you to, you may experience some unexpected behaviour. When you have explored further into the mine and head back to see Falstadd it is possible that you will meet the miners heading back to the mine. Still dressed in their rags! What is happening here is that following performing your scripts in the conversation, they are going back to walking the waypoints because you haven't stopped them doing so. But as we have come to the end of the instructions, we'll leave it there. Which just leaves the very last section of the document.
But before I deal with that I just want to say, you can justifiably be proud of yourself. You have completed your first module. If you did all the extra credit sections too - I can see that you are truly dedicated as well.
Finally, I will deal with the What Next section in the final post of this series of blogs as I will have quite a few working links for you (hint - The website pointed to in the tutorial -http://nwn.bioware.com/builders -has not existed for quite some years now.