lfnetwork.com mark read register faq members calendar

Thread: Conditional Scripts
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 01-28-2011, 06:07 AM   #1
I'm in space!
TimBob12's Avatar
Join Date: Feb 2010
Location: Dantooine
Posts: 515
Current Game: Mass Effect 2!
Conditional Scripts

Script Condidionals

Hello There,
When I was making my Tatooine Job Office (http://www.lucasforums.com/showthread.php?t=206577)

I wanted to find how to only make certain conversation options available after certain conditions had been met. Now I couldn't find a dedicated tutorial anywhere so I had to ask.

So I thought I'd make it easier by writing this tutorial. This is my first tutorial so go easy on me

Things you will need:


Things you should read:


Right Script Conditionals. What can they do?

Script conditionals can be used when you want something (usually a dialog option) to only be displayed once a certain condition has been met. Some of the common conditions used are:
  • Global Variables
  • Local Variables
  • Item in PC Inventory
  • Certain Classes

There are many other conditions but as long as the condition returns either TRUE or FALSE then it will work.

Lets start Scripting!

First of all if you have only coded a little bit in KOTOR before then this will look completely different.

int StartingConditional() 
  int iResult;

  iResult = ((GetGlobalBoolean( "your_global_bool" ) == TRUE) );

  return iResult;  

Right lets break this down.

int StartingConditional()
This starting line is different than most scripts in KOTOR for one reason. In most scripts you do not require an outcome as they usually make something happen. We however want an outcome so the dialogue (or whatever) knows what to do / display.

Most scripts start with:

void main()
Void is used when no output is required and means nothing or to get rid of.
Int is a variable type meaning that it has to be filled by something.
The StartingConditional() part tells the game that it is to be used as a Starting Conditional


The next bit

int iResult;
Here you are declaring the variable "iResult". You will use this variable to store the outcome and tell the game what to do. If you've never used variables before get used to it because they are VITAL to scripting.

Then next bit

  iResult = ((GetGlobalBoolean( "your_global_bool" ) == TRUE) );
This is the most important part of your script. It determines what must happen for the conversation option to become available and then puts it into the "iResult" variable. In this example it gets whether a global bool is TRUE and then outputs TRUE into "iResult"but there are other options such as

  object oW1 = GetObjectByTag("black_market_pad");

  iResult = GetIsObjectValid(oW1);
This checks for the existance of "black_market_pad" in the PC's inventory and puts TRUE in the
"iResult" variable.

The last bit
return iResult;
This simply tells the script YES or NO / TRUE or FALSE. If the script sees TRUE it will display the dialog option.

Then you must simply compile the script and put the resulting file in the same place as your dialog. (For information on compiling scripts see one of the top links) or see this brief tutorial below.

Firstly you need to open up Kotor Tool Text Editor and either write or open your script. (save it as a .nss)

Show spoiler

Then you need to make sure it is saved and go to Script (in the top menu) Click whichever version of the game yours is for. Then click scripts again and Compile

Show spoiler

If all went well a small box should pop up. If it went wrong there will be extra lines telling you what went wrong and a helpful line number in brackets ()

Show spoiler

Now where ever you saved your .nss file, there should now also be a .ncs file which the game can read (Hooray!) that is the one that will need to be included in your overide folder or .MOD file.

It is then the name of that file (without the .ncs bit) that goes in your dialogue file. It should go in the part that says "Script that determines availablilty"

Show spoiler

Thats it.

Hope this helped.

If you have any questions at all I will do my best to answer them.



TimBob12 is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > Star Wars Gamer > Community > The Star Forge > Knights of the Old Republic series > Holowan Laboratories > Tutorials > Tutorials: Scripting > Conditional Scripts

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -4. The time now is 07:07 PM.

Powered by vBulletin®
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.