What is scripting?
Anyway, a script is a set of instructions that tell the game to do something. What "something" is can vary quite a bit. Warning, slight information overload follows. :)
Examples of common things that are controlled by scripts is what actions NPCs take during combat, what happens when you use a force power on someone, when an NPC says different things when you start conversation with them (e.g. "Welcome back..." greetings when you've already spoken to them before), and when characters move around and do things in cutscenes.
In very broad terms you can categorize scripts into groups like:
The common theme for all scripts are that they need to be fired from somewhere, either an event, a spell/force power, from a dialog, or by another script. A script does not run automatically just because you put it in the override folder.
Scripts are written as text files, you can write them in Notepad or the built-in text editor in KotorTool. These human readable "source code" files should be saved with a .NSS file extension. The script will then need to be translated into byte code that the game engine can understand, since it will not do anything with the source code files. This process is called compiling, and the easiest way of doing it is using KotorTool's built-in text editor, it should have options in the menu bar for compiling scripts. Compiling a script produces a file with the .NCS extension, which is byte code that the game can use.
A script needs to always contain a start function, which is run when the script is triggered. A function is essentially a group of instructions that perform a desired task. In all script types mentioned above except dialog conditional scripts the start function is called main. In the dialog conditional scripts, the function is called StartingConditional instead.
The difference between these two start functions, other than the name, is that the main() function does not return any value (void), while StartingConditional() returns an integer (int), that is a non-decimal number. This difference exists since a dialog conditional script needs to return either true (any value other than 0) or false (the value 0) to the dialog file that runs the script. If a conditional script returns true, the dialog node it is set on becomes available, while if it returns false the dialog node will be hidden/unavailable.
Here are two very simple examples, one of each type:
1. normal script:
2. dialog conditional script:
It then calls the standard script function (a function is instructions to do a specific task) SendMessageToPC(), which will show some text on a character's Journal Feedback log screen in the game.
This functions will take two parameters (basically settings to instruct the function how to work), which you specify within the paranthesises following the function name. The first parameter needs to be set to an object reference for the character who should receive the message. An object is essentially a character, scenery or item in the game world. In this case we use another function, GetFirstPC(), which returns an object reference to the player's character. (This function does not require any parameters to be set, but you still need to put the paranthesises after the function name when you call it.) The second parameter is a string value (text) that should be displayed, in this example Hello World!. Each instruction in a script need to be ended with a semicolon, so that follows the function call.
The second script, when run from a dialog, would enable the dialog node it is attached to if the player's character is female. It works similarly to the first, with the differences that the return data type is set to int (integer, a number) instead of void (nothing). This type of function need to return a value, which is what the return directive does. The script then calls the standard function GetGender(), which checks the gender (Male, Female) of the character you specify as parameter. Again, we use the GetFirstPC() to get an object reference to the player's character. We then compare the value the GetGender() function returns to the value of the GENDER_FEMALE constant. If they match, the script will return true, otherwise it will return false.
The standard functions (like GetFirstPC(), GetGender() and SendMessageToPC()), and standard constants (like GENDER_MALE and GENDER_FEMALE) are listed in a text file named nwscript.nss which you can extract with KotorTool from the scripts.bif data file. This file usually contains comments (lines of text starting with // are comments and not part of the script itself) that describe roughly what a function does. This file is a very handy reference for looking up things when you write scripts, and to try to figure out what the functions used in scripts are doing.
Those are just a few basic examples, scripts can be a lot more complex than that. :)
If you have no prior programming experience all this is probably rather confusing. It took me quite a while to figure out how things worked when I first started looking into scripting for KOTOR and Neverwinter Nights. I don't know if there are any real shortcuts I can offer.
If you want to learn the best advice I can offer, beyond checking out the "getting started with scripting" tutorials posted here in holowan, is to look at existing scripts and try to figure out how they do the things they do. You can find many of the game's existing scripts in the scripts.bif data file with KotorTool, or you can ask for scripts that do specific things in this forum and then have a look at the scripts people here offer. :)
Also ask in this forum if there is something specific you need explained or don't understand, people are generally very helpful around here.
|All times are GMT -4. The time now is 06:16 AM.|
Powered by vBulletin®
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
LFNetwork, LLC ©2002-2011 - All rights reserved.